Question on renderOrder, to access data assigned from plugins
See original GitHub issueI’m using the remark plugin, which now adds vFile.data
to the markdown pages.data
. It is working great, so I wrote another rehype plugin, to exctract an excerpt
(the first paragraph, with max length of 140 characters), from every blog post. The vfile.data.excerpt
gets appended to the page.data.excerpt
, like using the rehype-extract-toc
plugin.
Now using the .md
files layout file, I have access to the page.data
which includes:
url: "/posts/blog-post-02/",
excerpt: "Lorem markdownum exclamant. Saevit iussa, in parentem praenovimus gerit sceleratior ipse ima quam\nal...",
toc: [
{ depth: 2, value: "Praevisos ductae et poenae esse pereunt enituntur" },
{ depth: 2, value: "Illis Hyadasque dederat" },
{ depth: 2, value: "Adversi firmat nigra et traiectus quos" },
{ depth: 2, value: "Dignior lucis multa comitavit tenet" }
],
In my index.tsx
page file, for which the excerpt
data was supposed to be, I loop through the posts:
export default ({ search }: SiteData) => {
const posts = search.pages("type=post", "date=desc", 3);
return (
<section>
<h1>Recent blog posts</h1>
{posts.map(({ data }) => (
<article>
<h2>{data.title as string}</h2>
{data.excerpt}
</article>
))}
</section>
);
};
Here I don’t have access to the data, since like I read in the docs render order, the pages didn’t exist before the index
page was rendered. I tried changing the renderOrder
from all posts inside ./posts/_data.ts
: export const renderOrder = -1;
But after build I can see no navbar items at all, (they are defined through menu
inside the pages), the blog posts getting displayed, but the page.data
still not contains excerpt
& toc
.
When I use export const renderOrder = 1;
inside the index page, the navbar does not contain the index page, the blog posts getting displayed, but the page.data
still not contains excerpt
& toc
.
Here is my _config.ts
order:
site
.copy("assets", ".")
.use(readingTime())
.use(date())
.use(slugifyUrls())
.use(remark({
remarkPlugins,
rehypePlugins,
}))
.use(preactjsx())
.use(postcss())
If you can give any advice, I would be pleased.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
What @oscarotero has suggested is a workaround and not a solution. We should have a discussion around how Lume can have an API for any data that is accessible to
search
andpaginate
that can be safely enriched by plugins.I was thinking about introducing some sort of global store that can be referred by
search
but this is something that needs deliberation and community feedback.The data object passed to the renderers is a copy of the original page data object (here: https://github.com/lumeland/lume/blob/master/core/renderer.ts#L240) to prevent issues caused by modify this object later (like here: https://github.com/lumeland/lume/blob/master/core/renderer.ts#L271-L272), specially after rendering the page again after an update.
This is the reason why data stored in this object is accessible only when the page is being rendered, but is not really stored in the
page.data
object, hence, is not present when retrieving this page withsearch
.One simple solution could be include the page in the data object, like:
So plugins can store data in the
data
object, like they do now or in thedata.page.data
object (so it’s persistent).