fix: use frontmatter format for metadata in storage
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user