How to use the hexo-util.slugize function in hexo-util

To help you get started, we’ve selected a few hexo-util 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 greg-js / hexo-cli-extras / lib / rename.js View on Github external
function renameFile(art, renamed) {

      var src = art.full_source;
      var newSrc = path.join(src.substr(0, src.lastIndexOf(path.sep)), slugize(renamed, {transform: 1}));

      // first the markdown file
      return fsRename(src, newSrc + '.md').then(function doRenameMd() {
        var fldr;

        console.log(chalk.red(src) + ' renamed to ' + chalk.green(newSrc) + '.md');

        fldr = src.substr(0, src.lastIndexOf('.'));

        // then the folder if it exists
        return fsStat(fldr).then(function doCheckDir(stats) {
          if (stats.isDirectory()) {
            return fsRename(fldr, newSrc).then(function doRenameDir() {
              console.log(chalk.underline('Asset folder renamed as well.'));
            });
          } else {
github hexojs / hexo / lib / hexo / post.js View on Github external
Post.prototype.publish = function(data, replace, callback) {
  if (!callback && typeof replace === 'function') {
    callback = replace;
    replace = false;
  }

  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);
github screeps / docs / api / scripts / tag-api_method.js View on Github external
hexo.extend.tag.register('api_method', function(args) {
  if(args[2] === undefined) {
    args[2] = args[1];
    args[1] = '';
  }
  var name = args[0];
  const mr = this.raw.match(/^\# (\S+)/);
  if(mr) {
    name = mr[1] ? `${mr[1]}.${name}` : name;
  } else {
    if(this.parentTitle) {
      name = `${this.parentTitle}.${name}`;
    }
  }

  var id = util.slugize(name, {separator: '.'});

  var signatures = args[1].split('|').map(i =&gt; `(${i})`).join('<br>');
  var inherited = '';
  var cpuDescription = {
    0: 'This method has insignificant CPU cost.',
    1: 'This method has low CPU cost.',
    2: 'This method has medium CPU cost.',
    3: 'This method has high CPU cost.',
    A: 'This method is an action that changes game state. It has additional 0.2 CPU cost added to its natural cost in case if OK code is returned.',
  };
  var m = args[0].match(/^(.*?):(.*)$/);
  if(m) {
    args[0] = m[2];
    inherited = `<div class="api-property__inherited">Inherited from <a href="#${m[1]}">${m[1]}</a></div>`;
  }
  var opts = {};
github screeps / docs / api / scripts / tag-api_property.js View on Github external
hexo.extend.tag.register('api_property', function (args) {
    var name = args[0], inherited = '';
    var m = name.match(/^(.*?):(.*)$/);
    if (m) {
        name = m[2];
        inherited = `<div class="api-property__inherited">Inherited from <a href="#${m[1]}">${m[1]}</a></div>`;
    }

    var opts = {};
    if(args[2]) {
        opts = JSON.parse(args[2]);
    }

    var id = util.slugize(name.trim());
    var result = `<h2 class="api-property api-property--property ${inherited ? 'api-property--inherited' : ''} ${opts.deprecated ? 'api-property--deprecated' : ''}" id="${id}">${inherited}<span class="api-property__name">${name}</span><span class="api-property__type">${args[1]}</span></h2>`;
    if (opts.deprecated) {
        var text = 'This property is deprecated and will be removed soon.';
        if (opts.deprecated !== true) {
            text += ' ' + opts.deprecated;
        }
        text = hexo.render.renderSync({text, engine: 'markdown'});
        result += `<div class="api-deprecated">${text}</div>`
    }
    return result;
}, {async: false});
github hexojs / hexo-renderer-marked / lib / renderer.js View on Github external
const anchorId = (str, transformOption) => {
  return slugize(str.trim(), {transform: transformOption});
};
github hexojs / hexo / lib / plugins / processor / post.js View on Github external
day: /(\d{2})/,
        i_month: /(\d{1,2})/,
        i_day: /(\d{1,2})/,
        hash: /([0-9a-f]{12})/
      }
    });
  }

  const data = permalink.parse(path);

  if (data) {
    return data;
  }

  return {
    title: slugize(path)
  };
}
github greg-js / hexo-cli-extras / lib / rename.js View on Github external
function chooseRenameStyle(post) {
      var message = '\n - Rename title (' + chalk.green.underline(post.title) + ') to ' +
          chalk.cyan.underline(newName) + ' ?\n - Rename filename (' +
          chalk.green.underline(post.source.substr(post.source.lastIndexOf(path.sep))) + ') to ' +
          chalk.cyan.underline(slugize(newName, {transform: 1}) + '.md') + ' ?';

      return inquirer.prompt([
        {
          type: 'list',
          message: message,
          name: 'answer',
          choices: [
            'Yes, rename both',
            'Title only please (don\'t rename the file!)',
            'Filename only please (don\'t rename the title!)',
            'No, forget it, cancel everything.',
          ],
        },
      ]).then(function processRes(response) {
        var ans = response.answer;
github hexojs / hexo / lib / models / tag.js View on Github external
Tag.virtual('slug').get(function() {
    const map = ctx.config.tag_map || {};
    let name = this.name;
    if (!name) return;

    if (Reflect.apply(hasOwn, map, [name])) {
      name = map[name] || name;
    }

    return slugize(name, {transform: ctx.config.filename_case});
  });