Get topic URL in a widget


#1

I am building a widget to show a list of topics from a category on a sidebar. My helper function that loads the topics is the following:

		export function getLatestPosts(context) {
		  const store = context.container.lookup('store:main');
		  var topics = [];

		  return store.findFiltered("topicList", {filter: "c/categorySlug"}).then((result) => {
		    return result.topic_list.topics;
		  }).catch(() => {
		    console.log('failed')
		    return [];
		  })
		}

Each returned topic is then displayed in a widget that has the following code:

import { createWidget } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';

createWidget('sidebar-post-item', {
  tagName: 'div.sidebar-post-item',

  html(attrs) {

    return [
      h('span.item-title', attrs.title),
      h('span.comments', attrs.reply_count || '0'),
      h('span', this.attach('featured-link', {topic: attrs}))
    ]
  },
});

However, I am not sure how I can link the topic to its page… is there a way I can use the topic-link helper, for example?

Side question: the featured-link widget that is attached, is from the Discourse links category plugin. I am trying to make my code available as a plugin, so I am also wondering whether I can attach this widget if it is available. Is there a way I can check whether that particular widget is available?