Is your feature request related to a problem? Please describe.
I created a node module to generate paginated category pages for a site (https://www.npmjs.com/package/eleventy-generate-category-pages). When I run an Eleventy build using --watch or --serve, it creates an infinite loop during the build process where regenerating the category pages causes a site rebuild.
What I need for this is a beforeOnce event so the category page generation only happens once, at the beginning of the --serve process.
Describe the solution you'd like
Something like this:
var beforeFirstRun = true;
if (beforeFirstRun) {
beforeFirstRun = false;
await this.config.events.emit("eleventy.beforeOnce", eventsArg);
}
await this.config.events.emit("beforeBuild", eventsArg);
await this.config.events.emit("eleventy.before", eventsArg);
we can do the same for after, an afterOnce event:
var afterFirstRun = true;
if (afterFirstRun) {
afterFirstRun = false;
await this.config.events.emit("eleventy.afterOnce", eventsArg);
}
await this.config.events.emit("afterBuild", eventsArg);
await this.config.events.emit("eleventy.after", eventsArg);
Describe alternatives you've considered
To solve this, I added a similar check in my eleventy.before listener:
var firstRun = true;
eleventyConfig.on('eleventy.before', async ({ dir, runMode, outputMode }) => {
if (firstRun) {
firstRun = false;
generateCategoryPages({}, true, false);
}
});
Additional context
I can add this as a PR, buut wanted to see what the community thinks of it first. and, I'd have to figure out how to write a test for this.
Is your feature request related to a problem? Please describe.
I created a node module to generate paginated category pages for a site (https://www.npmjs.com/package/eleventy-generate-category-pages). When I run an Eleventy build using
--watchor--serve, it creates an infinite loop during the build process where regenerating the category pages causes a site rebuild.What I need for this is a
beforeOnceevent so the category page generation only happens once, at the beginning of the--serveprocess.Describe the solution you'd like
Something like this:
we can do the same for after, an
afterOnceevent:Describe alternatives you've considered
To solve this, I added a similar check in my
eleventy.beforelistener:Additional context
I can add this as a PR, buut wanted to see what the community thinks of it first. and, I'd have to figure out how to write a test for this.