diff options
author | David Mehren | 2019-10-27 15:22:14 +0100 |
---|---|---|
committer | David Mehren | 2019-10-27 15:23:38 +0100 |
commit | 2bc4233ba80346e60ed4840714a9aa347ccdb361 (patch) | |
tree | 1be1516143a0f9c0fe0104f1ca5b9cc209f7f8e7 /lib/web/note/util.js | |
parent | dee62ce571cc3e33f60499e3ed9cfa4cc5c2f0da (diff) |
Move showPublishNote and publishNoteActions to note controller
Signed-off-by: David Mehren <dmehren1@gmail.com>
Diffstat (limited to '')
-rw-r--r-- | lib/web/note/util.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/web/note/util.js b/lib/web/note/util.js index bda74ac4..eadfb1a3 100644 --- a/lib/web/note/util.js +++ b/lib/web/note/util.js @@ -2,6 +2,8 @@ const models = require('../../models') const logger = require('../../logger') const config = require('../../config') const errors = require('../../errors') +const fs = require('fs') +const path = require('path') exports.findNote = function (req, res, callback, include) { const id = req.params.noteId || req.params.shortid @@ -65,3 +67,43 @@ exports.newNote = function (req, res, body) { return errors.errorInternalError(res) }) } + +exports.getPublishData = function (req, res, note, callback) { + const body = note.content + const extracted = models.Note.extractMeta(body) + const markdown = extracted.markdown + const meta = models.Note.parseMeta(extracted.meta) + const createtime = note.createdAt + const updatetime = note.lastchangeAt + let title = models.Note.decodeTitle(note.title) + title = models.Note.generateWebTitle(meta.title || title) + const ogdata = models.Note.parseOpengraph(meta, title) + const data = { + title: title, + description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), + viewcount: note.viewcount, + createtime: createtime, + updatetime: updatetime, + body: markdown, + theme: meta.slideOptions && isRevealTheme(meta.slideOptions.theme), + meta: JSON.stringify(extracted.meta), + owner: note.owner ? note.owner.id : null, + ownerprofile: note.owner ? models.User.getProfile(note.owner) : null, + lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null, + lastchangeuserprofile: note.lastchangeuser ? models.User.getProfile(note.lastchangeuser) : null, + robots: meta.robots || false, // default allow robots + GA: meta.GA, + disqus: meta.disqus, + cspNonce: res.locals.nonce, + dnt: req.headers.dnt, + opengraph: ogdata + } + callback(data) +} + +function isRevealTheme (theme) { + if (fs.existsSync(path.join(__dirname, '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) { + return theme + } + return undefined +} |