Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hexo.extend.filter.register('before_exit', function() {
// to work smoothly with hexo_generator_json_content
var jsonContentCfg = hexo.config.hasOwnProperty('jsonContent')
? hexo.config.jsonContent
: {
meta: true,
};
var postsCfg = jsonContentCfg.hasOwnProperty('posts')
? jsonContentCfg.posts
: {};
if (postsCfg.featured_image && fs.existsSync(contentJsonPath)) {
var postsObject = {};
var posts = hexo.locals.get('posts');
posts.forEach(function(post) {
postsObject[post.path] = post;
});
var content = JSON.parse(fs.readFileSync(contentJsonPath));
var contentPosts = content.posts;
if (!contentPosts) return;
content.posts = contentPosts.map(function(post) {
var fullPost = postsObject[post.path];
if (fullPost && fullPost.featured_image) {
post.featured_image = fullPost.featured_image;
if (postsCfg.thumbnail && fullPost.thumbnail) {
post.thumbnail = fullPost.thumbnail;
}
}
module.exports = function (args) {
const { log, baseDir, pluginDir, logDir } = this;
const packagePath = pathFn.join(baseDir, 'package.json');
const packageLockPath = pathFn.join(baseDir, 'package-lock.json');
// Remove plugin dir
if (fs.existsSync(pluginDir) && fs.lstatSync(pluginDir).isDirectory()) {
deleteFolderRecursive(pluginDir);
}
// Remove log dir
if (fs.existsSync(logDir) && fs.lstatSync(logDir).isDirectory()) {
deleteFolderRecursive(logDir);
}
// Remove package-lock.json
fs.unlinkSync(packageLockPath);
// Rewrite package.json
fs.writeFileSync(packagePath, JSON.stringify({
'name': 'feflow-home',
'version': '0.0.0',
'private': true
* Use custom
*/
return scriptFrom;
}
}
if (config.enable) {
_.unset(config, 'enable');
if (_.hasIn(config, 'model.use')) {
let modelJsonUrl = null;
let tryPath = path.resolve(hexo.base_dir, './live2d_models/', config.model.use);
if (fs.existsSync(tryPath)) { // eslint-disable-line no-sync
/*
* Is in live2d_models(2)
* LoadModelFrom
*/
const {
modelGenerators,
'modelJsonUrl': pkgModelJsonUrl,
} = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
generators.push(...modelGenerators);
if (config.log) {
print.log(`Loaded model from live2d_models folder(2), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);
}
module.exports = function (args) {
const { log, baseDir, pluginDir, logDir } = this;
const packagePath = pathFn.join(baseDir, 'package.json');
const packageLockPath = pathFn.join(baseDir, 'package-lock.json');
// Remove plugin dir
if (fs.existsSync(pluginDir) && fs.lstatSync(pluginDir).isDirectory()) {
deleteFolderRecursive(pluginDir);
}
// Remove log dir
if (fs.existsSync(logDir) && fs.lstatSync(logDir).isDirectory()) {
deleteFolderRecursive(logDir);
}
// Remove package-lock.json
fs.unlinkSync(packageLockPath);
// Rewrite package.json
fs.writeFileSync(packagePath, JSON.stringify({
'name': 'feflow-home',
'version': '0.0.0',
'private': true
}, null, 4));
log.info('Feflow 重新重新初始化完成');
};
hexo.extend.helper.register('fileExists', function(path) {
return fs.existsSync(path);
});
run(generator, subgenerator) {
const ctx = this.ctx;
const pluginDir = ctx.pluginDir;
let path = pathFn.join(pluginDir, generator, `${subgenerator}/index.js`);
if (!fs.existsSync(path)) {
path = pathFn.join(pluginDir, generator, 'generators', `${subgenerator}/index.js`);
}
yeomanEnv.register(require.resolve(path), generator);
yeomanEnv.run(generator, this.args, err => {});
}
const deleteFolderRecursive = function (path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file) {
const curPath = path + '/' + file;
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
module.exports.getCacheHash = function(hexoConfig){
var result = null;
if( existsOption(hexoConfig) && fs.existsSync(getCachePath(hexoConfig)) ){
if(!read_cacheData){
read_cacheData = fs.readFileSync( getCachePath(hexoConfig) );
read_cacheData = JSON.parse(read_cacheData);
}
if(!read_cacheData.hash){
return "";
}else{
return read_cacheData.hash;
}
}else{
return "";
}
};
self.load().then(function () {
if(!fs.existsSync(publicDir)){
fs.mkdirSync(publicDir);
}
if(!fs.existsSync(path.join(publicDir,'assets'))){
fs.mkdirSync(path.join(publicDir,'assets'));
}
self.route.get(doubanLoadingPath)._data().then(function (stream) {
stream.pipe(fs.createWriteStream(path.join(publicDir, doubanLoadingPath)));
});
names.forEach(name => {
var id = name + "/index.html";
self.route.get(id) && self.route.get(id)._data().then(function (contents) {
fs.writeFile(path.join(publicDir, id), contents);
log.info("Generated: %s", id);
});
});
});