commit
864dc3cf42
|
@ -88,6 +88,10 @@ app.get('/help', requireLoggedIn, (req, res, next) => {
|
||||||
res.render('help.spy', {title: 'Help'})
|
res.render('help.spy', {title: 'Help'})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/published', requireLoggedIn, (req, res, next) => {
|
||||||
|
res.render('published.spy', {title: 'You published a note!'})
|
||||||
|
})
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
|
|
||||||
app.post('/login', verifyUser,
|
app.post('/login', verifyUser,
|
||||||
|
@ -108,7 +112,7 @@ app.post('/logout', function(req, res, next){
|
||||||
|
|
||||||
app.post('/publish', requireLoggedIn, (req, res) => {
|
app.post('/publish', requireLoggedIn, (req, res) => {
|
||||||
publishNewPost(req, () => {
|
publishNewPost(req, () => {
|
||||||
res.redirect('/')
|
res.redirect('/published')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
12
templates/published.spy
Normal file
12
templates/published.spy
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<< partials/head >>
|
||||||
|
<body>
|
||||||
|
<section>
|
||||||
|
<< partials/header >>
|
||||||
|
<main>
|
||||||
|
<h2> {{ title }}</h2>
|
||||||
|
<p>Hooray 🎉</p>
|
||||||
|
</main>
|
||||||
|
</section>
|
||||||
|
<footer></footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
11
utilities.js
11
utilities.js
|
@ -168,16 +168,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].split('\n')
|
||||||
for (let i = 6; i < 2; i--) {
|
for (let line of lines) {
|
||||||
if (lines[i] && lines[i].startsWith('=>')) {
|
if (line.startsWith('=>') && newlines.length < 4) {
|
||||||
lines[i] = lines[i-1]
|
newlines.push(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines[0] = '## Latest notes'
|
lines[0] = '## Latest notes'
|
||||||
lines[2] = `=> /${year}/${dateString}.gmi ${dateString} (${title})`
|
newlines.unshift(`## Latest notes\n\n=> /${year}/${dateString}.gmi ${dateString} (${title})`)
|
||||||
updated = links[0] + lines.join('\n')
|
updated = newlines.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
|
||||||
|
|
Loading…
Reference in a new issue