fix: use frontmatter format for metadata in storage

This commit is contained in:
Nick
2019-02-10 18:06:03 -05:00
parent 0eac78977a
commit 37556399b6
4 changed files with 26 additions and 51 deletions

View File

@@ -114,6 +114,27 @@ module.exports = class Page extends Model {
})
}
/**
* Inject page metadata into contents
*/
injectMetadata () {
let meta = [
['title', this.title],
['description', this.description],
['published', this.isPublished.toString()],
['date', this.updatedAt],
['tags', '']
]
switch (this.contentType) {
case 'markdown':
return '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + this.content
case 'html':
return '<!--\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n-->\n\n' + this.content
default:
return this.content
}
}
static async createPage(opts) {
await WIKI.models.pages.query().insert({
authorId: opts.authorId,