Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
});
});
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
};
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];
}