Get excerpt for regular topics

Hi, I had the same problem and managed to do it by fetching topic again to get needed data. I did that in topic-list-item.js component, by using Ember.PromiseProxyMixin. How to use it, read here: Using Ember.PromiseProxyMixin in discourse development

Code looks like something like this:

// I've used custom memoize function, to lower the number of requests
const getTopic = memoize(id => ajax(`/t/${id}.json`).then(data => data));
// ...
// Inside of component

  @discourseComputed("topic")
  topicPromise(topic) {
    return getTopic(topic.id);
  },

  @discourseComputed("topicPromise")
  topicProxy() {
    const promise = this.get("topicPromise");
    return promise && PromiseObject.create({ promise });
  },

  postStream: reads("topicProxy.content.post_stream"),

  @discourseComputed("postStream")
  excerpt(postStream) {
    if (!this.get("postStream")) return false;
    return `${stripHtml(postStream.posts[0].cooked).slice(0, 150)}...`;
  },

stripHtml is custom function to remove html from first post.

In topic-list-item.hbs you would have

  {{#if topicProxy.isFulfilled}}
    <div class="excerpt">
      {{#if excerpt}}
        {{html-safe excerpt}}
      {{/if}} 
    </div>
  {{/if}}