API or other way to generate topicId and discourseEmbedUrl list


(maiki) #1

I have Discourse comment embedding for a site generated by Hugo. Everything works fine, killer set up. My site outputs a few different formats, not all for a web browser. Also, a lot of my visitors use text browsers. So I was thinking of including a link to the topic, for all those folks that won’t see the thread load on the page.

It is kinda dicey, but I can obviously construct URLs with a pattern like https://discourse.example.org/t/$SLUG/, and that works for most cases, but doesn’t feel as nice as just linking to the exact URL as Discourse knows it.

Hugo has a function called getJSON, so I figured I would just call that at build time and key the values off of the discourseEmbedUrl, but I don’t think that is included in any output.

An aside: Do you know there are docs for the Discourse API?! I have mostly gotten along without them, but they also make an excellent reference.

http://docs.discourse.org

The question

Is there currently a way to pull in the discourseEmbedUrl fields for posts in JSON? And by that I mean without directly accessing the database as well.

Alternatively, is there a pattern to permalink generation in Discourse that can be used here?