From 79ef191dfcc9313399249bbce7563efa9a377a68 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Fri, 23 Aug 2019 07:45:20 +0930
Subject: [PATCH 01/10] fix(open_graph): support IDN url
---
lib/plugins/helper/open_graph.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index 0af4ef2c8b..a31cde5df3 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -90,6 +90,11 @@ function openGraphHelper(options = {}) {
url = url.replace(/index\.html$/, '');
}
+ url = urlFn.format({
+ protocol: urlFn.parse(url).protocol,
+ hostname: urlFn.parse(url).hostname,
+ pathname: encodeURI(urlFn.parse(url).pathname)
+ });
result += og('og:url', url, false);
result += og('og:site_name', siteName);
From 5043bac5f91b6efa317ee005f0745df13b3607e9 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Fri, 23 Aug 2019 08:17:51 +0930
Subject: [PATCH 02/10] test(open_graph): IDN handling
---
test/scripts/helpers/open_graph.js | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js
index 648046512e..d9c484a712 100644
--- a/test/scripts/helpers/open_graph.js
+++ b/test/scripts/helpers/open_graph.js
@@ -129,6 +129,19 @@ describe('open_graph', () => {
hexo.config.pretty_urls.trailing_index = true;
});
+ 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: 'https://xn--fo-9ja.com/b%C3%A1r'}));
+ });
+
it('images - content', () => {
const result = openGraph.call({
page: {
From c6190ca0b2602ee464b255461c8fd8b217ab779f Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Fri, 23 Aug 2019 09:07:43 +0930
Subject: [PATCH 03/10] fix(open_graph): do not format empty url
---
lib/plugins/helper/open_graph.js | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index a31cde5df3..a97436dae0 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -90,11 +90,13 @@ function openGraphHelper(options = {}) {
url = url.replace(/index\.html$/, '');
}
- url = urlFn.format({
- protocol: urlFn.parse(url).protocol,
- hostname: urlFn.parse(url).hostname,
- pathname: encodeURI(urlFn.parse(url).pathname)
- });
+ if (url) {
+ url = urlFn.format({
+ protocol: urlFn.parse(url).protocol,
+ hostname: urlFn.parse(url).hostname,
+ pathname: encodeURI(urlFn.parse(url).pathname)
+ });
+ }
result += og('og:url', url, false);
result += og('og:site_name', siteName);
From d5fb012e841f3a0a1d77c156263e3221967e9697 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Wed, 25 Sep 2019 02:25:09 +0100
Subject: [PATCH 04/10] refactor: utilize encodeURL of hexo-util
---
lib/plugins/helper/open_graph.js | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index a97436dae0..c3100a9ee6 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -2,7 +2,7 @@
const urlFn = require('url');
const moment = require('moment');
-const { escapeHTML, htmlTag, stripHTML } = require('hexo-util');
+const { encodeURL, escapeHTML, htmlTag, stripHTML } = require('hexo-util');
function meta(name, content, escape) {
if (escape !== false && typeof content === 'string') {
@@ -90,13 +90,7 @@ function openGraphHelper(options = {}) {
url = url.replace(/index\.html$/, '');
}
- if (url) {
- url = urlFn.format({
- protocol: urlFn.parse(url).protocol,
- hostname: urlFn.parse(url).hostname,
- pathname: encodeURI(urlFn.parse(url).pathname)
- });
- }
+ if (url) url = encodeURL(url);
result += og('og:url', url, false);
result += og('og:site_name', siteName);
From 8bd3439421e2b50799d13e1ba3f804d599c94962 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Wed, 25 Sep 2019 03:25:59 +0100
Subject: [PATCH 05/10] fix(open_graph): htmlTag escapes html by default
- https://github.com/hexojs/hexo-util/releases/tag/1.3.0
---
lib/plugins/helper/open_graph.js | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index c3100a9ee6..54e134dd17 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -2,24 +2,16 @@
const urlFn = require('url');
const moment = require('moment');
-const { encodeURL, escapeHTML, htmlTag, stripHTML } = require('hexo-util');
-
-function meta(name, content, escape) {
- if (escape !== false && typeof content === 'string') {
- content = escapeHTML(content);
- }
+const { encodeURL, htmlTag, stripHTML } = require('hexo-util');
+function meta(name, content) {
return `${htmlTag('meta', {
name,
content
})}\n`;
}
-function og(name, content, escape) {
- if (escape !== false && typeof content === 'string') {
- content = escapeHTML(content);
- }
-
+function og(name, content) {
return `${htmlTag('meta', {
property: name,
content
@@ -70,7 +62,7 @@ function openGraphHelper(options = {}) {
let result = '';
if (description) {
- result += meta('description', description, false);
+ result += meta('description', description);
}
if (keywords) {
@@ -91,15 +83,15 @@ function openGraphHelper(options = {}) {
}
if (url) url = encodeURL(url);
- result += og('og:url', url, false);
+ result += og('og:url', url);
result += og('og:site_name', siteName);
if (description) {
- result += og('og:description', description, false);
+ result += og('og:description', description);
}
if (language) {
- result += og('og:locale', language, false);
+ result += og('og:locale', language);
}
images = images.map(path => {
@@ -113,7 +105,7 @@ function openGraphHelper(options = {}) {
});
images.forEach(path => {
- result += og('og:image', path, false);
+ result += og('og:image', path);
});
if (updated) {
@@ -125,7 +117,7 @@ function openGraphHelper(options = {}) {
result += meta('twitter:card', twitterCard);
if (images.length) {
- result += meta('twitter:image', images[0], false);
+ result += meta('twitter:image', images[0]);
}
if (options.twitter_id) {
@@ -136,7 +128,7 @@ function openGraphHelper(options = {}) {
}
if (options.twitter_site) {
- result += meta('twitter:site', options.twitter_site, false);
+ result += meta('twitter:site', options.twitter_site);
}
if (options.google_plus) {
From e6ed3f829b8df43a187fcc31ba3d626b114976c4 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Wed, 25 Sep 2019 06:45:20 +0100
Subject: [PATCH 06/10] test(open_graph): avoid double-escaping
---
test/scripts/helpers/open_graph.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js
index d9c484a712..cffc4a63b4 100644
--- a/test/scripts/helpers/open_graph.js
+++ b/test/scripts/helpers/open_graph.js
@@ -10,6 +10,7 @@ describe('open_graph', () => {
const isPost = require('../../../lib/plugins/helper/is').post;
const tag = require('hexo-util').htmlTag;
const Post = hexo.model('Post');
+ const cheerio = require('cheerio');
function meta(options) {
return tag('meta', options);
@@ -591,7 +592,8 @@ describe('open_graph', () => {
const result = openGraph.call(ctx);
const keywords = 'optimize,web&<>"'/,site';
- result.should.contain(meta({name: 'keywords', content: keywords}));
+ const $ = cheerio.load(result, { decodeEntities: false });
+ $('meta[name="keywords"]').attr('content').should.eql(keywords);
});
it('og:locale - options.language', () => {
From 62e6e5c259d6d85c705a1fe7f1e13b139bdd64d6 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Wed, 25 Sep 2019 07:13:50 +0100
Subject: [PATCH 07/10] fix(open_graph): url might be null
---
lib/plugins/helper/open_graph.js | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js
index 54e134dd17..8fd03f8394 100644
--- a/lib/plugins/helper/open_graph.js
+++ b/lib/plugins/helper/open_graph.js
@@ -78,11 +78,12 @@ function openGraphHelper(options = {}) {
result += og('og:type', type);
result += og('og:title', title);
- if (config.pretty_urls.trailing_index === false) {
- url = url.replace(/index\.html$/, '');
+ if (url) {
+ if (config.pretty_urls.trailing_index === false) {
+ url = url.replace(/index\.html$/, '');
+ }
+ url = encodeURL(url);
}
-
- if (url) url = encodeURL(url);
result += og('og:url', url);
result += og('og:site_name', siteName);
From 02041eb705836d0c3c776a0abfb0fa4a5f9bc600 Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Mon, 7 Oct 2019 13:12:54 +0100
Subject: [PATCH 08/10] chore(deps): update hexo-util from ^1.3.1 to ^1.4.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 962c8e04fb..298392a387 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
"hexo-fs": "^2.0.0",
"hexo-i18n": "^1.0.0",
"hexo-log": "^1.0.0",
- "hexo-util": "^1.3.1",
+ "hexo-util": "^1.4.0",
"js-yaml": "^3.12.0",
"lodash": "^4.17.11",
"micromatch": "^4.0.2",
From 09ccc9f3f2ee48f09c4e9ac378c5efcc455f65be Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Mon, 7 Oct 2019 13:15:05 +0100
Subject: [PATCH 09/10] refactor: cheerio is no longer necessary
- https://github.com/hexojs/hexo-util/pull/104
- Revert 19902892c6a3fa64ae716a1e1ef0c85ea9fe7865
---
test/scripts/helpers/open_graph.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js
index cffc4a63b4..d9c484a712 100644
--- a/test/scripts/helpers/open_graph.js
+++ b/test/scripts/helpers/open_graph.js
@@ -10,7 +10,6 @@ describe('open_graph', () => {
const isPost = require('../../../lib/plugins/helper/is').post;
const tag = require('hexo-util').htmlTag;
const Post = hexo.model('Post');
- const cheerio = require('cheerio');
function meta(options) {
return tag('meta', options);
@@ -592,8 +591,7 @@ describe('open_graph', () => {
const result = openGraph.call(ctx);
const keywords = 'optimize,web&<>"'/,site';
- const $ = cheerio.load(result, { decodeEntities: false });
- $('meta[name="keywords"]').attr('content').should.eql(keywords);
+ result.should.contain(meta({name: 'keywords', content: keywords}));
});
it('og:locale - options.language', () => {
From 6f7fe0c36b71f4240e3ffe6cd235f2b07644d25a Mon Sep 17 00:00:00 2001
From: curbengh <43627182+curbengh@users.noreply.github.com>
Date: Mon, 7 Oct 2019 13:18:45 +0100
Subject: [PATCH 10/10] test(asset_img): attribute shouldn't be similar to
value, unless it's boolean
- https://github.com/hexojs/hexo-util/commit/622167f3cf98f08436b0fb0bc1a7bc7ec00904f4
---
test/scripts/tags/asset_img.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/test/scripts/tags/asset_img.js b/test/scripts/tags/asset_img.js
index 0adc7e60cb..d8f0709c09 100644
--- a/test/scripts/tags/asset_img.js
+++ b/test/scripts/tags/asset_img.js
@@ -50,7 +50,7 @@ describe('asset_img', () => {
});
it('default', () => {
- assetImg('bar title').should.eql('');
+ assetImg('bar "a title"').should.eql('');
});
it('with space', () => {
@@ -60,13 +60,13 @@ describe('asset_img', () => {
});
it('with alt and title', () => {
- assetImgTag.call(post, ['bar', '"title"', '"alt"'])
- .should.eql('');
+ assetImgTag.call(post, ['bar', '"a title"', '"an alt"'])
+ .should.eql('');
});
it('with width height alt and title', () => {
- assetImgTag.call(post, ['bar', '100', '200', '"title"', '"alt"'])
- .should.eql('');
+ assetImgTag.call(post, ['bar', '100', '200', '"a title"', '"an alt"'])
+ .should.eql('');
});
it('no slug', () => {