From 4e792421c72812fd7685453710dc8970cec923c4 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 13 Jun 2024 10:32:17 +0100 Subject: [PATCH] fix(prerender): extract links from explicit html routes (#2517) --- src/prerender.ts | 2 +- test/fixture/nitro.config.ts | 2 +- test/fixture/routes/prerender-custom.html.ts | 17 +++++++++++++++++ test/fixture/routes/prerender.ts | 3 --- test/presets/azure.test.ts | 4 ++++ 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 test/fixture/routes/prerender-custom.html.ts diff --git a/src/prerender.ts b/src/prerender.ts index bd6f1f73f6..b2122e3973 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -269,7 +269,7 @@ export async function prerender(nitro: Nitro) { } // Crawl route links - if (!_route.error && isImplicitHTML) { + if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) { const extractedLinks = extractLinks( dataBuff.toString("utf8"), route, diff --git a/test/fixture/nitro.config.ts b/test/fixture/nitro.config.ts index 0de6b427c5..3b5268dcf0 100644 --- a/test/fixture/nitro.config.ts +++ b/test/fixture/nitro.config.ts @@ -90,7 +90,7 @@ export default defineNitroConfig({ ignore: [ // '/api/param/' ], - routes: ["/prerender", "/404"], + routes: ["/prerender", "/prerender-custom.html", "/404"], }, experimental: { openAPI: true, diff --git a/test/fixture/routes/prerender-custom.html.ts b/test/fixture/routes/prerender-custom.html.ts new file mode 100644 index 0000000000..cef5c14d0b --- /dev/null +++ b/test/fixture/routes/prerender-custom.html.ts @@ -0,0 +1,17 @@ +export default defineEventHandler((event) => { + const links = ["/api/hello", "/api/param/foo.json", "/api/param/foo.css"]; + + return ` + + + + Prerendered routes test + + +

Prerendered routes test #2:

+ + +`; +}); diff --git a/test/fixture/routes/prerender.ts b/test/fixture/routes/prerender.ts index f734ac587a..a09f6bf8be 100644 --- a/test/fixture/routes/prerender.ts +++ b/test/fixture/routes/prerender.ts @@ -4,14 +4,11 @@ export default defineEventHandler((event) => { const links = [ "/404", "https://about.google/products/", - "/api/hello", "/api/hello?bar=baz", "/api/hello?bar=baz&bing=bap", "/api/hello?bar=baz&foo=qux", "/prerender#foo", "../api/hey", - "/api/param/foo.json", - "/api/param/foo.css", "/json-string", event.path.includes("?") ? "/api/param/hidden" : "/prerender?withQuery", ]; diff --git a/test/presets/azure.test.ts b/test/presets/azure.test.ts index 9832fe8b61..40e3b030fd 100644 --- a/test/presets/azure.test.ts +++ b/test/presets/azure.test.ts @@ -117,6 +117,10 @@ describe( "redirect": "/.auth/logout", "route": "/logout", }, + { + "rewrite": "/prerender-custom.html", + "route": "/prerender-custom", + }, { "rewrite": "/api/hey/index.html", "route": "/api/hey",