From 8d0274e00c388c3d1b959ae34cc6b8a556558888 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Fri, 31 Jan 2025 18:35:22 -0500 Subject: [PATCH] fix weird link behavior --- site.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/site.js b/site.js index 46c69c6..6f73a5f 100644 --- a/site.js +++ b/site.js @@ -24,7 +24,17 @@ async function urlCollector(url, path, file) { let links = body('a'); let urls = []; links.each(function(i, link) { - urls.push(body(link).attr('href')) + let h = body(link).attr('href'); + if (!h) return; + h = h.trim(); + if (h.startsWith('./') && h.startsWith('../')) { + h = `${url}/h`; + } else if (h.startsWith('/')) { + let u = new URL(url); + u.pathname = h; + urls.push(u.toString()) + } + urls.push(h) }) return urls;