Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support wildcard domain #33

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 'exclude1.com' now apply to `www.exclude1.com` and `en.exclude1.com` in this [commit](https://github.com/tangkunyin/hexo-filter-nofollow/commit/cf05a07054536dfaa36f986493e678252f31ad45)
- 'exclude1.com' apply to `www.exclude1.com` and `en.exclude1.com`.

6 changes: 3 additions & 3 deletions lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function isExternal(url, config) {

if (exclude && exclude.length) {
for (const i of exclude) {
if (host === i) return false;
if (i === host || (host && host.endsWith(i))) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary repetition

}
}

if (host !== sitehost) return true;
if (sitehost !== host && (host && !host.endsWith(sitehost))) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For host to be null, it is recommended to use early return


return false;
}
Expand All @@ -34,7 +34,7 @@ module.exports = function(data) {
return data.replace(/<a.*?(href=['"](.*?)['"]).*?>/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) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-filter-nofollow",
"version": "2.0.2",
"version": "2.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to modify it

"description": "Add nofollow attribute to all external links automatically",
"main": "index.js",
"directories": {
Expand Down
Loading