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

Adding rel=nofollow to all links #201

Open
jwr opened this issue Apr 17, 2024 · 7 comments
Open

Adding rel=nofollow to all links #201

jwr opened this issue Apr 17, 2024 · 7 comments

Comments

@jwr
Copy link
Contributor

jwr commented Apr 17, 2024

Short of patching markdown-clj, is there a way to add rel="nofollow" to all links?

This is pretty much a requirement for any user-supplied text that will be displayed on a public webpage, otherwise the SEO spamming crowd will eat you alive.

I've been looking at transformers, but it doesn't seem like they are created for that use case.

@yogthos
Copy link
Owner

yogthos commented Apr 17, 2024

You could potentially wrap the built in href transformer with your own that will inject rel="nofollow". I would definitely be open to a pr to facilitate this though. This would be the namespace to do it https://github.com/yogthos/markdown-clj/blob/master/src/cljc/markdown/links.cljc

@jwr
Copy link
Contributor Author

jwr commented Apr 17, 2024

While I do understand the intention of getting more people to contribute with PRs, I am not sure if this is the best way to proceed. This is something that requires design and my ideas might be very far from acceptable to you.

I would probably add global options that would be passed alongside state to all transformers, where each transformer could get at its options and use them. The href transformer would use :attributes, where one could specify :rel "nofollow,ugc", for example. This is likely not the best, or even a good way to implement this kind of functionality…

@yogthos
Copy link
Owner

yogthos commented Apr 17, 2024

There's actually some precedent for doing this already with :code-style option, so we could add more options :attributes would be ambiguous though, since you might want to set attributes for different elements. Perhaps, better approach might be to key on the transformer or tag type. For example, maybe could add :href {:attributes {:rel "nofollow,ugc"}}, or even just :href {:rel "nofollow,ugc"}.

I do think that the case could be addressed by making a custom transformer vector with the way things are currently set up. You would need a custom version of this vector where you replace the transformer for the tags with your custom version

https://github.com/yogthos/markdown-clj/blob/master/src/cljc/markdown/transformers.cljc#L423

@jwr
Copy link
Contributor Author

jwr commented Apr 19, 2024

Thank you. I don't think I'm capable of designing this properly, so I've worked around the issue by copying large swaths of code from markdown.links (href, make-link and link), so that I could replace href with href-nofollow that adds the rel=nofollow attribute.

@yogthos
Copy link
Owner

yogthos commented Apr 19, 2024

No worries, glad to hear the immediate issue is solved. I'll leave this open as an enhancement, if I get a bit of time I'll look at implementing the feature.

@coreagile
Copy link

Just to chime in, I'd also like to modify links. Like, for example, adding target=_blank -- probably will fit in to your existing design?

@yogthos
Copy link
Owner

yogthos commented May 1, 2024

It sounds like the best approach here might be to allow passing around a map of options, such as attributes, that can be applied to each type of element. These could then be applied by the transformers. If anybody wants to try to adding this in, I can definitely help guide a pr, but I probably won't have time to look myself in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants