Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions routes/proxy-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,32 @@ function parseSitemapUrls(
let path = options.root
? url.pathname.replace(`/${options.root}`, "/")
: url.pathname;
let pathname = posixNormalize(`/${options.prefix}${path}`);
paths.push({ pathname });
paths.push({ pathname: prefixed(path, options.prefix) });
} catch {
// skip malformed URLs
}
}
return paths;
}

/**
* Mount a path from a proxied site's sitemap under its prefix here.
*
* A site staticalized with `--base` naming the url it lives at *on this site*
* already carries the prefix in every `<loc>` β€” Effection publishes
* `https://frontside.com/effection/docs`, not `/docs`. Adding the prefix to
* that would ask for `/effection/effection/docs`, which is nowhere.
*
* A site that still advertises its own origin, as Interactors and Graphgen do,
* needs the prefix. So does an Effection preview, whose base is its own alias
* url. Deciding on the path rather than the origin covers all three.
*/
export function prefixed(path: string, prefix: string): string {
let mount = `/${prefix}`;

if (path === mount || path.startsWith(`${mount}/`)) {
return posixNormalize(path);
}

return posixNormalize(`${mount}${path}`);
}
Loading