Publishing fixes #4

Merged
hughrun merged 2 commits from publishing-fixes into main 2023-01-30 16:59:41 +11:00
2 changed files with 20 additions and 15 deletions
Showing only changes of commit 5a4876b43d - Show all commits

View file

@ -88,6 +88,10 @@ app.get('/help', requireLoggedIn, (req, res, next) => {
res.render('help.spy', {title: 'Help'})
})
app.get('/published', requireLoggedIn, (req, res, next) => {
res.render('published.spy', {title: 'You published a note!'})
})
// POST
app.post('/login', verifyUser,
@ -108,7 +112,7 @@ app.post('/logout', function(req, res, next){
app.post('/publish', requireLoggedIn, (req, res) => {
publishNewPost(req, () => {
res.redirect('/')
res.redirect('/published')
})
})

View file

@ -168,16 +168,17 @@ const publishNewPost = function(req, cb) {
})
}
} else {
let newlines = []
let links = data.split('## Latest notes')
let lines = links[1].split('\n')
for (let i = 6; i < 2; i--) {
if (lines[i] && lines[i].startsWith('=>')) {
lines[i] = lines[i-1]
for (let line of lines) {
if (line.startsWith('=>') && newlines.length < 4) {
newlines.push(line)
}
}
lines[0] = '## Latest notes'
lines[2] = `=> /${year}/${dateString}.gmi ${dateString} (${title})`
updated = links[0] + lines.join('\n')
newlines.unshift(`## Latest notes\n\n=> /${year}/${dateString}.gmi ${dateString} (${title})`)
updated = newlines.join('\n')
writeFile(indexFile, updated, (err) => {
if (err) {
// if the directory doesn't exist, create it and try again