Merge remote-tracking branch 'origin/v5' into dev-mode/config-extends

# Conflicts:
#	quartz/plugins/loader/config-loader.ts
This commit is contained in:
saberzero1 committed 2026-11-26 19:01:44 +01:00
commit 51c13bcca4
26 files changed
+374 -38

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"@jackyzha0/quartz": patch
---
- `@quartz-community/graph` 1.0.7: the local graph on folder index pages shows the folder's connections instead of a single node.
- `@quartz-community/utils` 1.2.1: `unescapeHTML` decodes each entity once, so a page description that mentions `&lt;br&gt;` keeps it in the page's meta tags instead of turning it into `<br>`.
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": minor
---
Layout conditions: add `is-index` (only on the home page) and `is-folder-index` (only on folder index pages), and let `not-<condition>` negate any condition, built-in or registered (`not-has-tags`, `not-has-backlinks`, …).
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Release tags are verified on GitHub: the release workflow creates each `vX.Y.Z` tag as a lightweight tag on the merged release commit (which GitHub signs) instead of letting the release create an unsigned annotated tag. It also starts the Docker build for the tag, so versioned images (`5.3.0`, `5.3`) are published for each release (none were built for 5.1.0–5.2.2).
+5
View File
@@ -0,0 +1,5 @@
---
"@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).
+11 -5
View File
@@ -21,6 +21,7 @@ jobs:
permissions:
contents: write
pull-requests: write
actions: write # start the Docker build for the new tag
steps:
- uses: actions/checkout@v7
with:
@@ -59,8 +60,13 @@ jobs:
echo "CHANGELOG.md has no section for $VERSION — not tagging."
exit 0
fi
# GitHub creates the tag, on the commit this push brought (the merged release PR). A tag
# made here with `git tag -a` is an unsigned tag object, which GitHub marks "Unverified"
# (jackyzha0/quartz#2455). This one points straight at the commit, which shows as verified
# because GitHub signs the commits it merges. `git describe --tags` sees it all the same.
gh release create "$TAG" --target "$GITHUB_SHA" --title "Quartz $VERSION" --notes-file release-notes.md
# The tag is a lightweight ref straight to the merged release commit, created here
# before the release. GitHub signs the commits it merges, so the tag shows as verified.
# Letting `gh release create` make the tag instead gives an unsigned annotated tag
# object (tagger: whoever merged the release PR), which GitHub marks "Unverified"
# (jackyzha0/quartz#2455). `git describe --tags` reads lightweight tags as well.
gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$TAG" -f sha="$GITHUB_SHA" >/dev/null
gh release create "$TAG" --verify-tag --title "Quartz $VERSION" --notes-file release-notes.md
# A tag created with GITHUB_TOKEN doesn't trigger `on: push: tags`, so the Docker workflow
# never built the versioned images; start it for the tag explicitly.
gh workflow run docker-build-push.yaml --ref "$TAG"
+3 -2
View File
@@ -556,10 +556,10 @@ export const MyFrame: PageFrame = {
`,
render({ componentData, pageBody: Content, footer: Footers }: PageFrameProps): unknown {
return (
<div class="center">
<main class="center">
{Content(componentData) as ComponentChildren}
{Footers.map((Footer) => Footer(componentData) as ComponentChildren)}
</div>
</main>
)
},
}
@@ -569,6 +569,7 @@ Key requirements:
- `name`: A unique string identifier. This is what page types and YAML config reference.
- `render()`: Receives all layout slots (header, sidebars, content, footer) and returns JSX for the inner page structure. Note that `footer` is a `QuartzComponent[]` (an array) — frames should iterate over it with `.map()` to render all footer components.
- Put the page's content in a `<main>` element (and sidebars in `<aside>`), as the built-in frames do, so screen readers can jump to it.
- `css` (optional): Frame-specific CSS. Scope it with `.page[data-frame="my-frame"]` selectors to avoid conflicts.
**2. Re-export the frame:**
+5
View File
@@ -83,6 +83,11 @@ This part of the configuration concerns anything that can affect the whole site.
- `"all"` (default): every file that isn't ignored.
- `"referenced"`: only files a published page links to or embeds. Use this with [[ExplicitPublish]] or [[private pages|drafts]], so that files only unpublished notes use stay private.
- Files that Quartz renders as pages themselves (e.g. `.base` and `.canvas` files) are never copied as raw assets.
- `slugs`: how file paths become URLs.
- `stripDiacritics`: `true` strips accents and other diacritics from page, folder and file URLs, e.g. `české/čeština.md` is published at `/ceske/cestina` instead of `/české/čeština` (which browsers show as `%C4%8Desk%C3%A9/...` when copied). Off by default.
- Links keep working as written in your notes: `[[čeština]]`, `[[české/čeština#Nadpis]]` and embeds like `![[obrázek.png]]` resolve to the stripped addresses. Aliases and `permalink`s are stripped the same way. Heading anchors (`#Nadpis`) keep their diacritics. Tag pages and the pages plugins generate from files (canvas, bases, …) are stripped too with `@quartz-community/utils` 1.3 or newer; with older versions they keep their diacritics.
- Only combining accents (`á č é ů …`) are removed. Letters without a decomposition (`ø`, `ł`, `ß`, `æ`) and non-Latin scripts (Chinese, Japanese, Korean, Arabic, Devanagari, …) are kept as they are.
- Turning it on changes the URLs of existing pages; links shared elsewhere to the old addresses will 404 unless you add the old addresses as `aliases`.
- `ignorePatterns`: a list of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that Quartz should ignore and not search through when looking for files inside the `content` folder. See [[private pages]] for more details.
- `theme`: configure how the site looks.
- `fontOrigin`: where to load fonts from.
+2
View File
@@ -15,4 +15,6 @@ Under the hood, this is done by hijacking page navigations and instead fetching
Pages are fetched ahead of a click by [[prefetching]], which the router uses to show them at once; the fetched pages are also reused by [[popover previews]].
Back and Forward return to where you were on each page: the router keeps each history entry's scroll position and restores it after the page is swapped in, and a reload keeps it too. Links to a heading on the same page add a history entry and only scroll, so Back returns to where you clicked.
Redirects are followed: when a link is redirected (for example `folder` → `folder/` on static hosts, or an alias page to its canonical page), the address bar shows the final URL and relative links on the new page resolve against it.
+11 -6
View File
@@ -170,12 +170,17 @@ plugins:
Available built-in conditions:
| Condition | Description |
| --------------- | ----------------------------------------------------- |
| `not-index` | Only render when the page is not the root `index.md` |
| `has-tags` | Only render when the page has tags in its frontmatter |
| `has-backlinks` | Only render when the page has backlinks |
| `has-toc` | Only render when the page has a table of contents |
| Condition | Description |
| ----------------- | --------------------------------------------------------------------------- |
| `is-index` | Only render on the root `index.md` (the home page) |
| `not-index` | Only render when the page is not the root `index.md` |
| `is-folder-index` | Only render on a folder's index page (`folder/index.md` or a generated one) |
| `has-tags` | Only render when the page has tags in its frontmatter |
| `has-backlinks` | Only render when the page has backlinks |
| `has-toc` | Only render when the page has a table of contents |
| `not-<condition>` | Negates any other condition, e.g. `not-has-tags`, `not-has-backlinks` |
The `not-` prefix also works for conditions registered by plugins or in `quartz.ts`. To change the layout of a whole page type (folder pages, tag pages, …) rather than single pages, use `layout.byPageType` (see [[layout#Per-page-type overrides]]).
### TS Override
+9 -6
View File
@@ -132,12 +132,15 @@ plugins:
Available conditions:
| Condition | Effect |
| --------------- | ------------------------------------------------------------------------ |
| `not-index` | Hidden on the root index page, shown everywhere else |
| `has-tags` | Only shown on pages that have tags in frontmatter |
| `has-backlinks` | Only shown on pages that another (listed) page links to |
| `has-toc` | Only shown on pages with a table of contents (needs `table-of-contents`) |
| Condition | Effect |
| ----------------- | ---------------------------------------------------------------------------- |
| `is-index` | Only shown on the root index page (the home page) |
| `not-index` | Hidden on the root index page, shown everywhere else |
| `is-folder-index` | Only shown on folder index pages (`folder/index.md` or a generated one) |
| `has-tags` | Only shown on pages that have tags in frontmatter |
| `has-backlinks` | Only shown on pages that another (listed) page links to |
| `has-toc` | Only shown on pages with a table of contents (needs `table-of-contents`) |
| `not-<condition>` | Negates any condition, built-in or registered: `not-has-tags`, `not-has-toc` |
Plugins can register additional conditions. An unknown condition name prints a warning at build time and the component is always shown.
+1
View File
@@ -63,6 +63,7 @@ With Quartz 5.1, `.base` pages follow the site's publish filters (e.g. [[Explici
This plugin accepts the following configuration options:
- `propertyLabels`: How column and property labels are shown. `"name"` (default) shows a property's name as Obsidian does (`priority`, `file name`); `"title"` title-cases it (`Priority`, `Name`). A property's `displayName` is always used.
- `defaultViewType`: Open a base on its first view of this type. Unset by default: a base opens on its first view, as in Obsidian.
- `linkResolution`: How to resolve internal links in view renderers. Should match `configuration.links.markdownLinkResolution` (built-in [[CrawlLinks|link processing]]). Can be `"absolute"`, `"relative"`, or `"shortest"`. Defaults to `"shortest"`.
- `customViews`: A map of custom view renderers. Keys are view type names. These override built-in renderers for the same type, or add new view types. Requires a TS override.
+1 -1
View File
@@ -22,7 +22,7 @@ This plugin accepts the following configuration options:
- `mathJaxOptions`: Additional options passed to the MathJax renderer. See the [MathJax docs](https://docs.mathjax.org/en/latest/options/) for available options.
- `typstOptions`: Additional options passed to the Typst renderer.
With KaTeX, the KaTeX stylesheet and its copy-tex script are loaded from jsDelivr.
With KaTeX, the KaTeX stylesheet and its copy-tex script are loaded from jsDelivr. The stylesheet blocks rendering only on pages with math; elsewhere it loads in the background, ready for pages opened with SPA navigation.
### Default options
+1
View File
@@ -34,6 +34,7 @@ This plugin accepts the following configuration options:
- `enableVideoEmbed`: If `true` (default), enables the embedding of video files.
- `enableCheckbox`: If `true`, adds support for interactive checkboxes in content, including custom task characters (e.g. `- [?]`, `- [!]`, `- [/]`). Defaults to `false`; the default `quartz.config.yaml` turns it on.
- `enableObsidianUri`: If `true` (default), marks `obsidian://` protocol links with a CSS class and data attribute for custom styling.
- `blockWrappers`: If `true` (default), wraps each top-level block in the `div` Obsidian puts it in (`div.el-p > p`), which Obsidian themes space blocks with. No visible change without a theme.
- `foldHeadings`: If `true`, headings fold as in Obsidian's reading view ("Fold heading"): an arrow before each heading, shown on hover, hides everything up to the next heading of the same or a higher level. Defaults to `false`.
- `foldLists`: If `true`, list items with a sublist fold as in Obsidian's reading view ("Fold indent"): an arrow before the item, shown on hover, hides its sublist. Defaults to `false`.
+8 -8
View File
@@ -34,7 +34,7 @@
"@quartz-community/folder-page": "^1.1.1",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.1.2",
"@quartz-community/graph": "^1.0.6",
"@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",
@@ -97,7 +97,7 @@
"devDependencies": {
"@changesets/cli": "^3.0.3",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@quartz-community/utils": "^1.2.1",
"@types/hast": "^3.0.4",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
@@ -2734,9 +2734,9 @@
}
},
"node_modules/@quartz-community/graph": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@quartz-community/graph/-/graph-1.0.6.tgz",
"integrity": "sha512-cZ7ymjZ0tyLA32ms92WVpUhcV4kGEYw5vivV4YaTwYFuu6YxuIn7YqlyUlqEAwcy6HvMgbLJZVX9O6vKpANn+A==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@quartz-community/graph/-/graph-1.0.7.tgz",
"integrity": "sha512-UEYxW5exKlAU5/P0Ixbf08iFxIoBzKRsFCJ4wCAcywGSNvW3uFnmhuSYin9ZQA1M3PUBnXxnMJR9JuP8x7F5yg==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
@@ -3230,9 +3230,9 @@
}
},
"node_modules/@quartz-community/utils": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.2.0.tgz",
"integrity": "sha512-X32uBfhfNACQw2Ciw6F0XQ9qSoTMQeh78/2ZEj8cYuOk7VTowNf0dpjtSDKAxs1co6aSpIEcDZBIG6p953UPiQ==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.2.1.tgz",
"integrity": "sha512-VVz1ZG/scBbboDYMxz4WZOnh6sPBNUCMwdO2O3eUZK0qR4kP0FPtTfWnrivNrdIacktZReihnPTiGcx78VuDvw==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0"
+2 -2
View File
@@ -64,7 +64,7 @@
"@quartz-community/folder-page": "^1.1.1",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.1.2",
"@quartz-community/graph": "^1.0.6",
"@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",
@@ -124,7 +124,7 @@
"devDependencies": {
"@changesets/cli": "^3.0.3",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@quartz-community/utils": "^1.2.1",
"@types/hast": "^3.0.4",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
+10
View File
@@ -109,6 +109,16 @@ export interface GlobalConfiguration {
* - "referenced": Only copy assets referenced by published pages
*/
publishAssets?: "all" | "referenced"
/** How file paths become URLs. */
slugs?: SlugsConfig
}
export interface SlugsConfig {
/**
* Strip accents and other diacritics from generated slugs (`české/čeština.md` →
* `ceske/cestina`), aliases and permalinks; links are resolved the same way. Off by default.
*/
stripDiacritics?: boolean
}
/** Shared by every built-in: `enabled: false` turns it off (e.g. to replace it with a plugin). */
+39 -1
View File
@@ -34,7 +34,8 @@ import {
import type { PluginJsonEntry } from "../loader/types"
import type { BuildCtx } from "../../util/ctx"
import type { ContentDetails } from "../types"
import type { FullSlug } from "../../util/path"
import type { FullSlug, SimpleSlug } from "../../util/path"
import { setSlugOptions } from "../../util/path"
import type { ProcessedContent } from "../vfile"
const entry = (source: string, extra: Partial<PluginJsonEntry> = {}): PluginJsonEntry => ({
@@ -365,6 +366,43 @@ describe("links built-in", () => {
assert.deepStrictEqual(file.data.links?.sort(), ["folder/sibling", "t"])
})
test("slugs.stripDiacritics: link targets are stripped like the slugs they point at (#2410)", () => {
setSlugOptions({ stripDiacritics: true })
try {
const img: Element = {
type: "element",
tagName: "img",
properties: { src: "obr%C3%A1zek.png" },
children: [],
}
const { els, file } = run(
[a("./%C4%8Ce%C5%A1tina#%C4%8Cesk%C3%BD-nadpis", "Čeština"), a("Příliš"), img],
"ceske/page",
{ markdownLinkResolution: "shortest" },
["ceske/page", "ceske/cestina", "jine/prilis", "ceske/obrazek.png"],
)
const [cestina, prilis] = els.filter((e) => e.tagName === "a")
assert.strictEqual(cestina.properties.href, "../ceske/cestina#český-nadpis")
assert.ok(!(cestina.properties.className as string[]).includes("broken"))
assert.strictEqual(prilis.properties.href, "../jine/prilis")
assert.strictEqual(
els.find((e) => e.tagName === "img")!.properties.src,
"../ceske/obrazek.png",
)
assert.ok(file.data.links?.includes("ceske/cestina" as SimpleSlug))
} finally {
setSlugOptions(undefined)
}
})
test("without slugs.stripDiacritics link targets keep their diacritics", () => {
const { els } = run([a("Příliš")], "page", { markdownLinkResolution: "shortest" }, [
"page",
"jine/příliš",
])
assert.strictEqual(els[0].properties.href, "./jine/příliš")
})
test("footnote anchors stay internal without Obsidian's note-link class", () => {
const fn = (props: Record<string, unknown>): Element => ({
type: "element",
+25 -1
View File
@@ -14,6 +14,8 @@ import {
resolveRelative,
simplifySlug,
slugifyFilePath,
applySlugOptions,
getSlugOptions,
splitAnchor,
stripSlashes,
transformLink,
@@ -86,6 +88,28 @@ export function pageExists(allSlugs: readonly string[], full: string): boolean {
return false
}
/**
* Link targets are written as in the vault (`[[Čeština]]`, `../české/x.png`). With
* `configuration.slugs.stripDiacritics` the pages and files they point at have stripped slugs,
* so the path part of the target is stripped the same way before it is resolved (wikilinks
* from obsidian-flavored-markdown are slugged with the plain rules first). The `#anchor` is
* left alone: heading ids keep their diacritics.
*/
function slugOptionsOnLinkPath(raw: string): string {
if (!getSlugOptions().stripDiacritics) return raw
const hash = raw.indexOf("#")
const linkPath = hash === -1 ? raw : raw.slice(0, hash)
const anchor = hash === -1 ? "" : raw.slice(hash)
let decoded = linkPath
try {
decoded = decodeURI(linkPath)
} catch {
// not percent-encoded (or malformed): strip as written
}
const stripped = applySlugOptions(decoded)
return stripped === decoded ? raw : stripped + anchor
}
export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
const opts = { ...linksDefaults, ...userOpts }
return {
@@ -111,7 +135,7 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
: fileSlug
const rebase = targets.size > 0 || pathSlug !== fileSlug
const resolveLink = (raw: string): RelativeURL => {
const rel = transformLink(pathSlug, raw, transformOptions)
const rel = transformLink(pathSlug, slugOptionsOnLinkPath(raw), transformOptions)
if (!rebase) return rel
const hash = rel.indexOf("#")
const anchor = hash === -1 ? "" : rel.slice(hash)
+59 -1
View File
@@ -1,6 +1,6 @@
import test, { describe } from "node:test"
import assert from "node:assert"
import { getCondition, hasBacklinks } from "./conditions"
import { getCondition, hasBacklinks, registerCondition } from "./conditions"
import type { QuartzComponentProps } from "../../components/types"
type Props = Pick<QuartzComponentProps, "fileData" | "allFiles">
@@ -51,3 +51,61 @@ describe("has-backlinks condition", () => {
assert.strictEqual(hasBacklinks({ fileData: { slug: "a" } } as unknown as Props), false)
})
})
describe("index conditions (#2465)", () => {
const run = (name: string, slug: string | undefined) =>
getCondition(name)!({ fileData: { slug }, allFiles: [] } as unknown as QuartzComponentProps)
test("is-index is true only on the root index page", () => {
assert.strictEqual(run("is-index", "index"), true)
assert.strictEqual(run("is-index", "folder/index"), false)
assert.strictEqual(run("is-index", "page"), false)
assert.strictEqual(run("is-index", undefined), false)
})
test("is-index and not-index are complements", () => {
for (const slug of ["index", "folder/index", "a/b", undefined]) {
assert.strictEqual(run("is-index", slug), !run("not-index", slug))
}
})
test("is-folder-index matches folder index pages, not the root index", () => {
assert.strictEqual(run("is-folder-index", "folder/index"), true)
assert.strictEqual(run("is-folder-index", "a/b/index"), true)
assert.strictEqual(run("is-folder-index", "index"), false)
assert.strictEqual(run("is-folder-index", "folder/indexes"), false)
assert.strictEqual(run("is-folder-index", undefined), false)
})
})
describe("not-<condition> negation", () => {
const withTags = { fileData: { slug: "a", frontmatter: { tags: ["x"] } }, allFiles: [] }
const noTags = { fileData: { slug: "a", frontmatter: {} }, allFiles: [] }
const call = (name: string, p: unknown) => getCondition(name)!(p as QuartzComponentProps)
test("not-has-tags negates has-tags", () => {
assert.strictEqual(call("not-has-tags", withTags), false)
assert.strictEqual(call("not-has-tags", noTags), true)
})
test("negates custom conditions too", () => {
registerCondition("is-draft-test", (p) => p.fileData.slug === "draft")
assert.strictEqual(call("not-is-draft-test", { fileData: { slug: "draft" } }), false)
assert.strictEqual(call("not-is-draft-test", { fileData: { slug: "x" } }), true)
})
test("an exact name wins over negation (not-index is its own built-in)", () => {
assert.strictEqual(call("not-index", { fileData: { slug: "index" } }), false)
assert.strictEqual(call("not-index", { fileData: { slug: "a" } }), true)
})
test("unknown names stay unknown", () => {
assert.strictEqual(getCondition("not-nonexistent"), undefined)
assert.strictEqual(getCondition("not-"), undefined)
assert.strictEqual(getCondition("nonexistent"), undefined)
})
test("double negation works", () => {
assert.strictEqual(call("not-not-has-tags", withTags), true)
})
})
+20 -1
View File
@@ -4,7 +4,13 @@ import { FullSlug, simplifySlug } from "../../util/path"
export type ConditionPredicate = (props: QuartzComponentProps) => boolean
const builtinConditions: Record<string, ConditionPredicate> = {
"is-index": (props) => props.fileData.slug === "index",
"not-index": (props) => props.fileData.slug !== "index",
// A folder's index page: `folder/index.md` or a generated folder page, not the root index.
"is-folder-index": (props) => {
const slug = props.fileData.slug
return typeof slug === "string" && slug.endsWith("/index")
},
"has-tags": (props) => {
const tags = props.fileData.frontmatter?.tags
return Array.isArray(tags) && tags.length > 0
@@ -36,8 +42,21 @@ export function registerCondition(name: string, predicate: ConditionPredicate):
customConditions.set(name, predicate)
}
const NEGATION_PREFIX = "not-"
/**
* Look up a condition. Besides the registered names, `not-<name>` negates any other
* condition (`not-has-tags`, `not-is-folder-index`, a custom `not-<custom>`), unless a
* condition with that exact name exists (`not-index` is its own built-in).
*/
export function getCondition(name: string): ConditionPredicate | undefined {
return customConditions.get(name) ?? builtinConditions[name]
const direct = customConditions.get(name) ?? builtinConditions[name]
if (direct) return direct
if (name.startsWith(NEGATION_PREFIX)) {
const inner = getCondition(name.slice(NEGATION_PREFIX.length))
if (inner) return (props) => !inner(props)
}
return undefined
}
export function getAllConditionNames(): string[] {
+4
View File
@@ -63,6 +63,7 @@ import { componentRegistry, RegisteredComponent } from "../../components/registr
import { frameRegistry } from "../../components/frames/registry"
import { OrderItem, constraintList, normalizePluginName, orderPlugins } from "./plugin-order"
import { resolveExtends } from "./config-extends"
import { setSlugOptions } from "../../util/path"
import { getCondition, getAllConditionNames } from "./conditions"
import {
LAYOUT_SLOTS,
@@ -369,6 +370,7 @@ export async function loadQuartzConfig(
if (!json) {
// Fallback: import old-style config directly
const oldConfig = await import("../../../quartz")
setSlugOptions(oldConfig.default?.configuration?.slugs)
return oldConfig.default
}
@@ -376,6 +378,8 @@ export async function loadQuartzConfig(
...(json.configuration as unknown as GlobalConfiguration),
...configOverrides,
}
// before anything computes a slug (this runs in the main thread and in every worker)
setSlugOptions(configuration.slugs)
// Entries of official plugins that are now built into core (crawl-links, remove-draft,
// content-index) are handled by the built-ins below and never installed or loaded.
+22 -1
View File
@@ -16,7 +16,7 @@ import {
} from "./dispatcher"
import { QuartzPageTypePluginInstance } from "../types"
import { QuartzComponent } from "../../components/types"
import { FilePath, FullSlug, SimpleSlug } from "../../util/path"
import { FilePath, FullSlug, SimpleSlug, setSlugOptions } from "../../util/path"
import { Root as HtmlRoot } from "hast"
import { BuildCtx } from "../../util/ctx"
import { defaultProcessedContent } from "../vfile"
@@ -278,6 +278,27 @@ describe("generateVirtualPages", () => {
assert.strictEqual(ctx.virtualPages.length, 2)
})
test("slugs.stripDiacritics moves folder pages to the stripped folder slug (#2410)", async () => {
setSlugOptions({ stripDiacritics: true })
try {
const entries = await generateVirtualPages(
[makePageType({ generate: () => [page("české/index"), page("tags/čeština")] })],
[],
makeCtx(),
{ head: StubHead },
{},
)
// tag pages keep their slugs: tag links are slugged by the plugins that render them
assert.deepStrictEqual(
entries.map((e) => e.vpSlug),
["ceske/index", "tags/čeština"],
)
assert.strictEqual(entries[0].vfile.data.slug, "ceske/index")
} finally {
setSlugOptions(undefined)
}
})
test("keeps the 404 page out of ctx.virtualPages", async () => {
const ctx = makeCtx()
const entries = await generateVirtualPages(
+4 -1
View File
@@ -15,6 +15,7 @@ import {
pathToRoot,
simplifySlug,
slugifyFilePath,
applySlugOptions,
} from "../../util/path"
import { ProcessedContent, defaultProcessedContent } from "../vfile"
import { write } from "../emitters/helpers"
@@ -215,7 +216,9 @@ export async function generateVirtualPages(
const layout = resolveLayout(pt, defaults, byPageType)
const fileBacked = (pt.fileExtensions?.length ?? 0) > 0
for (const vp of virtualPages) {
const vpSlug = vp.slug as FullSlug
// A folder's page lives at the folder's slug; with `slugs.stripDiacritics` that is the
// stripped one, whatever the page type computed from the file path (folder-page).
const vpSlug = (vp.slug.endsWith("/index") ? applySlugOptions(vp.slug) : vp.slug) as FullSlug
const vpRelativePath = (vpSlug + ".md") as FilePath
const [tree, vfile] = defaultProcessedContent({
slug: vpSlug,
+13 -1
View File
@@ -233,6 +233,18 @@
"default": "all",
"description": "Controls which assets are copied to public. \"all\" copies all non-markdown files; \"referenced\" only copies assets referenced by published pages"
},
"slugs": {
"type": "object",
"additionalProperties": false,
"description": "How file paths become URLs (slugs).",
"properties": {
"stripDiacritics": {
"type": "boolean",
"default": false,
"description": "Strip accents and other diacritics from generated slugs (české/čeština.md → ceske/cestina). Applies to file and folder names, aliases and permalinks; links are resolved the same way."
}
}
},
"frontmatter": {
"description": "Built-in frontmatter parsing: titles, tags, aliases, dates, drafts. Default order 0.",
"oneOf": [
@@ -499,7 +511,7 @@
},
"condition": {
"type": "string",
"description": "Render only when this condition holds. Built-in: not-index, has-tags, has-backlinks, has-toc; plugins may register more."
"description": "Render only when this condition holds. Built-in: is-index, not-index, is-folder-index, has-tags, has-backlinks, has-toc; plugins may register more. Prefix any condition with not- to negate it (not-has-tags)."
},
"group": {
"type": "string",
+47
View File
@@ -392,3 +392,50 @@ describe("resolveRelative", () => {
assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "ghi/" as SimpleSlug), "../ghi/")
})
})
describe("slugs.stripDiacritics (#2410)", () => {
const withStrip = <T>(fn: () => T): T => {
path.setSlugOptions({ stripDiacritics: true })
try {
return fn()
} finally {
path.setSlugOptions(undefined)
}
}
test("off by default: slugs keep their diacritics", () => {
assert.strictEqual(path.slugifyFilePath("české/čeština.md" as path.FilePath), "české/čeština")
})
test("strips diacritics from folder and file names", () => {
withStrip(() => {
const slug = (fp: string) => path.slugifyFilePath(fp as path.FilePath)
assert.strictEqual(slug("české/Čeština.md"), "ceske/cestina")
assert.strictEqual(slug("Příliš žluťoučký kůň.md"), "prilis-zlutoucky-kun")
assert.strictEqual(slug("Café/Crème brûlée.md"), "cafe/creme-brulee")
assert.strictEqual(slug("Tiếng Việt.md"), "tieng-viet")
assert.strictEqual(slug("obrázek.PNG"), "obrazek.PNG")
// decomposed input (macOS file names) gives the same slug
assert.strictEqual(slug("čeština.md"), "cestina")
})
})
test("keeps scripts whose marks are not Latin diacritics", () => {
withStrip(() => {
const slug = (fp: string) => path.slugifyFilePath(fp as path.FilePath)
assert.strictEqual(slug("한국어.md"), "한국어")
assert.strictEqual(slug("がぎぐ.md"), "がぎぐ")
assert.strictEqual(slug("हिन्दी.md"), "हिन्दी")
assert.strictEqual(slug("日本語/中文.md"), "日本語/中文")
// letters without a decomposition are kept
assert.strictEqual(slug("Łódź ø ß.md"), "łodz-ø-ß")
})
})
test("is idempotent", () => {
withStrip(() => {
const once = path.slugifyFilePath("Čeština/Ž.md" as path.FilePath)
assert.strictEqual(path.slugifyFilePath(`${once}.md` as path.FilePath), once)
})
})
})
+56 -1
View File
@@ -6,7 +6,6 @@ export {
isRelativeURL,
isAbsoluteURL,
getFullSlug,
slugifyFilePath,
simplifySlug,
joinSegments,
endsWith,
@@ -35,6 +34,62 @@ export type {
// --- v5-specific exports below ---
import { slugifyFilePath as slugifyFilePathBase } from "@quartz-community/utils"
import * as quartzUtils from "@quartz-community/utils"
import type { FilePath as _FilePath, FullSlug as _FullSlug } from "@quartz-community/utils"
export interface SlugOptions {
/** Strip accents and other diacritics (`č` → `c`, `é` → `e`) from generated slugs. */
stripDiacritics?: boolean
}
let slugOptions: SlugOptions = {}
/**
* Set how core turns file paths into slugs (`configuration.slugs`). Called when the config is
* loaded, in the main thread and in every worker, so all slugs of a build agree.
*/
export function setSlugOptions(options: SlugOptions | undefined): void {
slugOptions = { ...(options ?? {}) }
// @quartz-community/utils 1.3+ applies the same options to every slug it computes, for core
// and for plugins (tag pages, canvas, bases, alias-redirects …). Older utils lack it; core's
// own wrapper below and the links/dispatcher handling then cover core's slugs. Stripping is
// idempotent, so both applying is harmless. (Drop the wrapper once core requires utils 1.3.)
const utilsSetter = (quartzUtils as { setSlugOptions?: (o: SlugOptions | undefined) => void })
.setSlugOptions
utilsSetter?.(slugOptions)
}
export function getSlugOptions(): Readonly<SlugOptions> {
return slugOptions
}
/**
* Remove combining diacritical marks (U+0300–U+036F) after canonical decomposition:
* `Čeština` → `Cestina`, `Ελληνικά` → `Ελληνικα`. The string is recomposed afterwards, so
* scripts whose marks are outside that block (Hangul, kana with dakuten, Devanagari, Arabic)
* keep their usual form. Letters without a decomposition (`ø`, `ł`, `ß`, `æ`) are kept.
*/
export function stripDiacritics(s: string): string {
return s
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.normalize("NFC")
}
/** `stripDiacritics` when `configuration.slugs.stripDiacritics` is on, else unchanged. */
export function applySlugOptions(s: string): string {
return slugOptions.stripDiacritics ? stripDiacritics(s) : s
}
/**
* Slug of a content file path (see `@quartz-community/utils`), honouring
* `configuration.slugs` (see setSlugOptions).
*/
export function slugifyFilePath(fp: _FilePath, excludeExt?: boolean): _FullSlug {
return slugifyFilePathBase(applySlugOptions(fp) as _FilePath, excludeExt)
}
export const QUARTZ = "quartz"
// from micromorph/src/utils.ts