Skip to content

Commit

Permalink
refactor: use the WHATWG URL API instead of url.resolve (#5136)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Dec 31, 2022
1 parent d485ebd commit 4f2dde4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/plugins/tag/asset_img.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { resolve } = require('url');
const img = require('./img');
const { encodeURL } = require('hexo-util');

Expand All @@ -20,7 +19,7 @@ module.exports = ctx => {
for (let i = 0; i < len; i++) {
const asset = PostAsset.findOne({post: this._id, slug: args[i]});
if (asset) {
args[i] = encodeURL(resolve('/', asset.path));
args[i] = encodeURL(new URL(asset.path, ctx.config.url).pathname);
return img(ctx)(args);
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/tag/asset_link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { encodeURL, escapeHTML } = require('hexo-util');
const { resolve } = require('url');

/**
* Asset link tag
Expand Down Expand Up @@ -30,7 +29,7 @@ module.exports = ctx => {
const attrTitle = escapeHTML(title);
if (escape === 'true') title = attrTitle;

const link = encodeURL(resolve(ctx.config.root, asset.path));
const link = encodeURL(new URL(asset.path, ctx.config.url).pathname);

return `<a href="${link}" title="${attrTitle}">${title}</a>`;
};
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/tag/asset_path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { resolve } = require('url');
const { encodeURL } = require('hexo-util');

/**
Expand All @@ -19,7 +18,7 @@ module.exports = ctx => {
const asset = PostAsset.findOne({post: this._id, slug});
if (!asset) return;

const path = encodeURL(resolve(ctx.config.root, asset.path));
const path = encodeURL(new URL(asset.path, ctx.config.url).pathname);

return path;
};
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/tag/post_link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { encodeURL, escapeHTML } = require('hexo-util');
const { resolve } = require('url');
const { postFindOneFactory } = require('./');

/**
Expand Down Expand Up @@ -35,7 +34,7 @@ module.exports = ctx => {
const attrTitle = escapeHTML(post.title);
if (escape === 'true') title = escapeHTML(title);

const link = encodeURL(resolve(ctx.config.root, post.path));
const link = encodeURL(new URL(post.path, ctx.config.url).pathname);

return `<a href="${link}" title="${attrTitle}">${title}</a>`;
};
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/tag/post_path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { resolve } = require('url');
const { encodeURL } = require('hexo-util');
const { postFindOneFactory } = require('./');

Expand All @@ -19,7 +18,7 @@ module.exports = ctx => {
const post = factory({ slug }) || factory({ title: slug });
if (!post) return;

const link = encodeURL(resolve(ctx.config.root, post.path));
const link = encodeURL(new URL(post.path, ctx.config.url).pathname);

return link;
};
Expand Down

0 comments on commit 4f2dde4

Please sign in to comment.