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);
if (!result.data_prefix) result.data_prefix = result.data_dir;
// attach disqus script
if (result.comments && result.comments.disqus) {
const disqus = result.comments.disqus;
disqus.script = disqus.script || `//${disqus.shortname}.disqus.com/embed.js`;
delete disqus.shortname;
}
// convert menu to array
describe('structured_data', function () {
const Hexo = require('hexo');
const hexo = new Hexo();
const ctx = {
url_for: urlFor.bind(hexo),
config: hexo.config,
theme: { profile: {}, sns: {} }
};
const structuredData = require('../../../lib/helper/structured_data').bind(ctx);
it('generate WebSite entry', function () {
const $ = cheerio.load(structuredData({}));
const json = JSON.parse($('script').html());
expect(json.length).toBe(1);
expect(json[0]['@type']).toBe('WebSite');
});
it('generate additional Article entry for post page', function () {
const $ = cheerio.load(structuredData({ type: 'post', categories: { toArray() { return [] } } }));
const json = JSON.parse($('script').html());
describe('theme_static', function () {
const Hexo = require('hexo');
const hexo = new Hexo();
const ctx = {
url_for: urlFor.bind(hexo),
config: hexo.config,
theme: { theme: {} }
};
const themeStatic = require('../../../lib/helper/theme_static').bind(ctx);
it('css', function () {
const $ = cheerio.load(themeStatic('css'));
expect($('link').eq(0).attr('href')).toMatch(/^\/styles\.\w*\.css$/);
});
it('js', function () {
const $ = cheerio.load(themeStatic('js'));
expect($('script').eq(0).attr('src')).toMatch(/^\/runtime/);
expect($('script').eq(1).attr('src')).toMatch(/^\/polyfills/);
expect($('script').eq(2).attr('src')).toMatch(/^\/polyfills/);
expect($('script').eq(3).attr('src')).toMatch(/^\/main/);