Skip to content

Commit

Permalink
refactor: access url methods directly
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Aug 23, 2019
1 parent 8e8a043 commit 7d1ab81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const micromatch = require('micromatch');
const template = require('./template');
const url = require('url');
const { format, parse } = require('url');

module.exports = function(locals) {
const config = this.config;
Expand All @@ -26,10 +26,10 @@ module.exports = function(locals) {
})
.map(post => ({
...post,
permalink: url.format({
protocol: url.parse(post.permalink).protocol,
hostname: url.parse(post.permalink).hostname,
pathname: encodeURI(url.parse(post.permalink).pathname)
permalink: format({
protocol: parse(post.permalink).protocol,
hostname: parse(post.permalink).hostname,
pathname: encodeURI(parse(post.permalink).pathname)
})
}));

Expand Down
10 changes: 5 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const should = require('chai').should(); // eslint-disable-line
const Hexo = require('hexo');
const cheerio = require('cheerio');
const urlFn = require('url');
const { format, parse } = require('url');

describe('Sitemap generator', () => {
const hexo = new Hexo(__dirname, {silent: true});
Expand Down Expand Up @@ -71,10 +71,10 @@ describe('Sitemap generator', () => {

it('IDN handling', () => {
hexo.config.url = 'http://fôo.com/bár';
const parsedUrl = urlFn.format({
protocol: urlFn.parse(hexo.config.url).protocol,
hostname: urlFn.parse(hexo.config.url).hostname,
pathname: encodeURI(urlFn.parse(hexo.config.url).pathname)
const parsedUrl = format({
protocol: parse(hexo.config.url).protocol,
hostname: parse(hexo.config.url).hostname,
pathname: encodeURI(parse(hexo.config.url).pathname)
});

const result = generator(locals);
Expand Down

0 comments on commit 7d1ab81

Please sign in to comment.