From b94846d7254511368a300c75c7d7d844de676434 Mon Sep 17 00:00:00 2001
From: MDLeom <43627182+curbengh@users.noreply.github.com>
Date: Sat, 15 Aug 2020 10:25:01 +0000
Subject: [PATCH 1/2] refactor: replace url.resolve() with String.replace()
---
lib/plugins/tag/asset_img.js | 3 +--
lib/plugins/tag/asset_link.js | 3 +--
lib/plugins/tag/asset_path.js | 3 +--
lib/plugins/tag/post_link.js | 3 +--
lib/plugins/tag/post_path.js | 3 +--
5 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/lib/plugins/tag/asset_img.js b/lib/plugins/tag/asset_img.js
index df1b67bd34..b8160a8f95 100644
--- a/lib/plugins/tag/asset_img.js
+++ b/lib/plugins/tag/asset_img.js
@@ -1,6 +1,5 @@
'use strict';
-const { resolve } = require('url');
const img = require('./img');
const { encodeURL } = require('hexo-util');
@@ -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(('/' + asset.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
return img(ctx)(args);
}
}
diff --git a/lib/plugins/tag/asset_link.js b/lib/plugins/tag/asset_link.js
index c51dc3e005..40c98bcaaf 100644
--- a/lib/plugins/tag/asset_link.js
+++ b/lib/plugins/tag/asset_link.js
@@ -1,7 +1,6 @@
'use strict';
const { encodeURL, escapeHTML } = require('hexo-util');
-const { resolve } = require('url');
/**
* Asset link tag
@@ -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((ctx.config.root + asset.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
return `${title}`;
};
diff --git a/lib/plugins/tag/asset_path.js b/lib/plugins/tag/asset_path.js
index 88be887673..f32f613f53 100644
--- a/lib/plugins/tag/asset_path.js
+++ b/lib/plugins/tag/asset_path.js
@@ -1,6 +1,5 @@
'use strict';
-const { resolve } = require('url');
const { encodeURL } = require('hexo-util');
/**
@@ -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((ctx.config.root + asset.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
return path;
};
diff --git a/lib/plugins/tag/post_link.js b/lib/plugins/tag/post_link.js
index a5df3fa23d..da676cd747 100644
--- a/lib/plugins/tag/post_link.js
+++ b/lib/plugins/tag/post_link.js
@@ -1,7 +1,6 @@
'use strict';
const { encodeURL, escapeHTML } = require('hexo-util');
-const { resolve } = require('url');
/**
* Post link tag
@@ -31,7 +30,7 @@ module.exports = ctx => {
const attrTitle = escapeHTML(title);
if (escape === 'true') title = attrTitle;
- const link = encodeURL(resolve(ctx.config.root, post.path));
+ const link = encodeURL((ctx.config.root + post.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
return `${title}`;
};
diff --git a/lib/plugins/tag/post_path.js b/lib/plugins/tag/post_path.js
index e156c9deaa..764674f268 100644
--- a/lib/plugins/tag/post_path.js
+++ b/lib/plugins/tag/post_path.js
@@ -1,6 +1,5 @@
'use strict';
-const { resolve } = require('url');
const { encodeURL } = require('hexo-util');
/**
@@ -19,7 +18,7 @@ module.exports = ctx => {
const post = Post.findOne({slug});
if (!post) return;
- const link = encodeURL(resolve(ctx.config.root, post.path));
+ const link = encodeURL((ctx.config.root + post.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
return link;
};
From 27384cc49139156c51056a9f7a611c02882c54b2 Mon Sep 17 00:00:00 2001
From: MDLeom <43627182+curbengh@users.noreply.github.com>
Date: Sat, 15 Aug 2020 10:32:39 +0000
Subject: [PATCH 2/2] docs(open_graph): fix comment
---
lib/plugins/helper/open_graph.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index 71fb3cb5a4..8e15fd850c 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -119,7 +119,7 @@ function openGraphHelper(options = {}) {
images = images.map(path => {
if (!parse(path).host) {
// resolve `path`'s absolute path relative to current page's url
- // `path` can be both absolute (starts with `/`) or relative.
+ // `path` can be both absolute (starts with `http://`) or relative (starts with `/`).
return resolve(url || config.url, path);
}