The discussion revolves around rewriting external URLs in Discourse, particularly for affiliate links. kam44 initially attempted to use the “Watched Words” feature with regex, but without success. JammyDodger suggested the “Linkify Words” theme component, which kam44 tried but also had no success.
kam44 shared their regex attempts, and pfaffman pointed out that the issue might be with the replacement rather than the match. renato mentioned the Discourse Affiliate plugin, which supports Amazon and another site, but kam44 considered forking it for custom affiliate links.
pfaffman discovered a conflict with the “enable markdown linkify” setting, which might be the root cause of the issue. Steven also encountered this conflict. pfaffman proposed a simpler solution using a theme component, sharing their own component as an example.
renato highlighted the difference between a theme component and a plugin like Discourse Affiliate, which changes the link in the cooked content, making it work outside the web application. pfaffman acknowledged this point, noting that changing cooked posts requires a plugin.
I enjoy using Discourse feature that automatically converts watched words into links. However, I’m also looking for a way to auto-convert external links, primarily to insert affiliate links (other than Amazon). I attempted to achieve this using the regex option in watched words, but it doesn’t seem to work for links. Does anyone have any suggestions?
It looks that way to me too. I created a replacement for https://www.digitalocean.com/ → https://m.do.co/c/a5bf212d9a92/ and if enable markdown linkify is on, it doesn’t work, and if it’s off, it does. What I’d really like is for it to re-write the link.
That’s likely overkill. If you just want to rewrite some urls, you don’t need much. I have a theme component that rewrites one boxes.
I have a theme component that finds one-boxes from a certain domain and rewrites them as <iframes> appropriate to that site. It shouldn’t be too hard (for someone with skills as meager as mine) to change it to re-write your links.
The main difference with an approach like Discourse Affiliate’s is that it changes the link in the cooked content, so it will also work outside the web application, like in emails or if using a different client (very, very rare). Just something to be aware of.