Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support regex for prerender.ignore #1033

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/content/3.config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,23 @@ routeRules: {

### `prerender`

Default: `{ crawlLinks: false, ignore: [], routes: [] }`
Pre-rendering options used when building your application with Nitro.

Prerendered options. Any route specified will be fetched during the build and copied to the `.output/public` directory as a static asset.
Default:

Any route that starts with a prefix listed in `ignore` will be ignored.
```ts
{
crawlLinks: false,
ignore: [],
routes: []
}
```

Any route specified in `routes` will be fetched during the build and copied to the `.output/public` directory as a static asset.

If `crawlLinks` option is set to `true`, nitro starts crawling `/` by default (or all routes in `routes` array) and for HTML pages extracts `<a href="">` tags and prerender them as well. Nitro also reads from the `x-nitro-prerender` header send back to crawl extra routes.

If `crawlLinks` option is set to `true`, nitro starts with `/` by default (or all routes in `routes` array) and for HTML pages extracts `<a href="">` tags and prerender them as well.
The `ignore` option accepts an array of string or regex to specify the routes to ignore. Routes that starts with the string or matches the regex will be ignored.

## Directories

Expand Down
6 changes: 5 additions & 1 deletion src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
thezzisu marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export interface NitroOptions extends PresetOptions {
devErrorHandler: NitroErrorHandler;
prerender: {
crawlLinks: boolean;
ignore: string[];
ignore: (string | RegExp)[];
routes: string[];
};

Expand Down