Mostrar números de publicaciones

Is it possible to show post numbers for each post (Or easy to do via CSS or similar). My use case is running forum mafia, where allowing users to easily refer to a post without the bulk of quoting it would be amazing.

1 me gusta

Just press the link button under each post, and the post number is visible there.

It is hard to say if this is what you are looking for, but it should get you close.

https://github.com/sitepoint/discourse-theme/blob/b4b4a7218ffbbfd4ee3cf8aa7421d29c96fdc4ed/assets/stylesheets/desktop/topic-post.scss#L45-L51

We use that CSS to put #1, #2, et al on a topic after the date/timestamp.

10 Me gusta

Yes, it is, this is amazing :slight_smile:

Thanks so much!

a.post-date span {
  margin-right: 1em;
}

a.post-date:after {
  content: "#"attr(data-post-number);
}

Esto ya no parece funcionar. ¿Hay alguna forma actual de mostrar los números de las publicaciones?

2 Me gusta

Ahora la etiqueta post no tiene un identificador data-post-number, este estilo CSS no funciona, ¿hay alguna otra forma de solucionarlo?

No sin javascript.

3 Me gusta

Gracias por la respuesta, ¿es este un plugin que necesita ser escrito para llamar a la API? ¿O está simplemente escrito en el componente del tema?

¡Muchas gracias! ¡Ya he resuelto el problema!

api.decorateCooked(() => {
          var add_post_number_timer = setTimeout(() => {
            var articles = document.getElementsByTagName("article");
            for (var i = 0; i < articles.length; i++) {
              var post_date = articles[i].getElementsByClassName("post-date");
              if (post_date.length != 0) {
                var post_number = articles[i].getAttribute("id").replace("post_", "");
                post_date[1].setAttribute("data-post-number", post_number);
              }
            }
            clearTimeout(add_post_number_timer);
          }, 500);
        }, {
        id: 'add_post_number'
    });

¡Genial! Descubriste cómo hacerlo. :+1:

Aquí tienes algunas mejoras que puedes hacer:

  • api.decoratedCooked será obsoleto y se llama en cada publicación.
    Puedes usar decorateCookedElement en su lugar, que funciona sin jQuery.

  • Se pasa un element que representa la publicación actual a la API; puedes usarlo como contexto de tu publicación.

  • Puedes trabajar con la función schedule de ember para esperar a que se renderice el elemento.

import { schedule } from "@ember/runloop";
// const { schedule } = require("@ember/runloop");  // usa esto si se ejecuta en Admin UI

api.decorateCookedElement((element,  /* helper */) => {
  schedule("afterRender", () => {
    const article = element.closest("article");
    if (article) {
      article.dataset.postNumber = article.id.replace("post_", "");
    }
  });
});

image

3 Me gusta

:+1: Muchas gracias por la corrección.