From 06a8ebbcb1cbb5d0dc6aae4035f396d12716ddb0 Mon Sep 17 00:00:00 2001 From: KentarouTakeda Date: Thu, 8 Sep 2022 03:00:29 +0900 Subject: [PATCH] fix(#5053): exclude data-uri image for og:image (#5053) --- lib/plugins/helper/open_graph.js | 3 ++- test/scripts/helpers/open_graph.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js index 35d8beb12e..3f35ed82e4 100644 --- a/lib/plugins/helper/open_graph.js +++ b/lib/plugins/helper/open_graph.js @@ -115,7 +115,8 @@ function openGraphHelper(options = {}) { result += og('og:locale', localeToTerritory(language), false); } - images = images.map(path => new URL(path, url || config.url).toString()); + images = images.map(path => new URL(path, url || config.url).toString()) + .filter(url => !url.startsWith('data:')); images.forEach(path => { result += og('og:image', path, false); diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js index c709e7fa17..be2fb2ecb1 100644 --- a/test/scripts/helpers/open_graph.js +++ b/test/scripts/helpers/open_graph.js @@ -211,6 +211,18 @@ describe('open_graph', () => { result.should.have.string(meta({property: 'og:image', content: 'https://hexo.io/test.jpg'})); }); + it('images - content with data-uri', () => { + const result = openGraph.call({ + page: { + content: '' + }, + config: hexo.config, + is_post: isPost + }); + + result.should.not.have.string(meta({property: 'og:image', content: 'data:image/svg+xml;utf8,...'})); + }); + it('images - string', () => { const result = openGraph.call({ page: {