Topic entrance like plugin for tags

AI-generated summary

A user, Eiji, is developing a Discourse plugin, “Topic entrance like plugin for tags.” The plugin aims to modify tag link behavior, showing two options when a tag is clicked: the normal tag URL and a related external page. The list of tags with corresponding external slugs will be stored in a Ruby array of hashes or JSON format.

Eiji has considered two methods from the Discourse API: addTagsHtmlCallback and replaceTagRenderer, but both require returning a raw string and don’t allow for writing and compiling Ember templates by hand.

After initial development, Eiji released the first version of the plugin, available on GitLab: https://gitlab.com/eiji-plugins/discourse/tag-link-popup. Eiji later shared an updated version, highlighting specific changes.

AstonJ expressed interest in using the plugin on Devtalk and requested feedback from experienced Discourse plugin developers to improve it.

Hi, I’m working on my first Discourse plugin.

The idea

We want to alter the tag links behaviour slightly, where, when a tag is clicked anywhere in Discourse, instead of going directly to it, it shows two options; the normal tag url (forum.com/tag/tag-name) or a related (external) page of our choice (something.site.com/some-name). This option would only show for that are in the list.

The list will be in the form of a Ruby array of hashes (or JSON) and this can either be added directly to the plug-in, or be made available at a URL. (The former seems like it will be more resource-friendly - we can just update the list and rebuild the plugin when it updates, as the updates won’t be that often.)

# Ruby array of hashes
array = [
  {forum_tag: "discourse", external_slug: "discourse"},
  {forum_tag: "dc", external_slug: "discourse"},
  {forum_tag: "xenforo", external_slug: "xenforo"},
  {forum_tag: "xf", external_slug: "xenforo"}
]

# OR

array.to_json
=> "[{\"forum_tag\":\"discourse\",\"external_slug\":\"discourse\"},{\"forum_tag\":\"dc\",\"external_slug\":\"discourse\"},{\"forum_tag\":\"xenforo\",\"external_slug\":\"xenforo\"},{\"forum_tag\":\"xf\",\"external_slug\":\"xenforo\"}]"

We basically want the option to display like when you click on a replies number on the main forum page:

My thoughts

I found 2 methods in Discourse API related to tags:

  1. addTagsHtmlCallback - In this case I would need to set topic.tags to empty array right after assigning its value to other variable. In that way I would prevent rendering tags and can write my custom code.

  2. replaceTagRenderer - The second one allows me to change tag render which does not look so hacky as 1st method.

However please look that in both cases I need to return raw string. From what I found I can’t write and compile Ember template by hand. Obviously I can just render custom links and write a simple function with jQuery putting it to root of app/assets/javascripts, but that’s way different solution comparing to Discourse code.

Am I on the right track? Any/all help will be very much appreciated.

For anyone interested I’m happy to announce a first release of my plugin!

Looking forward for your feedback!

For everyone interested I recommend to check the latest changes especially:

Good … day (?) for everyone!

:smiling_imp:

Nice one @Eiji!


We’re hoping to use this plugin on Devtalk… for anyone experienced with Discourse plugins could you take a look to see if any improvements can be made please? We’d appreciate it :blush: