Skip to content

Commit

Permalink
fix(prerender): only use pathnames
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 19, 2022
1 parent 7e3a959 commit 7cc02c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/prerender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve, join } from 'pathe'
import { hasProtocol } from 'ufo'
import { parseURL } from 'ufo'
import chalk from 'chalk'
import { createNitro } from './nitro'
import { build } from './build'
Expand Down Expand Up @@ -80,14 +80,14 @@ function extractLinks (html: string, _url: string) {
const links: string[] = []
for (const match of html.matchAll(LINK_REGEX)) {
const url = match[1]
if (!url || hasProtocol(url) || getExtension(url)) {
continue
}
if (!url.startsWith('/')) {
if (!url) { continue }
const { pathname, protocol } = parseURL(url)
if (protocol || getExtension(pathname)) { continue }
if (!pathname.startsWith('/')) {
// TODO: Handle relative urls with _url
continue
}
links.push(url)
links.push(pathname)
}
return links
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/routes/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export default defineEventHandler(() => {
const links = [
'https://about.google/products/',
'/api/hello',
'/api/hello',
'/prerender',
'/api/hello?bar=baz',
'/prerender#foo',
'../api/hey'
]
return `
Expand Down

0 comments on commit 7cc02c9

Please sign in to comment.