Show post numbers

Awesome! You figured out how to do it. :+1:

Here are a few improvements you can do:

  • api.decoratedCooked will be deprecated and is called on every post.
    You can use decorateCookedElement instead, which works without jQuery.

  • An element representing the current post is passed to the API; you can use it as your post context.

  • You can work with the schedule function from ember to wait for the element to be rendered.

import { schedule } from "@ember/runloop";
// const { schedule } = require("@ember/runloop");  // use this if running in Admin UI

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

image

3 Likes