Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (model, id, update, callback, hexo) {
function removeExtname(str) {
return str.substring(0, str.length - path.extname(str).length);
}
var post = hexo.model(model).get(id)
if (!post) {
return callback('Post not found');
}
var config = hexo.config,
slug = post.slug = hfm.escape(post.slug || post.title, config.filename_case),
layout = post.layout = (post.layout || config.default_layout).toLowerCase(),
date = post.date = post.date ? moment(post.date) : moment();
var split = hfm.split(post.raw),
frontMatter = split.data
compiled = hfm.parse([frontMatter, '---', split.content].join('\n'));
var preservedKeys = ['title', 'date', 'tags', 'categories', '_content', 'author'];
Object.keys(hexo.config.metadata || {}).forEach(function (key) {
preservedKeys.push(key);
});
var prev_full = post.full_source,
full_source = prev_full;
if (update.source && update.source !== post.source) {
// post.full_source only readable ~ see: /hexo/lib/models/post.js
full_source = hexo.source_dir + update.source
}
preservedKeys.forEach(function (attr) {
if (attr in update) {
module.exports = function (model, id, update, callback, hexo) {
var post = hexo.model(model).get(id)
if (!post) {
return callback('Post not found');
}
var config = hexo.config,
slug = post.slug = hfm.escape(post.slug || post.title, config.filename_case),
layout = post.layout = (post.layout || config.default_layout).toLowerCase(),
date = post.date = post.date ? moment(post.date) : moment();
var split = hfm.split(post.raw),
frontMatter = split.data
compiled = hfm.parse([frontMatter, '---', split.content].join('\n'));
var preservedKeys = ['title', 'date', 'tags', 'categories', '_content', 'keywords', 'description'];
var prev_full = post.full_source,
full_source = prev_full;
if (update.source && update.source !== post.source) {
// post.full_source only readable ~ see: /hexo/lib/models/post.js
full_source = hexo.source_dir + update.source
}
preservedKeys.forEach(function (attr) {
if (attr in update) {
compiled[attr] = update[attr]
}
});
return this._getScaffold(data.layout).then(scaffold => {
const frontMatter = prepareFrontMatter({...data});
yfmSplit = yfm.split(scaffold);
return tag.render(yfmSplit.data, frontMatter);
}).then(frontMatter => {
const { separator } = yfmSplit;
raw(query) {
let post = this.detail(query);
if (!post) return null;
return hfm.split(post.raw);
}