How to add custom topic map code?

AI-generated summary

The discussion focuses on adding custom topic map code to Discourse. amotl asks how to implement a JavaScript snippet to display the topic map on posts without replies, referencing a closed thread. Arkshine explains that the code can be added via a theme or theme component in the Admin panel, specifically in the Head section. amotl confirms it works, praising the improvements by @pmusaraj, @Don, and @JammyDodger that enable the topic map to display even on posts with no comments.

Hi again, I am continuing the discussion from Show topic-map without a reply, because it has been closed. [1]

That’s super sweet. Thank you, Jammy. May I humbly ask how/where this JavaScript snippet should be applied to make it work?

<script type="text/discourse-plugin" version="0.8">
  api.includePostAttributes('topicMap');
</script>

  1. a) Why? b) Feel free to refactor and/or re-open, as you see fit. ↩︎

Hi,

You can add it to your theme or in a new theme component HTML.

Usually, in a theme or component (Admin → Customize → Themes), you click on Edit CSS/HTML:

Then, you click on Head and you can insert the code there:

That’s it! :slight_smile:

Dear Arkshine,

that worked like a charm, thank you. For example, on this post, there have been no comments yet, so we never have been able to know about its pageviews, and other metadata.

With the improvements implemented by @pmusaraj [1], shared by @Don [2], and popularized by @JammyDodger, it works like DWIM. I love it, thank you very much!


  1. FIX: Don't force show topic map on non-first posts · Pull Request #19302 · discourse/discourse ↩︎

  2. How to show topic-map on non-commented posts? - #15 by Don ↩︎