From 2e9896c893602dfab6a1b564800c6354b802cece Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Wed, 20 Dec 2023 09:52:17 -0800 Subject: [PATCH] fix: deep clone before relativizing urls in transclude (closes #640) --- package-lock.json | 6 ++++++ package.json | 1 + quartz/util/path.ts | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 0bc4163..dd88ff7 100644 --- a/package-lock.json +++ b/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", diff --git a/package.json b/package.json index 252467e..70df833 100644 --- a/package.json +++ b/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", diff --git a/quartz/util/path.ts b/quartz/util/path.ts index 92cfabe..d399706 100644 --- a/quartz/util/path.ts +++ b/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 @@ const _rebaseHastElement = ( } } -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) {