Awesome! You figured out how to do it. ![]()
Here are a few improvements you can do:
-
api.decoratedCookedwill be deprecated and is called on every post.
You can usedecorateCookedElementinstead, which works without jQuery. -
An
elementrepresenting the current post is passed to the API; you can use it as your post context. -
You can work with the
schedulefunction 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_", "");
}
});
});
