From cf05a07054536dfaa36f986493e678252f31ad45 Mon Sep 17 00:00:00 2001 From: Thomas Tang Date: Tue, 20 Aug 2024 13:17:26 +0800 Subject: [PATCH 1/3] support wildcard domain name Signed-off-by: Thomas Tang --- lib/filter.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index ba020b9..a3d0ef6 100755 --- a/lib/filter.js +++ b/lib/filter.js @@ -12,11 +12,11 @@ function isExternal(url, config) { if (exclude && exclude.length) { for (const i of exclude) { - if (host === i) return false; + if (host === i || host.endsWith(i)) return false; } } - if (host !== sitehost) return true; + if (host !== sitehost && !host.endsWith(sitehost)) return true; return false; } @@ -34,7 +34,7 @@ module.exports = function(data) { return data.replace(//gi, (str, hrefStr, href) => { if (!isExternal(href, config)) return str; - let noFollow = ['noopener', 'external', 'nofollow', 'noreferrer']; + let noFollow = ['external', 'nofollow', 'noreferrer', 'noopener']; if (/rel=/gi.test(str)) { str = str.replace(/\srel="(.*?)"/gi, (relStr, rel) => { diff --git a/package.json b/package.json index c929917..84706ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-filter-nofollow", - "version": "2.0.2", + "version": "2.0.3", "description": "Add nofollow attribute to all external links automatically", "main": "index.js", "directories": { From e33d859e0e08a1272a4d763e71003aed3aae2754 Mon Sep 17 00:00:00 2001 From: Thomas Tang Date: Tue, 20 Aug 2024 13:38:29 +0800 Subject: [PATCH 2/3] update readme for support wildcard domain Signed-off-by: Thomas Tang --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68b30d5..d37c50c 100644 --- a/README.md +++ b/README.md @@ -30,5 +30,5 @@ nofollow: - **field** - The scope you want the plugin to proceed, can be 'site' or 'post'. Default value is `site`. - 'post' - Only add nofollow attribute to external links in your post content - 'site' - Add nofollow attribute to external links of whole sites -- **exclude** - Exclude hostname. Specify subdomain when applicable, including `www`. - - 'exclude1.com' does not apply to `www.exclude1.com` nor `en.exclude1.com`. +- **exclude** - Exclude hostname. Subdomain also supported well, such as `www` or `app`. + - 'exclude1.com' now apply to `www.exclude1.com` and `en.exclude1.com` in this [commit](https://github.com/tangkunyin/hexo-filter-nofollow/commit/cf05a07054536dfaa36f986493e678252f31ad45) From 83c141112c5cfa8aaf966130c3b5704ca7b6842f Mon Sep 17 00:00:00 2001 From: Thomas Tang Date: Tue, 20 Aug 2024 14:12:27 +0800 Subject: [PATCH 3/3] fix host null exception Signed-off-by: Thomas Tang --- lib/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index a3d0ef6..0a64294 100755 --- a/lib/filter.js +++ b/lib/filter.js @@ -12,11 +12,11 @@ function isExternal(url, config) { if (exclude && exclude.length) { for (const i of exclude) { - if (host === i || host.endsWith(i)) return false; + if (i === host || (host && host.endsWith(i))) return false; } } - if (host !== sitehost && !host.endsWith(sitehost)) return true; + if (sitehost !== host && (host && !host.endsWith(sitehost))) return true; return false; }