question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question on renderOrder, to access data assigned from plugins

See original GitHub issue

I’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:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
naiyerasifcommented, Jul 23, 2022

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 and paginate 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.

0reactions
oscaroterocommented, Jul 23, 2022

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 with search.

One simple solution could be include the page in the data object, like:

let data = { ...page.data, page };

So plugins can store data in the data object, like they do now or in the data.page.data object (so it’s persistent).

Read more comments on GitHub >

github_iconTop Results From Across the Web

three.js - How to use Object3d.renderOrder to control the z-index
It just controls the rendering order. It can be a useful tool if some objects are transparent. If all objects in the scene...
Read more >
Object3D#renderOrder – three.js docs
This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D...
Read more >
Render-order issue with DX11 shaders - 3ds Max
I'm working on a DirectX shader for Nitrous and I have a huge issue with render order in Shaded mode. I think this...
Read more >
Precomposing, nesting, and pre-rendering After Effects ...
Read about precomposing layers and nesting compositions in After Effects, its uses and preferences.
Read more >
QGIS 3.0 point cluster renderer, is it possible to control ...
Consider the point cluster renderer - it essentially analyzes and clusters point data at render time, creating a new pseudo layer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found