fix weird link behavior

This commit is contained in:
dervperson 2025-01-31 18:35:22 -05:00
parent 5c0113e972
commit 8d0274e00c

12
site.js
View file

@ -24,7 +24,17 @@ async function urlCollector(url, path, file) {
let links = body('a'); let links = body('a');
let urls = []; let urls = [];
links.each(function(i, link) { 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; return urls;