How to use hexo - 10 common examples

To help you get started, we’ve selected a few hexo 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 ikeq / hexo-theme-inside / lib / filter / post.js View on Github external
if (data.layout !== 'page' && data.layout !== 'post') return;

  const config = this.config;
  const theme = this.theme.config;
  const isPage = data.layout === 'page';

  if (hasComments === undefined)
    hasComments = !!(theme.comments || theme.plugins && theme.plugins.comments);
  if (hasReward === undefined)
    hasReward = !!theme.reward;
  if (hasToc === undefined)
    hasToc = !!theme.toc;
  if (copyright === undefined)
    copyright = theme.copyright;
  if (dateHelper === undefined)
    dateHelper = date.bind({ page: { lang: localeId(config.language, true) }, config })
  if (uriReplacer === undefined) {
    uriReplacer = (() => {
      let assetsFn = src => src;
      if (theme.assets) {
        const prefix = theme.assets.prefix ? theme.assets.prefix + '/' : ''
        const suffix = theme.assets.suffix || ''
        assetsFn = src => prefix + `${src}${suffix}`.replace(/\/{2,}/g, '/')
      }

      return (src, assetPath) => {
        assetPath = assetPath ? assetPath + '/' : ''

        // skip both external and absolute path
        return /^(\/\/?|http|data\:image)/.test(src) ? src : assetsFn(`${assetPath}${src}`);
      }
    })();
github ikeq / hexo-theme-inside / lib / config.js View on Github external
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 =&gt; 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 &amp;&amp; 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
github ikeq / hexo-theme-inside / lib / config.js View on Github external
hexo.on('generateBefore', function () {
    const site = hexo.config;
    const theme = hexo.theme.config;
    const email = theme.profile &amp;&amp; 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 =&gt; 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);
github ikeq / hexo-theme-inside / test / scripts / helpers / structured_data.js View on Github external
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());
github ikeq / hexo-theme-inside / test / scripts / helpers / theme_static.js View on Github external
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/);
github ikeq / hexo-theme-inside / lib / generator / api / page.js View on Github external
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)
    };
  });
}
github ikeq / hexo-theme-inside / lib / generator / api / post.js View on Github external
...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)
      };
    }),
github ikeq / hexo-theme-inside / lib / generator / entries / archives.js View on Github external
module.exports = function ({ site, theme, locals, helpers }) {
  const posts = locals.posts.map(pick(archiveProps));
  const config = theme.archive;
  const dateHelper = date.bind({ page: { lang: localeId(site.language, true) }, config })

  if (!posts.length) return [];

  return flattenDeep(
    helpers.pagination.apply(posts, { perPage: config.per_page, id: 'archives' }, [
      { type: 'json', dataFn: classify },
      { type: 'html', extend: { type: 'archives' } },
    ])
  );

  /**
   * Classify posts with `year` and `month`
   *
   * @param {object} data
   * @returns {data}
   */
github ppoffice / hexo-theme-icarus / include / filter / locals.js View on Github external
module.exports = hexo => {
    const RESERVED_KEYS = {
        post: Object.keys(require('hexo/lib/models/post')(hexo).paths),
        page: Object.keys(require('hexo/lib/models/page')(hexo).paths)
    };

    function getThemeConfig(extension) {
        if (fs.existsSync(path.join(hexo.theme_dir, '_config' + extension + '.yml'))) {
            return yaml.safeLoad(fs.readFileSync(path.join(hexo.theme_dir, '_config' + extension + '.yml')));
        }
        return null;
    }

    const ALTERNATIVE_CONFIG = {
        post: getThemeConfig('.post'),
        page: getThemeConfig('.page')
    }

    function getExtraConfig(source, reservedKeys) {
        const result = {};
github ppoffice / hexo-theme-icarus / include / filter / locals.js View on Github external
module.exports = hexo => {
    const RESERVED_KEYS = {
        post: Object.keys(require('hexo/lib/models/post')(hexo).paths),
        page: Object.keys(require('hexo/lib/models/page')(hexo).paths)
    };

    function getThemeConfig(extension) {
        if (fs.existsSync(path.join(hexo.theme_dir, '_config' + extension + '.yml'))) {
            return yaml.safeLoad(fs.readFileSync(path.join(hexo.theme_dir, '_config' + extension + '.yml')));
        }
        return null;
    }

    const ALTERNATIVE_CONFIG = {
        post: getThemeConfig('.post'),
        page: getThemeConfig('.page')
    }

    function getExtraConfig(source, reservedKeys) {