Get excerpt for regular topics

Hi,
I’m using Discourse API for get the latest topics for specific category(works great!):

http://haxe.org.il/c/15/l/latest.json?

but I want to get excerpt for all topics not just topics…
How can I do that?
Thanks,
Michael

There currently isn’t a get parameter to request excerpts, but it’s on the list of feature requests.

2 Likes

Hi.
It has been a few years, is it still impossible to do? I’m looking to display my lastest Discourse posts on a WP site and that would be an excellent feature.

Yeah this exists if you install this plugin:

Per:

@codinghorror I wonder should we just roll in the functionality of discourse tooltip, it will help keep it more stable over time and helps a tiny bit in some desktop situations.

4 Likes

I am fairly strongly opposed, because hover means nothing on touch and we should not be relying on non-touch behaviors at all. And given that the world will be 99.9% smartphone usage soon… it’s backwards thinking.

Hi,
I’ve installed and enabled this plugin. It works but I still don’t have the excerpts from other topics than pinned in top.json data.

I believe you need to do another request for the excerpts, like:

https://github.com/discourse/discourse-tooltips/blob/34e3ed2086f69df181cdb7868869ea44a6c7a1f0/assets/javascripts/mixins/topic-hover-extension.js.es6#L74

3 Likes

Hi, I know this is an old topic, but I am having the same issue.

My rss feed is working fine, but I rather use the Json one as it is more flexible.

So I have a php plugin that pulls discourse json feed ( latest, top, etc), everything works fine… expect the excerpt

Is there is reason why there is no post description on the Json feed? How can I fix this ?

Thanks.

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}}

Are you making an extra request for each topic in the list to fetch the excerpt?

Unfortunately, yes. I know that’s hit on performance, but I don’t make the decisions, if you know what I mean.

You gonna love this

5 Likes

OMG! Why is that hidden?! :smiley:

2 Likes

Because there is a lot of support topics from admins who go and click on all the settings without reading. That means lots of instances would have a heavier payload without ever using the extra data coming from the API.

Soon, themes will be able to declaratively enable those serializer changes.

5 Likes