Linkify Words

Hi, thanks for developing this amazing theme, I loved it so much! Could you release this for all users to use? And not only admin

GitHub - renato/discourse-imgify-words: theme to auto imgify urls in discourse, almost the same as discourse-linkify-works

Hi,

This theme component you linked is an adaptation of Sam’s that I did as a workaround for a need you described in another topic.

They are simple theme components which only change how these words are rendered in a post (Sam’s converts specific words to links, mine converts specific words to images) based on the theme component settings, which are only managed by admins.

The feature you describe can’t be done in a theme component, it would need a plugin to store a per-user set of (word, image url) in the database and the word to image conversion should be done server-side, when building the cooked post (as HTML) content. These can’t be done in a theme component, which is only frontend/client-side code (if you hire someone to do this work it’s critical that they understand these details).

This is out of scope of this theme component and would need a way more involved work. The suggestion is to post the details of how you want this feature to behave on #marketplace and you can hire someone here with prior experience with the Discourse internals to help you.

Thanks for letting me know, I’ll go in that category and talk about it

It’s been brought up many times in this topic, but I’d like to check again; is there any way to restrict this to a certain category or exclude categories? I would like to use this in our beginner’s category to have links to all the basic terms newbs need to learn, but in other areas, these would just be annoying to the experienced users. Thanks!

2 Likes

I found an annoying limitation: given a regular expression, $1 is only replaced exactly once.

Example

/foo-([0-9a-f]+)/,https://target.example/foo/$1/foo-$1

Expected

keyword link
foo-abcd https://target.example/foo/abcd/foo-abcd

Actual

keyword link
foo-abcd https://target.example/foo/abcd/foo-$1

The trouble with watched words is, that a watched word is linked as many times as the watched word appears in a post. It makes a mess.

P.S. Say that three times fast. :grin:

To be precise, the word is replaced once per line, not once per whole post. :slight_smile:

I wish that were true Coin, but it’s not on my install. :frowning:

Here’s how it works on my test instance:

:thinking:

Check this out…

My rule:

The result:

@Canapin you overlooked my issue: it’s not about repeated words, but about repeated pattern replacement of a single word: the URL contains the pattern to be replaced twice.

Since the /g pattern substitution option is default in the plugin, it should apply to all occurrences of $1 in the replacement, not just for the first one.

It’s a different case than having the keyword appear multiple times in a sentence, line, or paragraph. The replacement should account for multiple occurrences of the selection.

1 Like

I was talking about the linkify word component, not the watched words feature :slight_smile:

@hellekin, thanks for the clarification :+1:

I was responding to Sam about watched words. :grin:

Good to know linkify only does one, but would love it one per post. I may have to try this out today, watched words is unbearable at times when it finds a match.

1 Like

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