| | |
| | | |
| | | let slug = withoutFileExt |
| | | .split("/") |
| | | .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent")) // slugify all segments |
| | | .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent").replace(/\?/g, "-q")) // slugify all segments |
| | | .join("/") // always use / as sep |
| | | .replace(/\/$/, "") // remove trailing slash |
| | | |
| | |
| | | return res |
| | | } |
| | | |
| | | // from micromorph/src/utils.ts |
| | | // https://github.com/natemoo-re/micromorph/blob/main/src/utils.ts#L5 |
| | | export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) { |
| | | const rebase = (el: Element, attr: string, newBase: string | URL) => { |
| | | const rebased = new URL(el.getAttribute(attr)!, newBase) |
| | | el.setAttribute(attr, rebased.pathname + rebased.hash) |
| | | } |
| | | |
| | | el.querySelectorAll('[href^="./"], [href^="../"]').forEach((item) => |
| | | rebase(item, "href", destination), |
| | | ) |
| | | el.querySelectorAll('[src^="./"], [src^="../"]').forEach((item) => |
| | | rebase(item, "src", destination), |
| | | ) |
| | | } |
| | | |
| | | // resolve /a/b/c to ../.. |
| | | export function pathToRoot(slug: FullSlug): RelativeURL { |
| | | let rootPath = slug |
| | |
| | | } |
| | | |
| | | export function joinSegments(...args: string[]): string { |
| | | return args.filter((segment) => segment !== "").join("/") |
| | | return args |
| | | .filter((segment) => segment !== "") |
| | | .join("/") |
| | | .replace(/\/\/+/g, "/") |
| | | } |
| | | |
| | | export function getAllSegmentPrefixes(tags: string): string[] { |