How to use the hexo-fs.readFileSync function in hexo-fs

To help you get started, we’ve selected a few hexo-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Troy-Yang / hexo-lazyload-image / lib / process.js View on Github external
function lazyProcess(htmlContent) {
    let defaultImagePath = __dirname + '/default-image.json';
    let loadingImage = this.config.lazyload.loadingImg;

    if (!loadingImage) {
        loadingImage = JSON.parse(fs.readFileSync(defaultImagePath)).default;
    }

    return htmlContent.replace(//gi, function (str, p1, p2) {
        // might be duplicate
        if(/data-original/gi.test(str)){
            return str;
        }
        if(/src="data:image(.*?)/gi.test(str)) {
            return str;
        }
        if(/no-lazy/gi.test(str)) {
            return str;
        }
        return str.replace(p2, loadingImage + '" data-original="' + p2);
    });
}
github hexojs / hexo / lib / hexo / multi_config_path.js View on Github external
const numPaths = paths.length;

  // combine files
  let combinedConfig = {};
  let count = 0;
  for (let i = 0; i < numPaths; i++) {
    const configPath = isAbsolute(paths[i]) ? paths[i] : join(base, paths[i]);

    if (!fs.existsSync(configPath)) {
      log.w(`Config file ${paths[i]} not found.`);
      continue;
    }

    // files read synchronously to ensure proper overwrite order
    const file = fs.readFileSync(configPath);
    const ext = extname(paths[i]).toLowerCase();

    if (ext === '.yml') {
      combinedConfig = deepMerge(combinedConfig, yml.load(file));
      count++;
    } else if (ext === '.json') {
      combinedConfig = deepMerge(combinedConfig, yml.safeLoad(file, {json: true}));
      count++;
    } else {
      log.w(`Config file ${paths[i]} not supported type.`);
    }
  }

  if (count === 0) {
    log.e('No config files found. Using _config.yml.');
    return defaultPath;
github hexojs / hexo / test / scripts / hexo / multi_config_path.js View on Github external
it('JSON & YAML overwrite', () => {
    let config = fs.readFileSync(mcp(base, 'test1.yml,test1.json'));
    config = yml.safeLoad(config);

    config.author.should.eql('dinosaur');
    config.favorites.food.should.eql('burgers');
    config.type.should.eql('elephant');

    config = fs.readFileSync(mcp(base, 'test1.json,test1.yml'));
    config = yml.safeLoad(config);

    config.author.should.eql('foo');
    config.favorites.food.should.eql('sushi');
    config.type.should.eql('dinosaur');
  });
github phoenixcw / hexo-renderer-mathjax / index.js View on Github external
var path = require('path');
var ejs = require('ejs');
var fs = require('hexo-fs');

var layout = 'layout.ejs';
var bodyTag = '';
var mathjaxScript = fs.readFileSync(path.join(__dirname, 'mathjax.html'));

hexo.extend.renderer.register('ejs', 'html', function(data, options, callback) {
    var path = options.filename = data.path;
    var content = data.text;
    if (layout === path.substring(path.length - layout.length))
        content = content.replace(bodyTag, mathjaxScript + '\n' + bodyTag);
    callback(null, ejs.render(content, options));
});
github tea3 / hexo-generator-amp / lib / cache.js View on Github external
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 "";
  }
};
github hexojs / hexo / lib / box / file.js View on Github external
File.prototype.readSync = function(options) {
  return readFileSync(this.source, options);
};
github zhuzhuyule / HexoEditor / views / main / hexo / loadconfig.js View on Github external
function loadYAMLFile(file) {
    if (!file) return loadsh.extend({}, defConfig);
    file = file.toString().replace(/\\+/g, '\\\\');
    if (!fs.existsSync(file)) return {};
    var configPath = file;
    if (fs.statSync(file).isDirectory()) {
        configPath = (path.join(file, '_config.yml'));
    }
    var baseDir = path.dirname(configPath);
    var config = fs.existsSync(configPath) ? YAML.parse(fs.readFileSync(configPath).toString()) : {};
    defConfig.__basedir = baseDir;
    var themeConfig = {};
    if (config.theme) {
        defConfig.__themedir = path.join( baseDir,'themes',config.theme);
        configPath = path.join( defConfig.__themedir,'_config.yml');
        themeConfig = fs.existsSync(configPath) ? YAML.parse(fs.readFileSync(configPath).toString()) : {};
    }
    return loadsh.extend({}, defConfig, config, themeConfig);
}
github jaredly / hexo-admin / api.js View on Github external
function getSettings() {
    var path = hexo.base_dir + '_admin-config.yml'
    if (!fs.existsSync(path)) {
      hexo.log.d('admin config not found, creating one')
      fs.writeFile(hexo.base_dir+'_admin-config.yml', '')
      return {}
    } else {
      var settings = yml.safeLoad(fs.readFileSync(path))

      if (!settings) return {}
      return settings
    }
  }
github poacher2k / hexo-featured-image / index.js View on Github external
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;
				}
			}
			return post;
		});
		fs.writeFileSync(contentJsonPath, JSON.stringify(content));
	}
});
github dojo / dojo.io / site / scripts / codefile.js View on Github external
}

			if(_.startsWith(arg, "title:")) {
				title = arg.replace(/(^title:\'?)|(\'$)/gm, "");
				title = `<div class="prism-code-title">${title}</div>`;
			}

			if(_.startsWith(arg, "note:")) {
				note = arg.replace(/(^note:\'?)|(\'$)/gm, "");
				note = `<div class="prism-code-note">${note}</div>`;
			}
		});

		lang = lang ? lang : "javascript";

		var rawContent = fs.readFileSync(cf.getFilePath(this.path, filename));

		if (lines !== false) {
			content = cf.extractContent(rawContent, lines);
		} else {
			content = rawContent;
		}

		var prismHtml = Prism.highlight(cf.normalizeWhitespace(content), Prism.languages[lang]);

		if(highlighted) {
			highlightedLines = cf.adjustHighlightedLineNumbers(highlighted, lines);
			prismHtml = cf.highlightHtml(prismHtml, highlightedLines);
		}

		return `<pre class="language-${lang}">${title}<code class="language-${lang}">${prismHtml}</code>${note}</pre>`;
	},