fix(slugs): pass slugs.stripDiacritics to browser scripts; plugins bundling utils 1.3 (bases-page, breadcrumbs, canvas-page, explorer, folder-page, note-properties, OFM)

This commit is contained in:
saberzero1 committed 2026-11-26 21:22:39 +01:00
1 parent 673a596cf8
commit dd667ee315
6 files changed
+105 -46

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
`slugs.stripDiacritics` reaches plugins and the browser: bases-page 1.5.3, breadcrumbs 1.0.4, canvas-page 1.1.1, explorer 1.2.1, folder-page 1.1.2, note-properties 1.2.1 and obsidian-flavored-markdown 2.5.1 bundle `@quartz-community/utils` 1.3, so their links, tag pages from inline tags, canvas file nodes and base views use the stripped addresses. Quartz also passes the option to scripts in the browser, so the explorer places folders and pages with accents where the build put them.
+1 -1
View File
@@ -2,4 +2,4 @@
"@jackyzha0/quartz": minor
---
New opt-in `configuration.slugs.stripDiacritics`: strips accents and other diacritics from generated slugs (`české/čeština.md` → `/ceske/cestina`). Links, embeds, aliases, permalinks and folder pages resolve to the stripped addresses; heading anchors and non-Latin scripts are unchanged. With `@quartz-community/utils` 1.3+ the option also reaches plugins that slug through utils (tag pages, canvas, bases, alias-redirects).
New opt-in `configuration.slugs.stripDiacritics`: strips accents and other diacritics from generated slugs (`české/čeština.md` → `/ceske/cestina`). Links, embeds, aliases, permalinks, tags and folder pages resolve to the stripped addresses, and the old addresses redirect to them; heading anchors keep their diacritics. Letters without a separate accent (`ł`, `ø`, `ß`) are kept, as are Korean, Japanese, Chinese, Indic, Hebrew and Arabic text. Plugins that make slugs follow the option when they bundle `@quartz-community/utils` 1.3 or later, as the plugins updated in this release do.
+35 -35
View File
@@ -16,9 +16,9 @@
"@quartz-community/alias-redirects": "^1.0.3",
"@quartz-community/article-title": "^1.0.2",
"@quartz-community/backlinks": "^1.0.4",
"@quartz-community/bases-page": "^1.5.2",
"@quartz-community/breadcrumbs": "^1.0.3",
"@quartz-community/canvas-page": "^1.1.0",
"@quartz-community/bases-page": "^1.5.3",
"@quartz-community/breadcrumbs": "^1.0.4",
"@quartz-community/canvas-page": "^1.1.1",
"@quartz-community/citations": "^1.0.1",
"@quartz-community/cname": "^1.0.1",
"@quartz-community/comments": "^1.0.2",
@@ -29,16 +29,16 @@
"@quartz-community/description": "^1.0.2",
"@quartz-community/encrypted-pages": "^1.2.0",
"@quartz-community/explicit-publish": "^1.2.0",
"@quartz-community/explorer": "^1.2.0",
"@quartz-community/explorer": "^1.2.1",
"@quartz-community/favicon": "^1.0.1",
"@quartz-community/folder-page": "^1.1.1",
"@quartz-community/folder-page": "^1.1.2",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.2.0",
"@quartz-community/graph": "^1.0.7",
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.1.1",
"@quartz-community/note-properties": "^1.2.0",
"@quartz-community/obsidian-flavored-markdown": "^2.5.0",
"@quartz-community/note-properties": "^1.2.1",
"@quartz-community/obsidian-flavored-markdown": "^2.5.1",
"@quartz-community/og-image": "^1.1.2",
"@quartz-community/ox-hugo": "^1.0.2",
"@quartz-community/page-title": "^1.0.2",
@@ -2330,14 +2330,14 @@
}
},
"node_modules/@quartz-community/bases-page": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.5.2.tgz",
"integrity": "sha512-wOPNaLAmDHSuVd8Jm424I8hMR7F1zHAvpy6VfKDOJOyfwzSLJF2BCvChUWlSl7E7IUZoAwPeIPKe7Ky9O2LnDw==",
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.5.3.tgz",
"integrity": "sha512-MfaehkZ4iBnan43HPTVHUARbUsnJqr3H/bxeJYRqSv+rOE+QBI48XGz+AkaXodaVYihlE9dTSo6TS9lGK0opEA==",
"license": "MIT",
"dependencies": {
"@lucide/icons": "^1.70.0",
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2361,13 +2361,13 @@
}
},
"node_modules/@quartz-community/breadcrumbs": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@quartz-community/breadcrumbs/-/breadcrumbs-1.0.3.tgz",
"integrity": "sha512-ciGV+xk98Nl5WqxTSyfyzDC+dWcSVjQcN2qN1GjnSKSeuPgX1/LQhpr1VHiDAVd3XpLMr/c7Gg19UkdMvBPgKQ==",
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@quartz-community/breadcrumbs/-/breadcrumbs-1.0.4.tgz",
"integrity": "sha512-nVmGBLRQ8jibp8ednTmzh+TwSLVYNYi/Fwn42AH7HVx5Df78piqRl0eiSkSPyIECR6NSXGnh4Yd7spR15DU1TA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2383,13 +2383,13 @@
}
},
"node_modules/@quartz-community/canvas-page": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@quartz-community/canvas-page/-/canvas-page-1.1.0.tgz",
"integrity": "sha512-IkjtkjTgV/Et6BSO40Mrdae8ujk+PG07mg/I4mX8n2ta5erGucMK/SH9ZHOSzFUL4d/mDHeaPZlnlvVV8MT45w==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@quartz-community/canvas-page/-/canvas-page-1.1.1.tgz",
"integrity": "sha512-iBeqAmcWGGe1dV87YJWNxvi8LYmEDeLMxT146JiW+n6e+kx3IuSLKKn0uL58fE7SGXUEQN0IwS59RAjWw2ttmA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2621,13 +2621,13 @@
}
},
"node_modules/@quartz-community/explorer": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@quartz-community/explorer/-/explorer-1.2.0.tgz",
"integrity": "sha512-w8CNRVLjaEn5DH1iTs/dDWqIhi0frii5KVaVkZnKlYQW89bdt1tUvyHrKxVd+wqzAz9CikpNEpmPEMKqwR8epA==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/explorer/-/explorer-1.2.1.tgz",
"integrity": "sha512-xw9gN+YB4J+GnUBIxNrwR/DulSgg4uN7Ya9dWS6SD6lLCHzegaZn0wbmrkDIJa0kjSzxWgcSVPkUSELB50T3RA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2664,13 +2664,13 @@
}
},
"node_modules/@quartz-community/folder-page": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@quartz-community/folder-page/-/folder-page-1.1.1.tgz",
"integrity": "sha512-3JxOPfe7q6m/Vyx+ZLVpiON4/qOlqBte9SOj1MRAKJK59kM9p0k/vu+rSv5k87U5wBIirA2mDzZenQfug8dUeQ==",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@quartz-community/folder-page/-/folder-page-1.1.2.tgz",
"integrity": "sha512-n/1ICi+8rDv9DPxNqSO/ncCWSrbH/kWV9pxaaXw7V4Z8MAGvmQWDaOCBfMsZacX1nw8tb0JY33KibWej+U66hA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2802,13 +2802,13 @@
}
},
"node_modules/@quartz-community/note-properties": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.2.0.tgz",
"integrity": "sha512-ToM07F/+4so+gmSW9SEzrIE+HKBV9/B8IaVQDlxtwx8x2aKqx3EdxeqK55f6ARDWPmXbha67vFPSXA85Xpneng==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.2.1.tgz",
"integrity": "sha512-xwJoztzc6G1pUHXBfNwBIu548bi5XjbKYOM+zqn1DkonFNY9SiuS+Tz5BI+G75ndBtcmZ7aXuuiaTob5RNQUpw==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.0"
"@quartz-community/utils": "^1.3.0"
},
"engines": {
"node": ">=22",
@@ -2828,15 +2828,15 @@
}
},
"node_modules/@quartz-community/obsidian-flavored-markdown": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.5.0.tgz",
"integrity": "sha512-ovNJBhdLwbwfiLbtZ4QeTfFQ/7nlCoGsFSlGfLvKGIJC+/oLjCnQIMTARpCvrB02LdgO2jFrGUaTZ20UuAH/KQ==",
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.5.1.tgz",
"integrity": "sha512-VYsj6876bhH3ufqXQ+/4hlgUkFaV76IjVRH9SJHyOqDE4iq4TELHL7TrYpzg9m1lVyq8GQE1hyIG5q0GshDjPg==",
"license": "MIT",
"dependencies": {
"@quartz-community/rehype-obsidian": "^1.5.0",
"@quartz-community/remark-obsidian": "^2.2.1",
"@quartz-community/types": "^1.1.0",
"@quartz-community/utils": "^1.2.0",
"@quartz-community/utils": "^1.3.0",
"pele": "^1.13.0"
},
"engines": {
+7 -7
View File
@@ -46,9 +46,9 @@
"@quartz-community/alias-redirects": "^1.0.3",
"@quartz-community/article-title": "^1.0.2",
"@quartz-community/backlinks": "^1.0.4",
"@quartz-community/bases-page": "^1.5.2",
"@quartz-community/breadcrumbs": "^1.0.3",
"@quartz-community/canvas-page": "^1.1.0",
"@quartz-community/bases-page": "^1.5.3",
"@quartz-community/breadcrumbs": "^1.0.4",
"@quartz-community/canvas-page": "^1.1.1",
"@quartz-community/citations": "^1.0.1",
"@quartz-community/cname": "^1.0.1",
"@quartz-community/comments": "^1.0.2",
@@ -59,16 +59,16 @@
"@quartz-community/description": "^1.0.2",
"@quartz-community/encrypted-pages": "^1.2.0",
"@quartz-community/explicit-publish": "^1.2.0",
"@quartz-community/explorer": "^1.2.0",
"@quartz-community/explorer": "^1.2.1",
"@quartz-community/favicon": "^1.0.1",
"@quartz-community/folder-page": "^1.1.1",
"@quartz-community/folder-page": "^1.1.2",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.2.0",
"@quartz-community/graph": "^1.0.7",
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.1.1",
"@quartz-community/note-properties": "^1.2.0",
"@quartz-community/obsidian-flavored-markdown": "^2.5.0",
"@quartz-community/note-properties": "^1.2.1",
"@quartz-community/obsidian-flavored-markdown": "^2.5.1",
"@quartz-community/og-image": "^1.1.2",
"@quartz-community/ox-hugo": "^1.0.2",
"@quartz-community/page-title": "^1.0.2",
+37 -1
View File
@@ -3,7 +3,9 @@ import { toHtml } from "hast-util-to-html"
import assert from "node:assert"
import { renderTranscludes, pageResources, transformPageContent } from "./renderPage"
import { Root, Element } from "hast"
import { FullSlug } from "../util/path"
import { FullSlug, setSlugOptions } from "../util/path"
import { slugifyFilePath } from "@quartz-community/utils"
import vm from "node:vm"
import { GlobalConfiguration } from "../cfg"
import { QuartzComponentProps } from "./types"
import { StaticResources } from "../util/resources"
@@ -459,6 +461,40 @@ describe("pageResources", () => {
)
})
const inlineScript = (result: ReturnType<typeof pageResources>) =>
result.js
.filter((j) => j.contentType === "inline")
.map((j) => ("script" in j ? j.script : ""))
.join("\n")
test("slugs.stripDiacritics reaches scripts in the browser (#2410)", () => {
setSlugOptions({ stripDiacritics: true })
try {
const script = inlineScript(pageResources("." as FullSlug, emptyResources))
// run it as the page does; the global it sets is the one utils reads
const page = vm.createContext({
fetch: () => new Promise(() => {}),
location: { href: "https://x/" },
URL,
})
vm.runInContext(script.replace("window.", "globalThis."), page)
const set = vm.runInContext(
`JSON.stringify(globalThis[Symbol.for("@quartz-community/utils/slugOptions")])`,
page,
)
assert.strictEqual(set, JSON.stringify({ stripDiacritics: true }))
// same global as utils in this thread: a script with utils 1.3 slugs as the build does
assert.strictEqual(slugifyFilePath("české/čeština.md" as never), "ceske/cestina")
} finally {
setSlugOptions(undefined)
}
})
test("the default slug options write nothing to the page", () => {
const script = inlineScript(pageResources("." as FullSlug, emptyResources))
assert.ok(!script.includes("slugOptions"), script)
})
test("omits subpath prefix when baseDir is empty (serve mode)", () => {
const result = pageResources("." as FullSlug, emptyResources)
for (const css of result.css) {
+20 -2
View File
@@ -7,7 +7,13 @@ import {
JSResourceToScriptElement,
StaticResources,
} from "../util/resources"
import { FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
import {
FullSlug,
RelativeURL,
getSlugOptions,
joinSegments,
normalizeHastElement,
} from "../util/path"
import { clone } from "../util/clone"
import { Root, Element, ElementContent } from "hast"
import { GlobalConfiguration, SidebarModes } from "../cfg"
@@ -51,6 +57,17 @@ function headingHasId(heading: Element, id: string): boolean {
)
return hasAlias(heading)
}
/**
* `configuration.slugs` for scripts in the browser. @quartz-community/utils (1.3+) keeps its slug
* options on this global, so every plugin script that slugs (the explorer places pages by their
* file path) slugs as the build did. Nothing is written with the default options.
*/
export function slugOptionsScript(): string {
const options = getSlugOptions()
if (!options.stripDiacritics) return ""
return `;globalThis[Symbol.for("@quartz-community/utils/slugOptions")] = ${JSON.stringify(options)}`
}
export function pageResources(
baseDir: FullSlug | RelativeURL,
staticResources: StaticResources,
@@ -102,7 +119,8 @@ export function pageResources(
`.catch(e => { console.warn("[Quartz] Could not load ${contentIndexPath} (" + e.message + "); is configuration.contentIndex disabled?"); return {} });` +
// Absolute URL of static/ (plugin assets live in static/plugins/<to>). Resolved once on the
// first page, so it stays valid across SPA navigations.
`window.quartzStaticUrl = new URL(${JSON.stringify(joinSegments(baseDir, "static") + "/")}, location.href).href`
`window.quartzStaticUrl = new URL(${JSON.stringify(joinSegments(baseDir, "static") + "/")}, location.href).href` +
slugOptionsScript()
const resources: StaticResources = {
css: [