How to use the hexo-util.createSha1Hash 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 hexojs / hexo / test / scripts / filters / new_post_path.js View on Github external
it('hash', () => {
    const now = moment();
    const slug = 'foo';
    const sha1 = createSha1Hash();
    const hash = sha1.update(slug + now.unix().toString())
      .digest('hex').slice(0, 12);
    hexo.config.new_post_name = ':title-:hash';

    return newPostPath({
      slug,
      title: 'tree',
      date: now.format('YYYY-MM-DD HH:mm:ss')
    }).then(target => {
      target.should.eql(pathFn.join(postDir, `${slug}-${hash}.md`));
      hexo.config.new_post_name = NEW_POST_NAME;
    });
  });
github hexojs / hexo / lib / plugins / filter / post_permalink.js View on Github external
function postPermalinkFilter(data) {
  const { config } = this;
  const { id, _id, slug, title, date } = data;
  const hash = slug && date
    ? createSha1Hash().update(slug + date.unix().toString()).digest('hex').slice(0, 12)
    : null;
  const meta = {
    id: id || _id,
    title: slug,
    name: typeof slug === 'string' ? basename(slug) : '',
    post_title: slugize(title, {transform: 1}),
    year: date.format('YYYY'),
    month: date.format('MM'),
    day: date.format('DD'),
    hour: date.format('HH'),
    minute: date.format('mm'),
    i_month: date.format('M'),
    i_day: date.format('D'),
    hash
  };
github hexojs / hexo / lib / plugins / filter / new_post_path.js View on Github external
target = join(postDir, path);
    }
  } else if (slug) {
    switch (layout) {
      case 'page':
        target = join(sourceDir, slug, 'index');
        break;

      case 'draft':
        target = join(draftDir, slug);
        break;

      default: {
        const date = moment(data.date || Date.now());
        const keys = Object.keys(data);
        const hash = createSha1Hash().update(slug + date.unix().toString())
          .digest('hex').slice(0, 12);

        const filenameData = {
          year: date.format('YYYY'),
          month: date.format('MM'),
          i_month: date.format('M'),
          day: date.format('DD'),
          i_day: date.format('D'),
          title: slug,
          hash
        };

        for (let i = 0, len = keys.length; i < len; i++) {
          const key = keys[i];
          if (!reservedKeys[key]) filenameData[key] = data[key];
        }