diff --git a/package-lock.json b/package-lock.json index c07858f..5ef898e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1857,7 +1857,7 @@ }, "node_modules/@quartz-community/utils": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/quartz-community/utils.git#4dda81bc82b90f5bceaa3582e81547ce41cc581b", + "resolved": "git+ssh://git@github.com/quartz-community/utils.git#83f824b0ad495ae24b7f3524dd2049da76d24c2c", "dev": true, "license": "MIT", "dependencies": { diff --git a/quartz/util/path.ts b/quartz/util/path.ts index b17d04f..5332b60 100644 --- a/quartz/util/path.ts +++ b/quartz/util/path.ts @@ -21,6 +21,7 @@ export { slugTag, transformInternalLink, transformLink, + normalizeHastElement, } from "@quartz-community/utils" export type { @@ -33,11 +34,6 @@ export type { // --- v5-specific exports below --- -import type { Element as HastElement } from "hast" -import type { FullSlug } from "@quartz-community/utils" -import { isRelativeURL, joinSegments, resolveRelative } from "@quartz-community/utils" -import { clone } from "./clone" - export const QUARTZ = "quartz" // from micromorph/src/utils.ts @@ -54,32 +50,3 @@ export function normalizeRelativeURLs(el: Element | Document, destination: strin _rebaseHtmlElement(item, "src", destination) }) } - -const _rebaseHastElement = ( - el: HastElement, - attr: string, - curBase: FullSlug, - newBase: FullSlug, -) => { - if (el.properties?.[attr]) { - if (!isRelativeURL(String(el.properties[attr]))) { - return - } - - const rel = joinSegments(resolveRelative(curBase, newBase), "..", el.properties[attr] as string) - el.properties[attr] = rel - } -} - -export function normalizeHastElement(rawEl: HastElement, curBase: FullSlug, newBase: FullSlug) { - const el = clone(rawEl) // clone so we dont modify the original page - _rebaseHastElement(el, "src", curBase, newBase) - _rebaseHastElement(el, "href", curBase, newBase) - if (el.children) { - el.children = el.children.map((child) => - normalizeHastElement(child as HastElement, curBase, newBase), - ) - } - - return el -}