do not wipe homepage content on publish #9

Merged
hughrun merged 1 commit from publishing-fixes into main 2023-03-12 17:48:52 +11:00
Showing only changes of commit 88b0b097b1 - Show all commits

View file

@ -153,16 +153,17 @@ const publishNewPost = function(req, cb) {
}) })
} }
} else { } else {
let newlines = []
let links = data.split('## Latest notes') let links = data.split('## Latest notes')
let lines = links[1].split('\n') let lines = links[1].trimStart().split('\n')
for (let line of lines) { // remove the oldest item
if (line.startsWith('=>') && newlines.length < 4) { if (lines[4].startsWith('=>')) {
newlines.push(line) lines.splice(4,1)
} }
} // add new post at top of list
newlines.unshift(`## Latest notes\n\n=> /${year}/${dateString}.gmi ${dateString} (${title})`) lines.unshift(`## Latest notes\n\n=> /${year}/${dateString}.gmi ${dateString} (${title})`)
updated = newlines.join('\n') // add back everything preceeding latest notes
lines.unshift(`${links[0].trimEnd()}\n`) // because we join with a newline we need to remove one here
updated = lines.join('\n')
writeFile(indexFile, updated, (err) => { writeFile(indexFile, updated, (err) => {
if (err) { if (err) {
// if the directory doesn't exist, create it and try again // if the directory doesn't exist, create it and try again