How to use the hexo-util.encodeURL 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 / helpers / open_graph.js View on Github external
it('url - IDN', () => {
    const ctx = {
      page: {},
      config: hexo.config,
      is_post: isPost,
      url: 'https://foô.com/bár'
    };

    const result = openGraph.call(ctx);

    result.should.contain(meta({property: 'og:url', content: encodeURL(ctx.url)}));
  });
github hexojs / hexo-generator-feed / test / index.js View on Github external
const checkURL = function(url, root) {
      hexo.config.url = url;
      hexo.config.root = root;

      const feedCfg = hexo.config.feed;
      const result = generator(locals, feedCfg.type, feedCfg.path);
      const $ = cheerio.load(result.data);

      if (url[url.length - 1] !== '/') url += '/';
      const punyIDN = encodeURL(url);
      $('feed>id').text().should.eql(punyIDN);
    };
github hexojs / hexo-renderer-marked / test / index.js View on Github external
const urlA = '/foo/bár.jpg';
      const urlB = 'http://fóo.com/bar.jpg';

      const body = [
        `![](${urlA})`,
        `![](${urlB})`
      ].join('\n');

      const r = require('../lib/renderer').bind(hexo);

      const result = await r({text: body});

      result.should.eql([
        `<p><img data-src="${encodeURL(urlA)}">`,
        `<img data-src="${encodeURL(urlB)}"></p>\n`
      ].join('\n'));
    });
  });
github hexojs / hexo / test / scripts / helpers / toc.js View on Github external
const zh = '这是-H1-标题';
    const zhs = zh.replace(/-/g, ' ');
    const de = 'Ich-♥-Deutsch';
    const des = de.replace(/-/g, ' ');
    const ru = 'Я-люблю-русский';
    const rus = ru.replace(/-/g, ' ');
    const input = [
      `<h1 id="${zh}">${zhs}</h1>`,
      `<h1 id="${de}">${des}</h1>`,
      `<h1 id="${ru}">${rus}</h1>`
    ].join('');

    const expected = [
      `<ol class="${className}">`,
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
      '</li></ol>'
    ].join('');

    toc(input, { list_number: false, class: className }).should.eql(expected);
  });
github hexojs / hexo / test / scripts / helpers / toc.js View on Github external
const des = de.replace(/-/g, ' ');
    const ru = 'Я-люблю-русский';
    const rus = ru.replace(/-/g, ' ');
    const input = [
      `<h1 id="${zh}">${zhs}</h1>`,
      `<h1 id="${de}">${des}</h1>`,
      `<h1 id="${ru}">${rus}</h1>`
    ].join('');

    const expected = [
      `<ol class="${className}">`,
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
      '</li></ol>'
    ].join('');

    toc(input, { list_number: false, class: className }).should.eql(expected);
  });
github hexojs / hexo / test / scripts / helpers / toc.js View on Github external
const input = [
      `<h1 id="${zh}">${zhs}</h1>`,
      `<h1 id="${de}">${des}</h1>`,
      `<h1 id="${ru}">${rus}</h1>`
    ].join('');

    const expected = [
      `<ol class="${className}">`,
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
      '</li>',
      `<li class="${className}-item ${className}-level-1">`,
      `<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
      '</li></ol>'
    ].join('');

    toc(input, { list_number: false, class: className }).should.eql(expected);
  });
github hexojs / hexo / lib / plugins / helper / open_graph.js View on Github external
}

  let result = '';

  if (description) {
    result += meta('description', description);
  }

  result += og('og:type', type);
  result += og('og:title', title);

  if (url) {
    if (config.pretty_urls.trailing_index === false) {
      url = url.replace(/index\.html$/, '');
    }
    url = encodeURL(url);
  }
  result += og('og:url', url);

  result += og('og:site_name', siteName);
  if (description) {
    result += og('og:description', description);
  }

  if (language) {
    if (language.length === 2) {
      language = language.replace(localeRegex, str => localeMap[str]);
      result += og('og:locale', language);
    } else if (language.length === 5) {
      const territory = language.slice(-2);
      const territoryRegex = new RegExp(territory.concat('$'));
github ppoffice / hexo-theme-icarus / layout / misc / open_graph.jsx View on Github external
images,
            keywords,
            twitterId
        } = this.props;

        const htmlTags = [];

        if (description) {
            description = escapeHTML(stripHTML(description).substring(0, 200).trim())
                .replace(/\n/g, ' ');
            htmlTags.push();
        }

        htmlTags.push();
        htmlTags.push();
        htmlTags.push();
        htmlTags.push();

        if (description) {
            htmlTags.push();
        }

        if (language) {
            if (language.length === 2) {
                language = language.replace(localeRegex, str =&gt; localeMap[str]);
                htmlTags.push();
            } else if (language.length === 5) {
                const territory = language.slice(-2);
                const territoryRegex = new RegExp(territory.concat('$'));
                language = language.replace('-', '_').replace(territoryRegex, territory.toUpperCase());
                htmlTags.push();
            }