diff --git a/layout/common/scripts.ejs b/layout/common/scripts.ejs
index d2da751..813165c 100644
--- a/layout/common/scripts.ejs
+++ b/layout/common/scripts.ejs
@@ -2,8 +2,23 @@
<%- _js(cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')) %>
+<%
+let externalLink = get_config('external_link');
+if (typeof externalLink === 'boolean') {
+ externalLink = { enable: externalLink, exclude: [] };
+} else {
+ externalLink = {
+ enable: typeof externalLink.enable === 'boolean' ? externalLink.enable : true,
+ exclude: externalLink.exclude || []
+ };
+}
+%>
<% if (get_config('article.highlight.clipboard')) { %>
- <%- _js(cdn('clipboard', '2.0.4', 'dist/clipboard.min.js'), true) %>
+<%- _js(cdn('clipboard', '2.0.4', 'dist/clipboard.min.js'), true) %>
<% } %>
<% if (has_config('plugins')) { %>
- <% for (let plugin in get_config('plugins')) { %>
- <%- _partial('plugin/' + plugin, { head: false, plugin: get_config('plugins')[plugin] }) %>
- <% } %>
+<% for (let plugin in get_config('plugins')) { %>
+<%- _partial('plugin/' + plugin, { head: false, plugin: get_config('plugins')[plugin] }) %>
+<% } %>
<% } %>
<%- _js('js/main', true) %>
\ No newline at end of file
diff --git a/package.json b/package.json
index a4f3123..148fc84 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,8 @@
{
"name": "hexo-theme-icarus",
"version": "2.6.0",
- "private": true
-}
+ "private": true,
+ "engines": {
+ "node": ">=8.3.0"
+ }
+}
\ No newline at end of file
diff --git a/source/js/main.js b/source/js/main.js
index f35c60f..4597251 100644
--- a/source/js/main.js
+++ b/source/js/main.js
@@ -103,4 +103,49 @@
$mask.on('click', toggleToc);
$('.navbar-main .catalogue').on('click', toggleToc);
}
+
+ // hexo-util/lib/is_external_link.js
+ function isExternalLink(input, sitehost, exclude) {
+ try {
+ sitehost = new URL(sitehost).hostname;
+ } catch (e) { }
+
+ if (!sitehost) return false;
+
+ // handle relative url
+ const data = new URL(input, 'http://' + sitehost);
+
+ // handle mailto: javascript: vbscript: and so on
+ if (data.origin === 'null') return false;
+
+ const host = data.hostname;
+
+ if (exclude) {
+ exclude = Array.isArray(exclude) ? exclude : [exclude];
+
+ if (exclude && exclude.length) {
+ for (const i of exclude) {
+ if (host === i) return false;
+ }
+ }
+ }
+
+ if (host !== sitehost) return true;
+
+ return false;
+ }
+
+ if (typeof (IcarusThemeSettings) !== 'undefined' &&
+ typeof (IcarusThemeSettings.site.url) !== 'undefined' &&
+ typeof (IcarusThemeSettings.site.external_link) !== 'undefined' &&
+ IcarusThemeSettings.site.external_link.enable) {
+ $('.article .content a').filter(function (i, link) {
+ return link.href && link.classList.length === 0 && isExternalLink(link.href,
+ IcarusThemeSettings.site.url,
+ IcarusThemeSettings.site.external_link.exclude);
+ }).each(function (i, link) {
+ link.relList.add('noopener');
+ link.target = '_blank';
+ });
+ }
})(jQuery);