Move showNote to note controller

Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
David Mehren 2019-10-27 14:59:44 +01:00
parent 181d5646cf
commit dee62ce571
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
3 changed files with 19 additions and 133 deletions

View file

@ -14,7 +14,6 @@ const errors = require('./errors')
// public
var response = {
showNote: showNote,
showPublishNote: showPublishNote,
showIndex: showIndex,
publishNoteActions: publishNoteActions,
@ -52,33 +51,6 @@ function showIndex (req, res, next) {
}
}
function responseCodiMD (res, note) {
var body = note.content
var extracted = models.Note.extractMeta(body)
var meta = models.Note.parseMeta(extracted.meta)
var title = models.Note.decodeTitle(note.title)
title = models.Note.generateWebTitle(meta.title || title)
var opengraph = models.Note.parseOpengraph(meta, title)
res.set({
'Cache-Control': 'private', // only cache by client
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
})
res.render('codimd.ejs', {
title: title,
opengraph: opengraph
})
}
function showNote (req, res, next) {
noteUtil.findNote(req, res, function (note) {
// force to use note id
var noteId = req.params.noteId
var id = models.Note.encodeNoteId(note.id)
if ((note.alias && noteId !== note.alias) || (!note.alias && noteId !== id)) { return res.redirect(config.serverURL + '/' + (note.alias || id)) }
return responseCodiMD(res, note)
})
}
function showPublishNote (req, res, next) {
var include = [{
model: models.User,