Skip to content

Commit 382b0de

Browse files
committed
fix: use url.resolve() as a workaround for Windows compatibility
1 parent 6aeab6f commit 382b0de

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

lib/plugins/tag/asset_img.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const { resolve } = require('url');
34
const img = require('./img');
45
const { encodeURL } = require('hexo-util');
56

@@ -19,7 +20,7 @@ module.exports = ctx => {
1920
for (let i = 0; i < len; i++) {
2021
const asset = PostAsset.findOne({post: this._id, slug: args[i]});
2122
if (asset) {
22-
args[i] = encodeURL('/' + asset.path);
23+
args[i] = encodeURL(resolve('/', asset.path));
2324
return img(ctx)(args);
2425
}
2526
}

lib/plugins/tag/asset_link.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const url = require('url');
43
const { encodeURL, escapeHTML } = require('hexo-util');
4+
const { resolve } = require('url');
55

66
/**
77
* Asset link tag
@@ -29,8 +29,9 @@ module.exports = ctx => {
2929
let title = args.length ? args.join(' ') : asset.slug;
3030
const attrTitle = escapeHTML(title);
3131
if (escape === 'true') title = attrTitle;
32-
const link = encodeURL(url_for.call(ctx, asset.path));
3332

34-
return `<a href="${url.resolve(ctx.config.root, asset.path)}" title="${attrTitle}">${title}</a>`;
33+
const link = encodeURL(resolve(ctx.config.root, asset.path));
34+
35+
return `<a href="${link}" title="${attrTitle}">${title}</a>`;
3536
};
3637
};

lib/plugins/tag/asset_path.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const url_for = require('../helper/url_for');
3+
const { resolve } = require('url');
4+
const { encodeURL } = require('hexo-util');
45

56
/**
67
* Asset path tag
@@ -18,7 +19,7 @@ module.exports = ctx => {
1819
const asset = PostAsset.findOne({post: this._id, slug});
1920
if (!asset) return;
2021

21-
const path = url_for.call(ctx, asset.path);
22+
const path = encodeURL(resolve(ctx.config.root, asset.path));
2223

2324
return path;
2425
};

lib/plugins/tag/post_link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

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

56
/**
67
* Post link tag
@@ -28,10 +29,9 @@ module.exports = ctx => {
2829
let title = args.length ? args.join(' ') : post.title;
2930
const attrTitle = escapeHTML(title);
3031
if (escape === 'true') title = attrTitle;
31-
const title = args.length ? args.join(' ') : post.title;
3232

33-
const link = url_for.call(ctx, post.path);
33+
const link = encodeURL(resolve(ctx.config.root, post.path));
3434

35-
return `<a href="${ctx.config.root}${post.path}" title="${attrTitle}">${title}</a>`;
35+
return `<a href="${link}" title="${attrTitle}">${title}</a>`;
3636
};
3737
};

lib/plugins/tag/post_path.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const url_for = require('../helper/url_for');
3+
const { resolve } = require('url');
4+
const { encodeURL } = require('hexo-util');
45

56
/**
67
* Post path tag
@@ -18,7 +19,7 @@ module.exports = ctx => {
1819
const post = Post.findOne({slug});
1920
if (!post) return;
2021

21-
const link = url_for.call(ctx, post.path);
22+
const link = encodeURL(resolve(ctx.config.root, post.path));
2223

2324
return link;
2425
};

0 commit comments

Comments
 (0)