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

Add a BlackFriday option for rel="nofollow" on external links #4722

Closed
Jos512 opened this Issue May 14, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@Jos512

Jos512 commented May 14, 2018

BlackFriday can already be configured to open external links in a new tab. It would be quite helpful if we can also specify the rel=nofollow tag on external links.

Luckily, BlackFriday already seems to have a feature for that: the HTML_NOFOLLOW_LINKS constant flag. That GoDoc link doesn't state it, but it seems to be implemented in such a way that the rel=nofollow tag is added to external links only. That would mean this BlackFriday feature is a good solution for this feature request, without adjustments or modifications on the part of Hugo's code base.


It might probably also useful to expose the HTML_NOREFERRER_LINKS BlackFriday setting at the same time, since it's a related link setting and might save work in having to revisit in the future. But I don't want to make the scope of this issue too big, so this is just a suggestion for the developer.


The forum discussion of this feature is here: Setting rel=“nofollow” for external links in all articles.

@kaushalmodi

This comment has been minimized.

Member

kaushalmodi commented May 14, 2018

Even if this feature gets implemented in hugo, I believe that the rel="nofollow" will still not be added correctly. See this related hugoDocs issue: gohugoio/hugoDocs#428.

The problem is that Blackfriday's check for external link doesn't always work as intended.. it assumes that the link is external if the link is not relative:

if options.flags&HTML_NOFOLLOW_LINKS != 0 && !isRelativeLink(link) {
		relAttrs = append(relAttrs, "nofollow")
}

See the isRelativeLink function definition.. what if the user has set the canonifyURLs to true, or if a link is created using absURL? In those cases, even if the link is not external, isRelativeLink will eval to false, and consider internal links as external.

So implementing this feature won't always work as expected i.e. nofollow will be added for internal links too.

I add rel="nofollow" to the external links on my site using this very unconventional way.. though only for target="_blank" links.

@Jos512

This comment has been minimized.

Jos512 commented May 15, 2018

The problem is that Blackfriday's check for external link doesn't always work as intended.. it assumes that the link is external if the link is not relative.

I didn't know that, and I assume a lot of people didn't since I can't find a Hugo issue for this. Is this problem big enough for people that it should hold up this issue? It sounds more like a documentation issue or perhaps an improvement to BlackFriday's HTML_HREF_TARGET_BLANK feature. But those two things are definitely out of scope for this issue, and likely deserve their own ticket.

This is about exposing the HTML_NOFOLLOW_LINKS the BlackFriday setting in Hugo. That would create behaviour that me and others in the forum thread would probably be happy with 98% of the time, with the small caveat that absolute internal links are also seen as external. Once your Hugo docs issue gets documented, people also know about that.

But I'm of course with you that BlackFriday's isRelativeLink() function could be improved so that internal, absolute links are not seen as external. But should we make a Hugo issue for this or take it up to BlackFriday?

@kaushalmodi

This comment has been minimized.

Member

kaushalmodi commented May 15, 2018

This is about exposing the HTML_NOFOLLOW_LINKS the BlackFriday setting in Hugo.

I agree.

But should we make a Hugo issue for this or take it up to BlackFriday?

That should be a Blackfriday issue.

stefanneuhaus added a commit to stefanneuhaus/hugo that referenced this issue May 27, 2018

Add a BlackFriday option for rel="nofollow" on external links
Add a configuration option "nofollowLinks". When set to "true" the "HTML_NOFOLLOW_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "nofollow" value for the "rel" attribute.

Fixes gohugoio#4722

stefanneuhaus added a commit to stefanneuhaus/hugo that referenced this issue May 27, 2018

Add a BlackFriday option for rel="noreferrer" on external links
Add a configuration option "noreferrerLinks". When set to "true" the "HTML_NOREFERRER_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "noreferrer" value for their "rel" attribute.

See gohugoio#4722

@bep bep closed this in #4788 May 27, 2018

bep added a commit that referenced this issue May 27, 2018

Add a BlackFriday option for rel="nofollow" on external links
Add a configuration option "nofollowLinks". When set to "true" the "HTML_NOFOLLOW_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "nofollow" value for the "rel" attribute.

Fixes #4722

stefanneuhaus added a commit to stefanneuhaus/hugo that referenced this issue May 28, 2018

Add a BlackFriday option for rel="noreferrer" on external links
Add a configuration option "noreferrerLinks". When set to "true" the "HTML_NOREFERRER_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "noreferrer" value for their "rel" attribute.

See gohugoio#4722

bep added a commit that referenced this issue May 29, 2018

Add a BlackFriday option for rel="noreferrer" on external links
Add a configuration option "noreferrerLinks". When set to "true" the "HTML_NOREFERRER_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "noreferrer" value for their "rel" attribute.

See #4722
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment