From 7821062db15192e7a685272e937f888881750851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9F=9A=E5=AD=90?= <76462613+uuznn@users.noreply.github.com> Date: Wed, 17 Feb 2021 11:56:05 +0800 Subject: [PATCH] Add exturl icon option (#192) --- _config.yml | 2 ++ scripts/filters/post.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/_config.yml b/_config.yml index d804b75..cd65f3b 100644 --- a/_config.yml +++ b/_config.yml @@ -461,6 +461,8 @@ index_with_subtitle: false # Automatically add external URL with Base64 encrypt & decrypt. exturl: false +# If true, an icon will be attached to each external URL +exturl_icon: true # Google Webmaster tools verification. # See: https://developers.google.com/search diff --git a/scripts/filters/post.js b/scripts/filters/post.js index d40cef2..87e7026 100644 --- a/scripts/filters/post.js +++ b/scripts/filters/post.js @@ -13,6 +13,8 @@ hexo.extend.filter.register('after_post_render', data => { } if (theme.exturl) { const siteHost = parse(config.url).hostname || config.url; + // External URL icon + const exturlIcon = theme.exturl_icon ? '' : ''; data.content = data.content.replace(/]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => { // Exit if the href attribute doesn't exists. if (!href) return match; @@ -23,9 +25,9 @@ hexo.extend.filter.register('after_post_render', data => { // Return encrypted URL with title. const title = match.match(/title="([^"]+)"/); - if (title) return `${html}`; + if (title) return `${html}${exturlIcon}`; - return `${html}`; + return `${html}${exturlIcon}`; }); }