From 3297765f8830ced5b904bc98ddee72049014fffc Mon Sep 17 00:00:00 2001 From: thezzisu Date: Tue, 7 Mar 2023 21:45:39 +0800 Subject: [PATCH 1/2] feat: enhance prerender.ignore --- src/prerender.ts | 6 +++++- src/types/nitro.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index 80eeba6afb..ec65544903 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -112,7 +112,11 @@ export async function prerender(nitro: Nitro) { // Check for explicitly ignored routes for (const ignore of nitro.options.prerender.ignore) { - if (route.startsWith(ignore)) { + if (typeof ignore === "string") { + if (route.startsWith(ignore)) { + return false; + } + } else if (ignore.test(route)) { return false; } } diff --git a/src/types/nitro.ts b/src/types/nitro.ts index 1ba939aa55..29f6c5cbcd 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -208,7 +208,7 @@ export interface NitroOptions extends PresetOptions { devErrorHandler: NitroErrorHandler; prerender: { crawlLinks: boolean; - ignore: string[]; + ignore: (string | RegExp)[]; routes: string[]; }; From 7561d6cf1b4ae8c55f4c3694e7dbd7841620beae Mon Sep 17 00:00:00 2001 From: thezzisu Date: Tue, 7 Mar 2023 21:54:10 +0800 Subject: [PATCH 2/2] chore: update docs --- docs/content/3.config/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/content/3.config/index.md b/docs/content/3.config/index.md index 443ba241cc..8e88c657dd 100644 --- a/docs/content/3.config/index.md +++ b/docs/content/3.config/index.md @@ -261,10 +261,12 @@ When `cache` option is set, handlers matching pattern will be automatically wrap ### `prerender` -Default: `{ crawlLinks: false, routes: [] }` +Default: `{ crawlLinks: false, ignore: [], routes: [] }` Prerendered options. Any route specified will be fetched during the build and copied to the `.output/public` directory as a static asset. +The `ignore` option accepts an array of string or regex to specify routes to ignore. Routes that starts with the string or matches the regex will be ignored. + If `crawlLinks` option is set to `true`, nitro starts with `/` by default (or all routes in `routes` array) and for HTML pages extracts `` tags and prerender them as well.