How to use the hexo-fs.listDir 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 hexojs / hexo / lib / hexo / post.js View on Github external
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;
github hexojs / hexo-cli / test / scripts / init.js View on Github external
  before(() => fs.listDir(assetDir).then(files => {
    assets = files;
  }));
github hexojs / hexo / test / scripts / hexo / post.js View on Github external
})).then(post => Promise.all([
      fs.exists(assetDir),
      fs.listDir(newAssetDir),
      fs.unlink(post.path)
    ])).spread((exist, files) => {
      hexo.config.post_asset_folder = false;
github hexojs / hexo / lib / plugins / processor / post.js View on Github external
return fs.stat(assetDir).then(stats => {
      if (!stats.isDirectory()) return [];

      return fs.listDir(assetDir);
    }).catch(err => {
      if (err.cause && err.cause.code === 'ENOENT') return [];
github tajpure / hexo-editor / models / file-manager.js View on Github external
getDraftItems() {
    return fs.listDir(this.draft_dir, []);
  }
github tajpure / hexo-editor / models / file-manager.js View on Github external
getItems() {
    return fs.listDir(this.post_dir, []);
  }
github tajpure / hexo-editor / models / file-manager.js View on Github external
getTrashItems() {
    return fs.listDir(this.trash_dir, []);
  }
github hexojs / hexo / lib / hexo / load_scripts.js View on Github external
}).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);
    });
  });
};
github zthxxx / hexo-directory-category / lib / processor_post.js View on Github external
return fs.stat(assetDir).then(stats => {
      if (!stats.isDirectory()) return [];

      return fs.listDir(assetDir);
    }).catch(err => {
      if (err.cause && err.cause.code === 'ENOENT') return [];
github hexojs / hexo / lib / hexo / scaffold.js View on Github external
return exists(scaffoldDir).then(exist => {
      if (!exist) return [];

      return listDir(scaffoldDir, {
        ignoreFilesRegex: /^_|\/_/
      });
    }).map(item => ({
      name: item.substring(0, item.length - extname(item).length),