lumeland/lume

buildOrder: make page render after all plugins are run

iacore opened this issue · 6 comments

Enter your suggestions in details:

so the use case is like this

I want this:

  1. normal HTML pages are rendered
  2. resolve_urls rewrites the link
  3. Atom feed file is generated by reading the HTML files

instead, I get this

  1. normal HTML pages are rendered
  2. Atom feed file is generated by reading the HTML files
  3. resolve_urls rewrites the link

Do I need to write a plugin to deal with this use case?

The feed plugin fixes this problem, because you can add the feed plugin after other plugins.

The feed plugin fixes this problem, because you can add the feed plugin after other plugins.

Thanks. This should tell me how to write my own plugin.

@iacore Why do you want to write a Feed plugin?
If you're missing something from the existing one, maybe we can add it.

I have my own .tsx template.

Other than missing a feed plugin, I think I need a plugin that renders a page after all plugins are run.

something like

site.use(render_page_late, { page: "example.tsx" })

it doesn't have to be 'beforeSave'
it just have to be after the plugins placed before it in _config.ts are run.

Other than missing a feed plugin, I think I need a plugin that renders a page after all plugins are run.

@oscarotero how do I write a plugin like this? alternatively, should buildOrder affect plugins as well?

If I understand correctly, you want to create a page dynamically. One way to do that is with a processor:

import { Page } from "lume/core/file.ts";

site.process("*", (_, pages) => {
  const newPage = Page.create({
    url: "/new-page-url/",
    content: "Content of the page",
  });

  pages.push(newPage);
});

If you want to render the page like the rest of the pages (with the layouts, preprocessors, processors, etc), it's a bit tricky, because Lume is not prepared for that. Maybe you can use the renderPageOnDemand function from the renderer class. I didn't test it but perhaps this works:

import { Page } from "lume/core/file.ts";

site.process("*", async (_, pages) => {
  const newPage = Page.create({
    url: "/new-page-url/",
    layout: "main-layout.vto",
    title: "Page title",
    content: "Content of the page {{ title }}",
    templateEngine: [".vto"],
  });

  await site.renderer.renderPageOnDemand(newPage);

  pages.push(newPage);
});