diff options
Diffstat (limited to '')
-rw-r--r-- | lib/models/note.js | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/lib/models/note.js b/lib/models/note.js index 5c63dc1a..132f8b1e 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -236,33 +236,17 @@ module.exports = function (sequelize, DataTypes) { }); }, parseNoteInfo: function (body) { - var meta = null; - try { - var obj = metaMarked(body); - body = obj.markdown; - meta = obj.meta; - } catch (err) { - //na - } - if (!meta) meta = {}; - var $ = cheerio.load(md.render(body)); + var parsed = Note.extractMeta(body); + var $ = cheerio.load(md.render(parsed.markdown)); return { - title: Note.extractNoteTitle(meta, $), - tags: Note.extractNoteTags(meta, $) + title: Note.extractNoteTitle(parsed.meta, $), + tags: Note.extractNoteTags(parsed.meta, $) }; }, parseNoteTitle: function (body) { - var meta = null; - try { - var obj = metaMarked(body); - body = obj.markdown; - meta = obj.meta; - } catch (err) { - //na - } - if (!meta) meta = {}; - var $ = cheerio.load(md.render(body)); - return Note.extractNoteTitle(meta, $); + var parsed = Note.extractMeta(body); + var $ = cheerio.load(md.render(parsed.markdown)); + return Note.extractNoteTitle(parsed.meta, $); }, extractNoteTitle: function (meta, $) { var title = ""; @@ -320,6 +304,19 @@ module.exports = function (sequelize, DataTypes) { } return tags; }, + extractMeta: function (content) { + try { + var obj = metaMarked(content); + if (!obj.markdown) obj.markdown = ""; + if (!obj.meta) obj.meta = {}; + } catch (err) { + var obj = { + markdown: content, + meta: {} + }; + } + return obj; + }, parseMeta: function (meta) { var _meta = {}; if (meta) { |