Jacky Zhao
2023-12-20 2e9896c893602dfab6a1b564800c6354b802cece
fix: deep clone before relativizing urls in transclude (closes #640)
3 files modified
14 ■■■■■ changed files
package-lock.json 6 ●●●●● patch | view | raw | blame | history
package.json 1 ●●●● patch | view | raw | blame | history
quartz/util/path.ts 7 ●●●● patch | view | raw | blame | history
package-lock.json
@@ -52,6 +52,7 @@
        "remark-parse": "^11.0.0",
        "remark-rehype": "^11.0.0",
        "remark-smartypants": "^2.0.0",
        "rfdc": "^1.3.0",
        "rimraf": "^5.0.5",
        "serve-handler": "^6.1.5",
        "shikiji": "^0.9.9",
@@ -5161,6 +5162,11 @@
        "node": ">=0.10.0"
      }
    },
    "node_modules/rfdc": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
      "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
    },
    "node_modules/rimraf": {
      "version": "5.0.5",
      "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.5.tgz",
package.json
@@ -77,6 +77,7 @@
    "remark-parse": "^11.0.0",
    "remark-rehype": "^11.0.0",
    "remark-smartypants": "^2.0.0",
    "rfdc": "^1.3.0",
    "rimraf": "^5.0.5",
    "serve-handler": "^6.1.5",
    "shikiji": "^0.9.9",
quartz/util/path.ts
@@ -1,5 +1,9 @@
import { slug as slugAnchor } from "github-slugger"
import type { Element as HastElement } from "hast"
import rfdc from "rfdc"
const clone = rfdc()
// this file must be isomorphic so it can't use node libs (e.g. path)
export const QUARTZ = "quartz"
@@ -121,7 +125,8 @@
  }
}
export function normalizeHastElement(el: HastElement, curBase: FullSlug, newBase: FullSlug) {
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) {