Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (data.layout === 'draft') data.layout = 'post';
const ctx = this.context;
const { config } = ctx;
const draftDir = join(ctx.source_dir, '_drafts');
const slug = slugize(data.slug.toString(), {transform: config.filename_case});
data.slug = slug;
const regex = new RegExp(`^${escapeRegExp(slug)}(?:[^\\/\\\\]+)`);
let src = '';
const result = {};
data.layout = (data.layout || config.default_layout).toLowerCase();
// Find the draft
return fs.listDir(draftDir).then(list => {
return list.find(item => regex.test(item));
}).then(item => {
if (!item) throw new Error(`Draft "${slug}" does not exist.`);
// Read the content
src = join(draftDir, item);
return fs.readFile(src);
}).then(content => {
// Create post
Object.assign(data, yfm(content));
data.content = data._content;
delete data._content;
return this.create(data, replace).then(post => {
result.path = post.path;
result.content = post.content;
before(() => fs.listDir(assetDir).then(files => {
assets = files;
}));
})).then(post => Promise.all([
fs.exists(assetDir),
fs.listDir(newAssetDir),
fs.unlink(post.path)
])).spread((exist, files) => {
hexo.config.post_asset_folder = false;
return fs.stat(assetDir).then(stats => {
if (!stats.isDirectory()) return [];
return fs.listDir(assetDir);
}).catch(err => {
if (err.cause && err.cause.code === 'ENOENT') return [];
getDraftItems() {
return fs.listDir(this.draft_dir, []);
}
getItems() {
return fs.listDir(this.post_dir, []);
}
getTrashItems() {
return fs.listDir(this.trash_dir, []);
}
}).map(function(scriptDir){
var scriptPath = '';
return fs.listDir(scriptDir).map(function(name){
scriptPath = pathFn.join(scriptDir, name);
require(scriptPath);
ctx.log.debug('Script loaded: %s', tildify(scriptPath).magenta);
}).catch(function(err){
ctx.log.error({err: err}, 'Script load failed: %s', tildify(scriptPath).magenta);
});
});
};
return fs.stat(assetDir).then(stats => {
if (!stats.isDirectory()) return [];
return fs.listDir(assetDir);
}).catch(err => {
if (err.cause && err.cause.code === 'ENOENT') return [];
return exists(scaffoldDir).then(exist => {
if (!exist) return [];
return listDir(scaffoldDir, {
ignoreFilesRegex: /^_|\/_/
});
}).map(item => ({
name: item.substring(0, item.length - extname(item).length),