Skip to content

Commit

Permalink
fix category changer
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyzt authored May 8, 2021
1 parent 6a6cf2b commit 2a3a2b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
35 changes: 14 additions & 21 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1369,21 +1369,14 @@
dbWrite( await legacyAddress(story.categoryID), {[id]: legacyStory}, true)

if(story.categoryID !== oldStory.categoryID){
const storySiblingIDs = (await dbLive('categories'))
[story.categoryID]
.articleIDs
.concat([id])
.sort(async (a,b)=>(
(await dbLive('snippets'))[a].timestamp
-
(await dbLive('snippets'))[b].timestamp
))
const oldStorySiblingIDs = (await dbLive('categories'))
[oldStory.categoryID]
.articleIDs
.filter(x=>x!==id)
dbWrite( 'categories/'+story.categoryID, {articleIDs: storySiblingIDs} )
dbWrite( 'categories/'+oldStory.categoryID, {articleIDs: oldStorySiblingIDs} )
const categories = await dbLive('categories')
const snippets = await dbLive('snippets')
const siblingIDs = categories[story.categoryID].articleIDs
const index = siblingIDs.findIndex(id=>snippets[id].timestamp < story.timestamp)
index < 0 ? siblingIDs.push(id) : siblingIDs.splice(index,0,id)
const oldSiblingIDs = categories[oldStory.categoryID].articleIDs.filter(x=>x!==id)
dbWrite( 'categories/'+story.categoryID, {articleIDs: siblingIDs} )
dbWrite( 'categories/'+oldStory.categoryID, {articleIDs: oldSiblingIDs} )
dbWrite( await legacyAddress(oldStory.categoryID), { [id]: null}, true )
}
discord(id,'✏️ '+story.title,diff(story,oldStory))
Expand Down Expand Up @@ -1960,18 +1953,18 @@
const typography = text => text
// Smart quotes
/* opening singles */
.replace(/(^|[-\u2014\s(\["])'/g,'$1&lsquo;')
.replace(/(^|[-\u2014\s(\["])'/g,'$1')
/* closing singles & apostrophes */
.replace(/'/g,'&rsquo;')
.replace(/'/g,'')
/* opening doubles */
.replace(/(^|[-\u2014/\[(\u2018\s])"/g,'$1&ldquo;')
.replace(/(^|[-\u2014/\[(\u2018\s])"/g,'$1')
/* closing doubles */
.replace(/"/g,'&rdquo;')
.replace(/"/g,'')
// Dashes
/* em-dashes */
.replace(/\s--\s?/g,'&thinsp;&mdash;&thinsp;')
.replace(/\s--\s?/g,' — ')
/* en-dashes */
.replace(/--/g,'&ndash;')
.replace(/--/g,'')
const timestamp = () => Math.floor(Date.now()/1000)

/**
Expand Down
23 changes: 8 additions & 15 deletions src/js/modules/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,14 @@ async function publishStory(target){
dbWrite( await legacyAddress(story.categoryID), {[id]: legacyStory}, true)

if(story.categoryID !== oldStory.categoryID){
const storySiblingIDs = (await dbLive('categories'))
[story.categoryID]
.articleIDs
.concat([id])
.sort(async (a,b)=>(
(await dbLive('snippets'))[a].timestamp
-
(await dbLive('snippets'))[b].timestamp
))
const oldStorySiblingIDs = (await dbLive('categories'))
[oldStory.categoryID]
.articleIDs
.filter(x=>x!==id)
dbWrite( 'categories/'+story.categoryID, {articleIDs: storySiblingIDs} )
dbWrite( 'categories/'+oldStory.categoryID, {articleIDs: oldStorySiblingIDs} )
const categories = await dbLive('categories')
const snippets = await dbLive('snippets')
const siblingIDs = categories[story.categoryID].articleIDs
const index = siblingIDs.findIndex(id=>snippets[id].timestamp < story.timestamp)
index < 0 ? siblingIDs.push(id) : siblingIDs.splice(index,0,id)
const oldSiblingIDs = categories[oldStory.categoryID].articleIDs.filter(x=>x!==id)
dbWrite( 'categories/'+story.categoryID, {articleIDs: siblingIDs} )
dbWrite( 'categories/'+oldStory.categoryID, {articleIDs: oldSiblingIDs} )
dbWrite( await legacyAddress(oldStory.categoryID), { [id]: null}, true )
}
discord(id,'✏️ '+story.title,diff(story,oldStory))
Expand Down

0 comments on commit 2a3a2b2

Please sign in to comment.