| | |
| | | el.setAttribute(attr, rebased.pathname + rebased.hash) |
| | | } |
| | | export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) { |
| | | el.querySelectorAll('[href^="./"], [href^="../"]').forEach((item) => |
| | | el.querySelectorAll('[href=""], [href^="./"], [href^="../"]').forEach((item) => |
| | | _rebaseHtmlElement(item, "href", destination), |
| | | ) |
| | | el.querySelectorAll('[src^="./"], [src^="../"]').forEach((item) => |
| | | el.querySelectorAll('[src=""], [src^="./"], [src^="../"]').forEach((item) => |
| | | _rebaseHtmlElement(item, "src", destination), |
| | | ) |
| | | } |
| | |
| | | export function joinSegments(...args: string[]): string { |
| | | return args |
| | | .filter((segment) => segment !== "") |
| | | .map((segment, index) => |
| | | index === 0 |
| | | ? // Deduplicate but not remove leading slashes for first segment |
| | | segment.replace(/\/+$/g, "").replace(/^\/\/+/g, "/") |
| | | : segment.replace(/^\/+|\/+$/g, ""), |
| | | ) |
| | | .join("/") |
| | | .replace(/\/\/+/g, "/") |
| | | } |
| | | |
| | | export function getAllSegmentPrefixes(tags: string): string[] { |