Obtenez un extrait pour les sujets réguliers

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 « J'aime »

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 « J'aime »

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 « J'aime »

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.

Bonjour, j’ai rencontré le même problème et j’ai réussi à le résoudre en récupérant à nouveau le sujet pour obtenir les données nécessaires. Je l’ai fait dans le composant topic-list-item.js en utilisant Ember.PromiseProxyMixin. Pour savoir comment l’utiliser, lisez ici : Use Ember.PromiseProxyMixin in a theme

Le code ressemble à ceci :

// J'ai utilisé une fonction memoize personnalisée pour réduire le nombre de requêtes
const getTopic = memoize(id => ajax(`/t/${id}.json`).then(data => data));
// ...
// À l'intérieur du composant

  @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 est une fonction personnalisée pour supprimer le HTML du premier message.

Dans topic-list-item.hbs, vous auriez :

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

Faites-vous une requête supplémentaire pour chaque sujet de la liste afin de récupérer l’extrait ?

Malheureusement, oui. Je sais que cela impacte les performances, mais je ne prends pas les décisions, si vous voyez ce que je veux dire.

Vous allez adorer ça

5 « J'aime »

OMG ! Pourquoi c’est caché ?! :smiley:

2 « J'aime »

Parce qu’il y a de nombreuses questions de support de la part d’administrateurs qui cliquent sur tous les paramètres sans les lire. Cela signifie que de nombreuses instances auraient une charge utile plus lourde sans jamais utiliser les données supplémentaires provenant de l’API.

Bientôt, les thèmes pourront activer de manière déclarative ces modifications de sérialisation.

5 « J'aime »

Ce sujet a été automatiquement fermé après 3184 jours. Les nouvelles réponses ne sont plus autorisées.