Skip to content

Commit

Permalink
fix(prerender): support relative urls
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 4, 2022
1 parent 4b15520 commit 970286d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ export async function prerender (nitro: Nitro) {

const LINK_REGEX = /href=['"]?([^'" >]+)/g

function extractLinks (html: string, _url: string) {
function extractLinks (html: string, from: string) {
const links: string[] = []
for (const match of html.matchAll(LINK_REGEX)) {
const url = match[1]
if (!url) { continue }
const { pathname, protocol } = parseURL(url)
if (protocol) { continue }
const parsed = parseURL(url)
if (parsed.protocol) { continue }
let { pathname } = parsed
if (!pathname.startsWith('/')) {
// TODO: Handle relative urls with _url
continue
const fromURL = new URL(from, 'http://localhost')
pathname = new URL(pathname, fromURL).pathname
}
links.push(pathname)
}
Expand Down

0 comments on commit 970286d

Please sign in to comment.