Auto-Linkify Words

Likely because folks don’t know, I got referred to this post looking for solution to link search words to topics and my default reaction was to install this component. I didn’t even realize that watched words existed. It’s so cool how much I learn about discourse every time I try to optimize it.

If you’re okay I’m going to edit the first post to let folks know that watched words exist and may be an out of box fit. Also this theme is marked as official so if it’s a duplicate of watched words maybe consider depreciating it or indicating it on the first post.

1 Like

I have a feature request. It would be wonderful if we could have this only apply to body text and not headings, it looks silly when one word in a heading is linked:

Sometimes, there are too many same linkify words in long content.
I think it be better to display in only first one in content. The others could be bold, instead of links.

2 Likes

Seems like you should be able to do that by adding h1 h2 and others to the " excluded tags" setting in the extension, no?

Thanks Matt, I think you mean excluded classes, which I somehow didn’t notice before, but unfortunately these are not working so I guess this is a bug report rather than a feature request.

The screenshot I posted earlier is an h2 with class of anchor.

No, I meant tags. Those are HTML tags, not discourse topic tags, as I understand it.

Indeed, you are correct! Thank you Matt. I was too fixated on tags being discourse tags. I appreciate your help.

1 Like

Can you tell me if it is possible to import multiple linkify words at the same time or use the API to connect to a management file on Google Sheets? I have an idea about using this TC in managing and creating multiple glossaries

I find this theme component interesting and useful, but it links keywords too many times, attaching it correctly is only attaching the first word to reduce spam.

I sent an attached image and it repeats 3 times for 1 keyword. I hope this part will be fixed in the next update.

3 Likes

Hi! Thanks for the great plugin!

Quick question: can it still match words even if they don’t have spaces before or after them? I remember it used to match without needing spaces around the word.

2 Likes

Hi there, is there a way to set links to target=“_self”? By default, they all open in a new tab (target=“_blank”), but I couldn’t find any setting to change this.

Tks a lot

https://meta.discourse.org/my/preferences/interface

and search for Open all external links in a new tab. It defaults to off because that’s Best Practice. You can use /admin/site_settings/category/all_results?filter=external%20links to change the default for all users.

1 Like

The preference works for normal links in the post, but for me those created by this component always open in a new tab. Does the preference change the behavior of links created by this component for you? I wonder what I am missing.

1 Like

Oops. Sorry. I didn’t notice that. You’re right. It’s hard-coded to blank:

Sounds like a reasonable feature request to me.

Wait. I was really not paying attention. If there is going to be a hard-coded option, ignoring the user preferences, it should be to open in the same window. That’s what the best practice is. And if the linkified links go to Discouse and not somewhere external then it’s an even more unexpected behavior that they’d open in a new tab.

2 Likes

I’ve tried to fix this with JavaScript (code below), but it only works occasionally. I believe Ember.js might be conflicting with it. So it’s not ideal

<script>
	window.addEventListener("load", function() {
		document.querySelectorAll("a.linkify-word.no-track-link").forEach(function(link) {
			link.removeAttribute("target");
		});
	});
</script>

A better solution would be to fork the theme component and/or submit a PR.

1 Like

I don’t know what it’s worth, but I asked ChatGPT for a way to add a backend checkbox to toggle between target=“_self” and target=“_blank”. Here’s what it suggested:

Code for settings.yaml:

self_target:
  type: bool
  default: false
  client: true

Code for initialize-discourse-linkify.js:

  let createLink = function (text, url) {
	let link = document.createElement("a");
	link.innerHTML = text;
	link.href = url;
	link.rel = "nofollow";
	link.target = settings.self_target ? "_self" : "_blank"; // Use the admin setting here
	link.className = "linkify-word no-track-link";
	return link;
  };

Do you think this might work ?