获取常规主题的摘要

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 个赞

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:

https://github.com/discourse/discourse-tooltips/blob/master/app/controllers/discourse_tooltips/tooltip_previews_controller.rb

@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 个赞

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:

3 个赞

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.

你好,我也遇到过同样的问题,通过重新获取主题来获取所需数据解决了。我在 topic-list-item.js 组件中使用了 Ember.PromiseProxyMixin 来实现。如何使用它,请阅读这里:Use Ember.PromiseProxyMixin in a theme

代码大致如下:

// 我使用了自定义的 memoize 函数来减少请求次数
const getTopic = memoize(id => ajax(`/t/${id}.json`).then(data => data));
// ...
// 在组件内部

  @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 是一个自定义函数,用于移除首帖中的 HTML。

topic-list-item.hbs 中,你可以这样写:

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

您是否为列表中的每个主题都额外发起一次请求以获取摘要?

不幸的是,确实如此。我知道这会影响性能,但决定权不在我手里,你懂的。

你一定会喜欢的

5 个赞

天哪!为什么那个被隐藏了?:smiley:

2 个赞

因为有很多管理员会不看说明就点击所有设置,从而产生大量支持工单。这意味着许多实例会携带更重的负载,却从未使用来自 API 的额外数据。

很快,主题将能够以声明方式启用这些序列化器更改

5 个赞

此主题已在 3184 天后自动关闭。不再允许回复。