Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hexo.on('generateBefore', function () {
const site = hexo.config;
const theme = hexo.theme.config;
const email = theme.profile && theme.profile.email || site.email || '';
const feed = site.feed ? urlFor.call(this, site.feed.path) : '';
const result = utils.parseConfig(configSchema, theme, {
$email: email,
$feed: feed,
$copyright: `© ${new Date().getFullYear()} • <a href="${site.url}">${site.author}</a>`,
$gravatar: gravatar(email, 160),
$title: site.title,
$description: site.description
});
const urlFn = result.static_prefix ?
a => utils.isExternal(a) ? a : `${result.static_prefix}/${a}` :
urlFor.bind(this);
// override default language
site.language = utils.localeId(site.language);
const __ = this.theme.i18n.__(site.language);
return pages.map(page => {
page.link = urlFor.call(this, page.slug);
page.slug = classifyPage(page, true);
page.comments = comments && page.comments;
return {
index: page.slug,
type: 'page',
data: pick(page, pageProps)
};
});
}
...posts.map(post => {
post.link = urlFor.call(this, path.dirname(post.path));
post.comments = comments && post.comments;
if (post.toc === undefined || post.toc) {
const toc = parseToc(post.content, config.toc && config.toc.depth);
if (toc.length) post.toc = toc;
else delete post.toc;
} else delete post.toc;
return {
index: post.slug,
type: 'post',
data: pick(post, postProps)
};
}),