mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-30 22:44:41 +01:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
724d70a631 | ||
|
|
6487fc2415 | ||
|
|
87ee900f05 | ||
|
|
92ff583098 | ||
|
|
c92fed97c0 | ||
|
|
79d3ea9875 | ||
|
|
f2015a4c76 | ||
|
|
2e69d52f76 | ||
|
|
8c81436188 | ||
|
|
fe47fb1239 | ||
|
|
fb4dbab487 | ||
|
|
9ca6f4ee69 | ||
|
|
9ebfc67c1b |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Links resolve against pages before aliases, as in Obsidian, where aliases aren't link targets: `[[upgrading]]` reaches the note `getting-started/upgrading.md` even when another address `upgrading` is an alias, and a note named like an alias wins over it. A link that only an alias matches now goes straight to the page with the alias, so its `#anchor` works (the alias's redirect page dropped it), and backlinks and the graph count it as a link to that page. Aliases are read before the build, like permalinks, so large sites built with worker threads resolve every alias. Redirect pages Quartz writes for `slugs.stripDiacritics` keep the `#anchor` of the address they redirect from.
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@jackyzha0/quartz": minor
|
||||
---
|
||||
|
||||
`quartz.lock.json` is read and written next to the config file Quartz uses, and every `npx quartz plugin` command takes `--config` / `-C` like `build`. A site's repository can hold its content, `quartz.config.yaml` and `quartz.lock.json` while Quartz is checked out elsewhere (as the GitHub Action will). With the config in Quartz's folder nothing changes, and a config elsewhere keeps using an existing lockfile in Quartz's folder until its own folder has one. Plugin commands with a config chosen by `QUARTZ_CONFIG_PATH` now also edit that file; they used to write their changes to `./quartz.config.yaml`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Reinstalling an npm plugin at the version pinned in `quartz.lock.json` (after a fresh clone, or on a CI runner) no longer rewrites its `installedAt`, so `npx quartz plugin install` leaves the lockfile unchanged, as it does for Git plugins.
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@jackyzha0/quartz": minor
|
||||
---
|
||||
|
||||
npm plugins that Quartz's `package.json` doesn't list are pinned in `quartz.lock.json` (version and integrity) and installed into `.quartz/plugins/@scope/name`, like Git plugins. `plugin add`, and `plugin install --from-config` (e.g. for the `obsidian` and `ttrpg` templates' Excalidraw plugin), no longer write them into Quartz's `package.json`, so `npx quartz upgrade` doesn't conflict with your plugins, and `npm install` / `npm ci` can't remove them. `plugin install`, `--latest`, `restore`, `remove`, `prune`, `list`, `doctor` and `npx quartz plugin` handle them alongside Git plugins, and a build installs a missing one at its pinned version. npm plugins in `package.json` (the default plugins, and any you `npm install` yourself) are versioned there and load from `node_modules`, as before: when a plugin is in both, `package.json` wins.
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Plugin update: og-image 1.2.0. A page's social image (`socialImage`, or Obsidian's `image` / `cover` property) can be an image in the content folder, written as a wikilink (`[[cover.png]]`), a path from the content folder, a path relative to the note, or a bare file name. Before, every value that was not a URL was read as a path in `quartz/static/`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Popovers show next to their link with Obsidian themes (quartz-themes-core) too: its Obsidian base styles made them `position: absolute`, so on a scrolled page they appeared a scroll's height above the link, often off screen — links to headings and an embed's "link to original" seemed to show no popover. A popover for a link to a heading now also scrolls the heading to the top of the popover when the theme positions the page's content box.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Links resolve as in Obsidian in more cases (`@quartz-community/utils` 1.3.5): `[[./index|index]]` in a subfolder links to that folder's index page instead of the home page; when several notes share a name, a link prefers the one under the linking note's folder, then the shortest path, instead of pointing to a page that doesn't exist (for example `[Status](current.md)` in a vault where several folders have a `current.md`); a `../` link that names no note resolves from the folder it leads to; and a link starting with `/` is a path from the root.
|
||||
@@ -1,5 +1,17 @@
|
||||
# @jackyzha0/quartz
|
||||
|
||||
## 5.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 9ebfc67: `extends` in `quartz.config.yaml` is stable for `default` and local paths: its merge rules won't change in a minor release. `https://` URLs stay experimental. Keys starting with `$` are now reserved in every file of an `extends` chain (the top-level `$schema` aside), so merge operators such as appending to a list can be added later without changing existing configs; a config that uses one stops with an error naming the key. Configs without `extends` are not affected.
|
||||
- cc8d104: `quartz.lock.json` is read and written next to the config file Quartz uses, and every `npx quartz plugin` command takes `--config` / `-C` like `build`. A site's repository can hold its content, `quartz.config.yaml` and `quartz.lock.json` while Quartz is checked out elsewhere (as the GitHub Action will). With the config in Quartz's folder nothing changes, and a config elsewhere keeps using an existing lockfile in Quartz's folder until its own folder has one. Plugin commands with a config chosen by `QUARTZ_CONFIG_PATH` now also edit that file; they used to write their changes to `./quartz.config.yaml`.
|
||||
- b86276f: npm plugins that Quartz's `package.json` doesn't list are pinned in `quartz.lock.json` (version and integrity) and installed into `.quartz/plugins/@scope/name`, like Git plugins. `plugin add`, and `plugin install --from-config` (e.g. for the `obsidian` and `ttrpg` templates' Excalidraw plugin), no longer write them into Quartz's `package.json`, so `npx quartz upgrade` doesn't conflict with your plugins, and `npm install` / `npm ci` can't remove them. `plugin install`, `--latest`, `restore`, `remove`, `prune`, `list`, `doctor` and `npx quartz plugin` handle them alongside Git plugins, and a build installs a missing one at its pinned version. npm plugins in `package.json` (the default plugins, and any you `npm install` yourself) are versioned there and load from `node_modules`, as before: when a plugin is in both, `package.json` wins.
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ea4b075: Plugin update: og-image 1.2.0. A page's social image (`socialImage`, or Obsidian's `image` / `cover` property) can be an image in the content folder, written as a wikilink (`[[cover.png]]`), a path from the content folder, a path relative to the note, or a bare file name. Before, every value that was not a URL was read as a path in `quartz/static/`.
|
||||
|
||||
## 5.3.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -44,17 +44,20 @@ plugins:
|
||||
|
||||
- `extends` is `default`, a path to another config file relative to this one (which may itself extend another), an `https://` URL, or a list of those. An empty file (or one with only comments) is an empty config, and `extends: []` extends nothing.
|
||||
- A list stacks presets: each file in it adds its own changes. Quartz puts every file of the `extends` chain in one line and applies each once, its bases before it: the list's entries in order, each after the bases it extends, and your file last. A base that several entries share (usually `default`) is applied once, at its first appearance. So with `extends: [./a.yaml, ./b.yaml]`, where both extend `default`, the order is `default` → `a.yaml` → `b.yaml` → your file: what `a.yaml` changes stays unless `b.yaml` changes the same thing (later entries win), and your file wins over both. An entry that doesn't extend the shared base is applied before it if it comes first, so the base's settings win over it; make such a preset extend `default` too, or list it after the others.
|
||||
- A URL is fetched when the config is loaded (10 s timeout, at most 1 MB) and kept in `.quartz-cache/extends/`. If a later fetch fails (offline, timeout, HTTP error), Quartz uses the cached copy and warns; without one, the build stops. `QUARTZ_EXTENDS_OFFLINE=1` uses only the cached copy. Relative `extends` inside a fetched file are resolved against its URL; `default` always means your local `quartz.config.default.yaml`. Only `https://` URLs are allowed, and only extend configs you trust: they choose which plugins your build runs.
|
||||
- **Experimental:** `https://` URLs. How they are fetched, cached and trusted may still change. A URL is fetched when the config is loaded (10 s timeout, at most 1 MB) and kept in `.quartz-cache/extends/`. If a later fetch fails (offline, timeout, HTTP error), Quartz uses the cached copy and warns; without one, the build stops. `QUARTZ_EXTENDS_OFFLINE=1` uses only the cached copy. Relative `extends` inside a fetched file are resolved against its URL; `default` always means your local `quartz.config.default.yaml`. Only `https://` URLs are allowed, and only extend configs you trust: they choose which plugins your build runs.
|
||||
- `configuration` and `layout` merge key by key, including nested objects (`theme.colors.lightMode.secondary` changes only that colour). Any other value replaces the default: strings, numbers and lists such as `ignorePatterns` or `byPageType.<type>.exclude`. Setting a key to `null` removes it, so the built-in default applies.
|
||||
- A plugin entry changes the default entry for the same plugin, matched by name (`github:quartz-community/explorer` matches `@quartz-community/explorer`, and a fork with the same name replaces it). A source with a `name` matches by that name; a source with a `subdir` and no `name` matches by repository and folder, so two plugins of one repository stay separate. `enabled`, `order` and `source` replace the default values. `options` and `layout` merge like `configuration`, and `null` drops them so the plugin's own defaults apply. A plugin that is not in the base is added, and it needs `enabled: true` just as in a full config.
|
||||
- Keys starting with `$` are reserved in every file of an `extends` chain, at any depth (the top-level `$schema` aside): they are kept free for merge operators, such as adding to a list instead of replacing it. A config that uses one stops with an error naming the key. Values may contain `$` freely.
|
||||
- Plugins run in `order` as before. Your file can change a default plugin's `order`. Where two plugins have the same order, the base config's list order decides, and added plugins come last.
|
||||
- Your updates to `quartz.config.default.yaml` (for example after `npx quartz upgrade`) reach your site without copying them over.
|
||||
|
||||
- `npx quartz build --serve` also rebuilds when a local file your config extends changes.
|
||||
- `npx quartz plugin` commands and `npx quartz info` read the merged configuration, as the build does: `plugin list`, `status`, `doctor`, `install` and `prune` see the plugins your bases configure. Commands that change plugins only ever write your own file, never the merged result: `enable`, `disable` and `config --set` add or change your entry for the plugin (`- source: …` with just that change), `config --unset` removes your value and, when a base sets the option, sets it to `null` so the plugin's default applies, and `add` appends a full entry. `remove` refuses a plugin that a base configures (it can't be removed from your file); disable it instead.
|
||||
|
||||
> [!warning] Experimental
|
||||
> `extends` is experimental: the merge rules may still change.
|
||||
> [!note] Stability
|
||||
> `extends` with `default` and local paths is stable: the merge rules above don't change in a minor release. `https://` URLs are experimental.
|
||||
>
|
||||
> A Quartz upgrade can change the defaults your site extends. A changed default applies to your site unless your file sets that value itself.
|
||||
|
||||
## General Configuration
|
||||
|
||||
|
||||
Generated
+6
-6
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@jackyzha0/quartz",
|
||||
"version": "5.3.1",
|
||||
"version": "5.4.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@jackyzha0/quartz",
|
||||
"version": "5.3.1",
|
||||
"version": "5.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^1.8.0",
|
||||
@@ -97,7 +97,7 @@
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^3.0.3",
|
||||
"@quartz-community/types": "^1.3.1",
|
||||
"@quartz-community/utils": "^1.3.4",
|
||||
"@quartz-community/utils": "^1.3.5",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/node": "^26.5.1",
|
||||
"@types/pretty-time": "^1.1.5",
|
||||
@@ -3230,9 +3230,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/utils": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.3.4.tgz",
|
||||
"integrity": "sha512-S1zlszf1jcHXcWXnlow/VxW3kKlTEWWNGQmWP07b8vAOB8lAIkeYRR5KoUA0TdjZPgN5dRaFHaAhv6sC2g/4Gw==",
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.3.5.tgz",
|
||||
"integrity": "sha512-ZN8nlrjrwnrGlOfCArOPqOhAJNiKqhpPp6sqsN31ZoOjCQkExqd5f1+vMpy48SezjFup+k9XJ+yPHRkaGjtPIg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/types": "^1.0.0"
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
"name": "@jackyzha0/quartz",
|
||||
"description": "🌱 publish your digital garden and notes as a website",
|
||||
"private": true,
|
||||
"version": "5.3.1",
|
||||
"version": "5.4.0",
|
||||
"type": "module",
|
||||
"author": "jackyzha0 <j.zhao2k19@gmail.com>",
|
||||
"license": "MIT",
|
||||
@@ -124,7 +124,7 @@
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^3.0.3",
|
||||
"@quartz-community/types": "^1.3.1",
|
||||
"@quartz-community/utils": "^1.3.4",
|
||||
"@quartz-community/utils": "^1.3.5",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/node": "^26.5.1",
|
||||
"@types/pretty-time": "^1.1.5",
|
||||
|
||||
@@ -355,6 +355,17 @@ yargs(hideBin(process.argv))
|
||||
},
|
||||
)
|
||||
.showHelpOnFail(true)
|
||||
.fail((msg, err, y) => {
|
||||
// A mistake in quartz.config.yaml (an `extends` error names the file and the key): the
|
||||
// message says what to fix, so print it without the usage text, which is about arguments.
|
||||
if (err?.name === "ConfigExtendsError") {
|
||||
console.error(`✗ ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
y.showHelp()
|
||||
console.error(err ?? msg)
|
||||
process.exit(1)
|
||||
})
|
||||
.help()
|
||||
.strict()
|
||||
.demandCommand().argv
|
||||
+39
-19
@@ -10,7 +10,7 @@ import { parseMarkdown } from "./processors/parse"
|
||||
import { filterContent } from "./processors/filter"
|
||||
import { emitContent } from "./processors/emit"
|
||||
import cfg from "../quartz"
|
||||
import { FilePath, joinSegments, slugifyFilePath } from "./util/path"
|
||||
import { FilePath, FullSlug, joinSegments, slugifyFilePath } from "./util/path"
|
||||
import { detectSlugCollisions, formatCollisionWarning } from "./util/slugCollisions"
|
||||
import chokidar from "chokidar"
|
||||
import { ProcessedContent } from "./plugins/vfile"
|
||||
@@ -29,42 +29,62 @@ import { prepareContentIndex } from "./plugins/builtins/contentIndex"
|
||||
import { filteredBy, printDiagnosticsSummary, warn } from "./util/diagnostics"
|
||||
import { LinksInstance, removedPages } from "./plugins/builtins/links"
|
||||
import { collectPermalinks } from "./util/permalinks"
|
||||
import { readFrontmatterData } from "./plugins/builtins/frontmatter"
|
||||
import { collectAliases } from "./util/aliases"
|
||||
import { aliasSlugsOf, readFrontmatterData } from "./plugins/builtins/frontmatter"
|
||||
import { ChangeRecord, clearChangeRecord } from "./util/incremental"
|
||||
import { diffContentFiles, pollingEnabled } from "./util/contentWatcher"
|
||||
|
||||
/**
|
||||
* Every page's address: permalinks (frontmatter `permalink`, read up front so links can resolve
|
||||
* to them) and the slugified paths of all files. A permalinked note's file path stays in
|
||||
* `allSlugs`: it becomes a redirect to the permalink.
|
||||
* `allSlugs`: it becomes a redirect to the permalink. Frontmatter `aliases` are read up front
|
||||
* too (`ctx.aliases`), so links that only an alias matches go to the page (util/aliases.ts).
|
||||
*/
|
||||
function updateSlugs(ctx: BuildCtx, allFiles: string[]): void {
|
||||
const frontmatter = ctx.cfg.configuration.frontmatter
|
||||
const enabled =
|
||||
frontmatter !== false && (typeof frontmatter !== "object" || frontmatter.enabled !== false)
|
||||
const options = typeof frontmatter === "object" ? frontmatter : {}
|
||||
const markdown = allFiles.filter((fp) => fp.endsWith(".md"))
|
||||
// frontmatter of the files that may set a permalink or aliases, read once
|
||||
const data = new Map<string, Record<string, unknown>>()
|
||||
if (enabled) {
|
||||
for (const fp of markdown) {
|
||||
let source: Buffer
|
||||
try {
|
||||
source = fs.readFileSync(path.join(ctx.argv.directory, fp))
|
||||
} catch {
|
||||
continue // an unreadable file is reported when the file is parsed
|
||||
}
|
||||
if (!source.includes("permalink") && !source.includes("alias")) continue
|
||||
try {
|
||||
data.set(fp, readFrontmatterData(source, options))
|
||||
} catch {
|
||||
// reported when the file is parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.permalinks = enabled
|
||||
? collectPermalinks({
|
||||
files: allFiles.filter((fp) => fp.endsWith(".md")),
|
||||
permalinkOf: (fp) => {
|
||||
let source: Buffer
|
||||
try {
|
||||
source = fs.readFileSync(path.join(ctx.argv.directory, fp))
|
||||
} catch {
|
||||
return undefined // an unreadable file is reported when the file is parsed
|
||||
}
|
||||
if (!source.includes("permalink")) return undefined
|
||||
try {
|
||||
return readFrontmatterData(source, options).permalink
|
||||
} catch {
|
||||
return undefined // reported when the file is parsed
|
||||
}
|
||||
},
|
||||
files: markdown,
|
||||
permalinkOf: (fp) => data.get(fp)?.permalink,
|
||||
warn: (message) => warn({ area: "permalinks", message }),
|
||||
})
|
||||
: {}
|
||||
ctx.aliases = enabled
|
||||
? collectAliases({
|
||||
files: allFiles,
|
||||
aliasesOf: (fp) => {
|
||||
const fm = data.get(fp)
|
||||
return fm ? aliasSlugsOf(fm) : []
|
||||
},
|
||||
permalinks: ctx.permalinks,
|
||||
})
|
||||
: {}
|
||||
const pathSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath))
|
||||
ctx.allSlugs = [...new Set([...pathSlugs, ...Object.values(ctx.permalinks)])]
|
||||
ctx.allSlugs = [
|
||||
...new Set([...pathSlugs, ...Object.values(ctx.permalinks), ...Object.keys(ctx.aliases)]),
|
||||
] as FullSlug[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+5
@@ -34,6 +34,11 @@ export function installNpmPlugin(
|
||||
},
|
||||
): NpmInstallResult
|
||||
export function removeNpmPlugin(name: string, pluginsDir: string): void
|
||||
export function nextNpmLockEntry(
|
||||
lockEntry: unknown,
|
||||
source: unknown,
|
||||
result: NpmInstallResult,
|
||||
): NpmLockEntry
|
||||
export function ensureNpmPlugin(
|
||||
name: string,
|
||||
options: {
|
||||
|
||||
@@ -254,6 +254,23 @@ export function removeNpmPlugin(name, pluginsDir) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The lock entry for an npm plugin just installed from `source`. Reinstalling the pinned version
|
||||
* (a fresh clone, `npm ci`, a CI runner) keeps `lockEntry` as it is, `installedAt` included, so
|
||||
* restoring plugins leaves quartz.lock.json unchanged, as it does for Git plugins.
|
||||
*/
|
||||
export function nextNpmLockEntry(lockEntry, source, result) {
|
||||
if (
|
||||
isNpmLockEntry(lockEntry) &&
|
||||
lockEntry.source === source &&
|
||||
lockEntry.version === result.version &&
|
||||
(!lockEntry.integrity || !result.integrity || lockEntry.integrity === result.integrity)
|
||||
) {
|
||||
return lockEntry
|
||||
}
|
||||
return { source, ...result, installedAt: new Date().toISOString() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the pinned npm plugin `name` is installed as `lockEntry` pins it (installed at the
|
||||
* locked version, else at `fallbackVersion`). Returns the lock entry fields when it installed
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
isNpmLockEntry,
|
||||
isPinnedNpmPluginInstalled,
|
||||
listPluginDirNames,
|
||||
nextNpmLockEntry,
|
||||
npmPackageName,
|
||||
npmPluginDir,
|
||||
readNpmLockEntry,
|
||||
@@ -241,3 +242,38 @@ describe("ensureNpmPlugin", () => {
|
||||
assert.strictEqual(ensureNpmPlugin("@me/plugin", { pluginsDir }), null)
|
||||
})
|
||||
})
|
||||
|
||||
describe("nextNpmLockEntry", () => {
|
||||
const pinned = {
|
||||
source: "@me/plugin",
|
||||
version: "1.4.2",
|
||||
integrity: "sha512-good",
|
||||
resolved: "https://registry.npmjs.org/@me/plugin/-/plugin-1.4.2.tgz",
|
||||
installedAt: "2026-01-01T00:00:00.000Z",
|
||||
}
|
||||
const result = { version: "1.4.2", integrity: "sha512-good", resolved: pinned.resolved }
|
||||
|
||||
test("reinstalling the pinned version keeps the lock entry, installedAt included", () => {
|
||||
assert.strictEqual(nextNpmLockEntry(pinned, "@me/plugin", result), pinned)
|
||||
})
|
||||
|
||||
test("a new version, source or package is a new entry", () => {
|
||||
const updated = nextNpmLockEntry(pinned, "@me/plugin", { ...result, version: "2.0.0" })
|
||||
assert.strictEqual(updated.version, "2.0.0")
|
||||
assert.notStrictEqual(updated.installedAt, pinned.installedAt)
|
||||
assert.notStrictEqual(nextNpmLockEntry(pinned, "@me/plugin@^1", result), pinned)
|
||||
assert.notStrictEqual(
|
||||
nextNpmLockEntry(pinned, "@me/plugin", { ...result, integrity: "sha512-other" }),
|
||||
pinned,
|
||||
)
|
||||
const added = nextNpmLockEntry(undefined, "@me/plugin", result)
|
||||
assert.deepStrictEqual(
|
||||
{ ...added, installedAt: undefined },
|
||||
{
|
||||
source: "@me/plugin",
|
||||
...result,
|
||||
installedAt: undefined,
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -61,6 +61,7 @@ import {
|
||||
installNpmPlugin,
|
||||
isHostDependency,
|
||||
isNpmLockEntry,
|
||||
nextNpmLockEntry,
|
||||
latestNpmVersion,
|
||||
latestNpmVersionAsync,
|
||||
listPluginDirNames,
|
||||
@@ -614,12 +615,11 @@ async function syncNpmPlugins({ pluginsJson, names, fromConfig, latest, dryRun }
|
||||
pluginsDir: PLUGINS_DIR,
|
||||
})
|
||||
linkPeerPlugins(npmPluginDir(pkg, PLUGINS_DIR))
|
||||
lockfile.plugins[pkg] = {
|
||||
source: entry.source,
|
||||
...result,
|
||||
installedAt: new Date().toISOString(),
|
||||
const next = nextNpmLockEntry(lockEntry, entry.source, result)
|
||||
if (next !== lockEntry) {
|
||||
lockfile.plugins[pkg] = next
|
||||
changed = true
|
||||
}
|
||||
changed = true
|
||||
installedAny = true
|
||||
console.log(styleText("green", `✓ Installed ${pkg}@${result.version}`))
|
||||
} catch (err) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Where a popover goes, and how far its content scrolls to show a heading. Kept out of
|
||||
* popover.inline.ts so tests can import them.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The popover's inline style for a position from floating-ui's `fixed` strategy. The
|
||||
* position is set here, not left to stylesheets: Obsidian's app.css, which quartz-themes-core
|
||||
* bundles for Obsidian themes, makes `.popover` `position: absolute`, and the viewport
|
||||
* coordinates then landed the popover a page's scroll above its link.
|
||||
*/
|
||||
export function popoverPlacement(x: number, y: number) {
|
||||
return {
|
||||
position: "fixed",
|
||||
top: "0",
|
||||
left: "0",
|
||||
transform: `translate(${x.toFixed()}px, ${y.toFixed()}px)`,
|
||||
}
|
||||
}
|
||||
|
||||
interface Box {
|
||||
getBoundingClientRect(): { top: number }
|
||||
}
|
||||
|
||||
/**
|
||||
* The scrollTop that shows `target` `buffer` px below the top of `inner`, measured on screen:
|
||||
* `offsetTop` is relative to the nearest positioned ancestor, which a theme can put inside the
|
||||
* popover (Obsidian themes position `.markdown-preview-view`).
|
||||
*/
|
||||
export function scrollTopFor(inner: Box & { scrollTop: number }, target: Box, buffer = 12) {
|
||||
return (
|
||||
target.getBoundingClientRect().top -
|
||||
inner.getBoundingClientRect().top +
|
||||
inner.scrollTop -
|
||||
buffer
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
||||
import { normalizeRelativeURLs } from "../../util/path"
|
||||
import { fetchCanonical } from "./util"
|
||||
import { popoverPlacement, scrollTopFor } from "./popover-layout"
|
||||
|
||||
const p = new DOMParser()
|
||||
let activeAnchor: HTMLAnchorElement | null = null
|
||||
@@ -19,9 +20,7 @@ async function mouseEnterHandler(
|
||||
strategy: "fixed",
|
||||
middleware: [inline({ x: clientX, y: clientY }), shift(), flip()],
|
||||
})
|
||||
Object.assign(popoverElement.style, {
|
||||
transform: `translate(${x.toFixed()}px, ${y.toFixed()}px)`,
|
||||
})
|
||||
Object.assign(popoverElement.style, popoverPlacement(x, y))
|
||||
}
|
||||
|
||||
function showPopover(popoverElement: HTMLElement) {
|
||||
@@ -37,7 +36,7 @@ async function mouseEnterHandler(
|
||||
const heading = inner.querySelector(targetAnchor) as HTMLElement | null
|
||||
if (heading) {
|
||||
// leave ~12px of buffer when scrolling to a heading
|
||||
inner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })
|
||||
inner.scroll({ top: scrollTopFor(inner, heading), behavior: "instant" })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import test, { describe } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import { popoverPlacement, scrollTopFor } from "./popover-layout"
|
||||
|
||||
type ScrollArg = { top: number; behavior?: ScrollBehavior }
|
||||
// a heading `offsetTop` px from the top of the popover's content (not scrolled)
|
||||
type FakeHeading = { offsetTop: number }
|
||||
const box = (top: number) => ({ getBoundingClientRect: () => ({ top }) })
|
||||
|
||||
interface FakePopoverInner {
|
||||
scrollTop: number
|
||||
getBoundingClientRect: () => { top: number }
|
||||
scroll: (arg: ScrollArg) => void
|
||||
querySelector: (sel: string) => FakeHeading | null
|
||||
_scrolled: ScrollArg | null
|
||||
@@ -25,6 +30,8 @@ interface FakePopoverElement {
|
||||
|
||||
function makeInner(heading: FakeHeading | null = null): FakePopoverInner {
|
||||
const inner: FakePopoverInner = {
|
||||
scrollTop: 0,
|
||||
getBoundingClientRect: () => ({ top: 0 }),
|
||||
scroll(arg) {
|
||||
this._scrolled = arg
|
||||
},
|
||||
@@ -84,7 +91,7 @@ function fixedShowPopover(
|
||||
const targetAnchor = `#popover-internal-${hash.slice(1)}`
|
||||
const heading = inner.querySelector(targetAnchor)
|
||||
if (heading) {
|
||||
inner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })
|
||||
inner.scroll({ top: scrollTopFor(inner, box(heading.offsetTop)), behavior: "instant" })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +114,7 @@ describe("showPopover on cache-hit with hash", () => {
|
||||
assert.deepStrictEqual(
|
||||
inner._scrolled,
|
||||
{ top: 200 - 12, behavior: "instant" },
|
||||
"scroll must target heading.offsetTop - 12",
|
||||
"scroll must show the heading 12px below the top",
|
||||
)
|
||||
assert.deepStrictEqual(inner._selectorsQueried, ["#popover-internal-plugins"])
|
||||
})
|
||||
@@ -221,3 +228,25 @@ describe("bfcache popover cleanup", () => {
|
||||
assert.strictEqual(queried, false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("popover layout", () => {
|
||||
test("the popover is placed with position: fixed, which its coordinates are for", () => {
|
||||
// Obsidian's app.css (quartz-themes-core) sets .popover { position: absolute }
|
||||
assert.deepStrictEqual(popoverPlacement(764.4, -4.6), {
|
||||
position: "fixed",
|
||||
top: "0",
|
||||
left: "0",
|
||||
transform: "translate(764px, -5px)",
|
||||
})
|
||||
})
|
||||
|
||||
test("scrolls to a heading by its position on screen, not its offsetTop", () => {
|
||||
// the content box starts 100px into the popover (an Obsidian theme positions
|
||||
// .markdown-preview-view, so the heading's offsetTop counts from there)
|
||||
const inner = { scrollTop: 0, ...box(200) }
|
||||
assert.strictEqual(scrollTopFor(inner, box(200 + 100 + 5944)), 100 + 5944 - 12)
|
||||
// already scrolled: the same target
|
||||
const scrolled = { scrollTop: 3000, ...box(200) }
|
||||
assert.strictEqual(scrollTopFor(scrolled, box(200 + 100 + 5944 - 3000)), 100 + 5944 - 12)
|
||||
})
|
||||
})
|
||||
@@ -435,6 +435,107 @@ describe("links built-in", () => {
|
||||
assert.deepStrictEqual(file.data.links?.sort(), ["folder/sibling", "t"])
|
||||
})
|
||||
|
||||
// #2725: resolved as Obsidian does (utils 1.3.5)
|
||||
test("a ./ link is in the page's folder, under every strategy", () => {
|
||||
for (const markdownLinkResolution of ["shortest", "absolute", "relative"]) {
|
||||
const { els, file } = run(
|
||||
[a("./index", "index"), a("./sibling")],
|
||||
"folder/special",
|
||||
{ markdownLinkResolution },
|
||||
["index", "folder/index", "folder/special", "folder/sibling", "sibling"],
|
||||
)
|
||||
const [index, sibling] = els.filter((e) => e.tagName === "a")
|
||||
assert.strictEqual(index.properties.href, "./", markdownLinkResolution)
|
||||
assert.strictEqual(index.properties["data-slug"], "folder/index", markdownLinkResolution)
|
||||
assert.strictEqual(sibling.properties["data-slug"], "folder/sibling", markdownLinkResolution)
|
||||
// the folder page, not the home page
|
||||
assert.ok(file.data.links?.includes("folder/" as SimpleSlug), markdownLinkResolution)
|
||||
}
|
||||
})
|
||||
|
||||
test("of several pages with a name, the one under the page's folder, else the shortest path", () => {
|
||||
const allSlugs = [
|
||||
"index",
|
||||
"projects/alpha/index",
|
||||
"projects/alpha/current",
|
||||
"projects/beta/index",
|
||||
"projects/beta/current",
|
||||
]
|
||||
const opts = { markdownLinkResolution: "shortest" }
|
||||
const slugOf = (src: string, target: string) =>
|
||||
run([a(target)], src, opts, allSlugs).els[0]!.properties["data-slug"]
|
||||
// relative-mode vaults write a note in the same folder as a bare name
|
||||
assert.strictEqual(slugOf("projects/alpha/index", "current.md"), "projects/alpha/current")
|
||||
assert.strictEqual(slugOf("projects/beta/index", "current"), "projects/beta/current")
|
||||
// from elsewhere, the shortest path (Obsidian sorts by path length)
|
||||
assert.strictEqual(slugOf("index", "current"), "projects/beta/current")
|
||||
})
|
||||
|
||||
describe("aliases", () => {
|
||||
// getting-started/upgrading.md has `aliases: [upgrading]`; guide.md has `aliases: [How To]`
|
||||
const aliasCtx = (extra: Record<string, unknown> = {}) =>
|
||||
({
|
||||
allSlugs: [
|
||||
"index",
|
||||
"getting-started/upgrading",
|
||||
"guide",
|
||||
"notes/how-to",
|
||||
"upgrading",
|
||||
"how-to",
|
||||
],
|
||||
aliases: { upgrading: "getting-started/upgrading", "how-to": "guide" },
|
||||
...extra,
|
||||
}) as unknown as BuildCtx
|
||||
const resolve = (links: Element[], slug = "getting-started/whats-new", ctx = aliasCtx()) => {
|
||||
const tree: Root = { type: "root", children: links }
|
||||
const file = new VFile("")
|
||||
file.data = { slug: slug as FullSlug }
|
||||
const [factory] = Links({ markdownLinkResolution: "shortest" }).htmlPlugins!(ctx) as [
|
||||
() => (t: Root, f: VFile) => void,
|
||||
]
|
||||
factory()(tree, file)
|
||||
return { links: tree.children as Element[], file }
|
||||
}
|
||||
|
||||
test("a link with an alias's name goes to the page, keeping its anchor", () => {
|
||||
const { links, file } = resolve(
|
||||
[a("upgrading#upgrading-from-52-to-53", "Upgrading")],
|
||||
"index",
|
||||
)
|
||||
// not ./upgrading#…: the alias's redirect page would drop the anchor
|
||||
assert.strictEqual(
|
||||
links[0]!.properties.href,
|
||||
"./getting-started/upgrading#upgrading-from-52-to-53",
|
||||
)
|
||||
assert.strictEqual(links[0]!.properties["data-slug"], "getting-started/upgrading")
|
||||
// backlinks and the graph see a link to the page
|
||||
assert.deepStrictEqual(file.data.links, ["getting-started/upgrading"])
|
||||
})
|
||||
|
||||
test("a page beats an alias with its name, as in Obsidian", () => {
|
||||
// `How To` is an alias of guide.md, but notes/how-to.md is a note with that name
|
||||
const { links } = resolve([a("how-to")], "index")
|
||||
assert.strictEqual(links[0]!.properties["data-slug"], "notes/how-to")
|
||||
})
|
||||
|
||||
test("a name only an alias has goes to its page", () => {
|
||||
const ctx = aliasCtx({
|
||||
allSlugs: ["index", "guide", "how-to"],
|
||||
aliases: { "how-to": "guide" },
|
||||
})
|
||||
const { links } = resolve([a("how-to#step-2", "How To")], "notes/page", ctx)
|
||||
assert.strictEqual(links[0]!.properties.href, "../guide#step-2")
|
||||
assert.ok(!(links[0]!.properties.className as string[]).includes("broken"))
|
||||
})
|
||||
|
||||
test("an alias named like an Object property is still an alias", () => {
|
||||
const ctx = aliasCtx({ allSlugs: ["index", "guide"], aliases: {} })
|
||||
const { links } = resolve([a("constructor")], "index", ctx)
|
||||
assert.strictEqual(links[0]!.properties["data-slug"], "constructor")
|
||||
assert.ok((links[0]!.properties.className as string[]).includes("broken"))
|
||||
})
|
||||
})
|
||||
|
||||
test("slugs.stripDiacritics: link targets are stripped like the slugs they point at (#2410)", () => {
|
||||
setSlugOptions({ stripDiacritics: true })
|
||||
try {
|
||||
@@ -451,7 +552,8 @@ describe("links built-in", () => {
|
||||
["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")
|
||||
// ./ is relative to ceske/page (utils 1.3.5): the same page as ../ceske/cestina
|
||||
assert.strictEqual(cestina.properties.href, "./cestina#český-nadpis")
|
||||
assert.ok(!(cestina.properties.className as string[]).includes("broken"))
|
||||
assert.strictEqual(prilis.properties.href, "../jine/prilis")
|
||||
assert.strictEqual(
|
||||
|
||||
@@ -58,6 +58,12 @@ function getAliasSlugs(aliases: string[]): FullSlug[] {
|
||||
})
|
||||
}
|
||||
|
||||
/** Slugs of the `aliases` (or `alias`) in raw frontmatter, as {@link normalizeFrontmatter} reads them. */
|
||||
export function aliasSlugsOf(data: Record<string, unknown>): FullSlug[] {
|
||||
const aliases = coerceToArray(coalesceAliases(data, ["aliases", "alias"]))
|
||||
return aliases ? getAliasSlugs(aliases) : []
|
||||
}
|
||||
|
||||
/** `[[Some Note#Heading]]` target → `some-note#heading` (same slugging as wikilinks). */
|
||||
export function slugifyWikilinkTarget(target: string): string {
|
||||
const [rawPath, anchor] = splitAnchor(target)
|
||||
|
||||
@@ -112,6 +112,29 @@ export function linkTargetMissing(allSlugs: readonly string[], full: string): bo
|
||||
return VAULT_FILE_TYPES.has(ext)
|
||||
}
|
||||
|
||||
/**
|
||||
* `allSlugs` without alias addresses (see util/aliases.ts), for resolving links against pages.
|
||||
* Cached: `allSlugs` only grows while files are parsed, and `aliases` is replaced on a rebuild.
|
||||
*/
|
||||
let pageSlugsCache: {
|
||||
from: readonly string[]
|
||||
length: number
|
||||
aliases: object
|
||||
slugs: FullSlug[]
|
||||
} = { from: [], length: -1, aliases: {}, slugs: [] }
|
||||
/** The page an alias slug belongs to (own keys only: `constructor` is a fine slug). */
|
||||
const aliasTarget = (aliases: Record<string, FullSlug>, slug: string): FullSlug | undefined =>
|
||||
Object.hasOwn(aliases, slug) ? aliases[slug] : undefined
|
||||
|
||||
export function pageSlugs(allSlugs: FullSlug[], aliases: Record<string, FullSlug>): FullSlug[] {
|
||||
if (Object.keys(aliases).length === 0) return allSlugs
|
||||
const c = pageSlugsCache
|
||||
if (c.from === allSlugs && c.length === allSlugs.length && c.aliases === aliases) return c.slugs
|
||||
const slugs = allSlugs.filter((slug) => !Object.hasOwn(aliases, slug))
|
||||
pageSlugsCache = { from: allSlugs, length: allSlugs.length, aliases, slugs }
|
||||
return slugs
|
||||
}
|
||||
|
||||
/** The `broken` mark added after filtering, so a later rebuild can take it off again. */
|
||||
const FILTERED_ATTR = "data-filtered"
|
||||
/** The `broken` mark for links to folder and tag pages that no page type generated. */
|
||||
@@ -258,13 +281,29 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
|
||||
? slugifyFilePath(file.data.relativePath)
|
||||
: fileSlug
|
||||
const rebase = targets.size > 0 || pathSlug !== fileSlug
|
||||
// Aliases: links resolve against the site's pages first (in Obsidian aliases aren't
|
||||
// link targets, so `[[upgrading]]` is the note `getting-started/upgrading`, not the
|
||||
// alias `upgrading` of some note). A link only an alias matches goes straight to the
|
||||
// page with the alias, keeping its anchor, which the alias's redirect page drops.
|
||||
const aliases = ctx.aliases ?? {}
|
||||
const pageOptions: TransformOptions = {
|
||||
...transformOptions,
|
||||
allSlugs: pageSlugs(ctx.allSlugs, aliases),
|
||||
}
|
||||
const resolveLink = (raw: string): RelativeURL => {
|
||||
const rel = transformLink(pathSlug, raw, transformOptions)
|
||||
if (!rebase) return rel
|
||||
let rel = transformLink(pathSlug, raw, pageOptions)
|
||||
let target = canonicalSlug(rel, simplifySlug(pathSlug))
|
||||
let page = aliasTarget(aliases, target)
|
||||
if (page === undefined && linkTargetMissing(pageOptions.allSlugs, target)) {
|
||||
// a name only an alias has, resolved like a page's (e.g. a path alias `a/b`)
|
||||
rel = transformLink(pathSlug, raw, transformOptions)
|
||||
target = canonicalSlug(rel, simplifySlug(pathSlug))
|
||||
page = aliasTarget(aliases, target)
|
||||
}
|
||||
if (page === undefined && !rebase) return rel
|
||||
const hash = rel.indexOf("#")
|
||||
const anchor = hash === -1 ? "" : rel.slice(hash)
|
||||
const target = canonicalSlug(rel, simplifySlug(pathSlug))
|
||||
return (resolveRelative(fileSlug, targets.get(target) ?? target) +
|
||||
return (resolveRelative(fileSlug, page ?? targets.get(target) ?? target) +
|
||||
anchor) as RelativeURL
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ describe("SlugRedirects emitter", () => {
|
||||
<link rel="canonical" href="${url}">
|
||||
<meta name="robots" content="noindex">
|
||||
<meta charset="utf-8">
|
||||
<script>location.replace(${JSON.stringify(url)} + location.hash)</script>
|
||||
<meta http-equiv="refresh" content="0; url=${url}">
|
||||
</head>
|
||||
</html>
|
||||
|
||||
@@ -73,6 +73,7 @@ function redirectHtml(to: string, url: string): string {
|
||||
<link rel="canonical" href="${url}">
|
||||
<meta name="robots" content="noindex">
|
||||
<meta charset="utf-8">
|
||||
<script>location.replace(${JSON.stringify(url).replace(/</g, "\\u003c")} + location.hash)</script>
|
||||
<meta http-equiv="refresh" content="0; url=${url}">
|
||||
</head>
|
||||
</html>
|
||||
|
||||
@@ -379,6 +379,70 @@ describe("resolveExtends", () => {
|
||||
)
|
||||
})
|
||||
|
||||
describe("keys starting with $ are reserved", () => {
|
||||
const own = path.join(root, "quartz.config.yaml")
|
||||
const opts = { quartzRoot: root, readFile }
|
||||
|
||||
test("in the extending file, at any depth", async () => {
|
||||
for (const [data, where] of [
|
||||
[
|
||||
{ configuration: { ignorePatterns: { $append: ["drafts"] } } },
|
||||
"configuration.ignorePatterns.$append",
|
||||
],
|
||||
[{ configuration: { $pageTitle: "x" } }, "configuration.$pageTitle"],
|
||||
[
|
||||
{ layout: { byPageType: { folder: { $exclude: [] } } } },
|
||||
"layout.byPageType.folder.$exclude",
|
||||
],
|
||||
[
|
||||
{ plugins: [{ source: "@quartz-community/explorer", options: { $merge: {} } }] },
|
||||
"plugins.0.options.$merge",
|
||||
],
|
||||
[
|
||||
{ plugins: [{ source: "@quartz-community/explorer", $remove: true }] },
|
||||
"plugins.0.$remove",
|
||||
],
|
||||
[{ $plugins: [] }, "$plugins"],
|
||||
] as const) {
|
||||
await assert.rejects(
|
||||
() => resolveExtends({ extends: "default", ...data }, own, opts),
|
||||
{
|
||||
name: "ConfigExtendsError",
|
||||
message: `${own}: "${where}" — keys starting with "$" are reserved in configs that use "extends"`,
|
||||
},
|
||||
where,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test("in a base the config extends", async () => {
|
||||
put("preset.yaml", { extends: "default", configuration: { $x: 1 } })
|
||||
await assert.rejects(
|
||||
() => resolveExtends({ extends: "./preset.yaml" }, own, opts),
|
||||
/preset\.yaml: "configuration\.\$x" — keys starting with "\$" are reserved/,
|
||||
)
|
||||
})
|
||||
|
||||
test("the top-level $schema is allowed, and $ inside values is fine", async () => {
|
||||
const merged = await resolveExtends(
|
||||
{
|
||||
$schema: "./quartz/plugins/quartz-plugins.schema.json",
|
||||
extends: "default",
|
||||
configuration: { pageTitle: "$5 tips", ignorePatterns: ["$tmp"] },
|
||||
},
|
||||
own,
|
||||
opts,
|
||||
)
|
||||
assert.strictEqual(merged.configuration.pageTitle, "$5 tips")
|
||||
assert.deepStrictEqual(merged.configuration.ignorePatterns, ["$tmp"])
|
||||
})
|
||||
|
||||
test("a config without extends is not checked", async () => {
|
||||
const data = { configuration: { pageTitle: "x", $custom: 1 }, plugins: [] }
|
||||
assert.strictEqual(await resolveExtends(data, own, opts), data as never)
|
||||
})
|
||||
})
|
||||
|
||||
test("a base that is not a configuration object is an error", async () => {
|
||||
files[path.join(root, "list.yaml")] = "- source: explorer\n- source: graph\n"
|
||||
const file = path.join(root, "list.yaml")
|
||||
|
||||
@@ -342,6 +342,32 @@ export function resolveTarget(target: string, from: string, quartzRoot: string):
|
||||
return resolved
|
||||
}
|
||||
|
||||
/**
|
||||
* Keys starting with `$` are reserved in every file of an `extends` chain (the top-level
|
||||
* `$schema` aside), at any depth: they are kept free for merge operators, such as appending
|
||||
* to a list instead of replacing it, so adding those later changes no existing config.
|
||||
*/
|
||||
export const RESERVED_KEY_PREFIX = "$"
|
||||
|
||||
function assertNoReservedKeys(data: PlainObject, file: string) {
|
||||
const visit = (value: unknown, at: string[]) => {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item, i) => visit(item, [...at, String(i)]))
|
||||
return
|
||||
}
|
||||
if (!isPlainObject(value)) return
|
||||
for (const [key, child] of Object.entries(value)) {
|
||||
if (key.startsWith(RESERVED_KEY_PREFIX) && !(at.length === 0 && key === "$schema")) {
|
||||
throw new ConfigExtendsError(
|
||||
`${file}: "${[...at, key].join(".")}" — keys starting with "${RESERVED_KEY_PREFIX}" are reserved in configs that use "extends"`,
|
||||
)
|
||||
}
|
||||
visit(child, [...at, key])
|
||||
}
|
||||
}
|
||||
visit(data, [])
|
||||
}
|
||||
|
||||
interface ConfigLayer {
|
||||
/** Resolved path or URL ("" for the config being resolved). */
|
||||
file: string
|
||||
@@ -443,6 +469,7 @@ async function extendsLayers(
|
||||
await visit(parsed, targetFile, here)
|
||||
}
|
||||
const { extends: _drop, ...own } = node
|
||||
assertNoReservedKeys(own, nodeFile)
|
||||
layers.push({ file: chain.length === 0 ? "" : self, data: own })
|
||||
applied.add(self)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
"description": "JSON Schema reference"
|
||||
},
|
||||
"extends": {
|
||||
"description": "Start from another config and apply this file on top: \"default\" (quartz.config.default.yaml) or a path relative to this file, or a list of them (later ones win). Objects merge key by key, other values replace, null removes a key; plugin entries match the base entry of the same plugin by name. Without extends, this file is the whole configuration.",
|
||||
"description": "Start from another config and apply this file on top: \"default\" (quartz.config.default.yaml), a path relative to this file, an https:// URL (experimental), or a list of them (later ones win). Objects merge key by key, other values replace, null removes a key; plugin entries match the base entry of the same plugin by name. Keys starting with $ are reserved (except $schema). Without extends, this file is the whole configuration.",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, test } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import { collectAliases } from "./aliases"
|
||||
import { FullSlug } from "./path"
|
||||
|
||||
describe("collectAliases", () => {
|
||||
const files = [
|
||||
"index.md",
|
||||
"getting-started/upgrading.md",
|
||||
"guide.md",
|
||||
"notes/how-to.md",
|
||||
"moved.md",
|
||||
"img/how-to.png",
|
||||
]
|
||||
const frontmatter: Record<string, string[]> = {
|
||||
"getting-started/upgrading.md": ["upgrading", "getting-started/upgrading"],
|
||||
"guide.md": ["how-to", "guide-old", "notes/how-to", "img/how-to.png"],
|
||||
"moved.md": ["guide-old", "previous"],
|
||||
}
|
||||
const aliases = collectAliases({
|
||||
files,
|
||||
aliasesOf: (file) => (frontmatter[file] ?? []) as FullSlug[],
|
||||
permalinks: { "moved.md": "elsewhere/moved" as FullSlug },
|
||||
})
|
||||
|
||||
test("maps each alias to the page that has it, at its published address", () => {
|
||||
assert.deepStrictEqual(aliases, {
|
||||
upgrading: "getting-started/upgrading",
|
||||
"how-to": "guide",
|
||||
"guide-old": "guide",
|
||||
previous: "elsewhere/moved",
|
||||
})
|
||||
})
|
||||
|
||||
test("a page's address is never an alias: its own path, another page's or a file's", () => {
|
||||
for (const slug of ["getting-started/upgrading", "notes/how-to", "img/how-to.png"]) {
|
||||
assert.ok(!Object.hasOwn(aliases, slug), slug)
|
||||
}
|
||||
})
|
||||
|
||||
test("of two notes with an alias, the first keeps it", () => {
|
||||
assert.strictEqual(aliases["guide-old"], "guide")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import { FilePath, FullSlug, slugifyFilePath } from "./path"
|
||||
import { Permalinks, slugForFile } from "./permalinks"
|
||||
|
||||
/**
|
||||
* Frontmatter `aliases`: alias slug → the slug of the page that has the alias.
|
||||
*
|
||||
* An alias is an extra address of a note: the alias-redirects plugin writes a redirect page
|
||||
* there. Links resolve against real pages first (as in Obsidian, where aliases are not link
|
||||
* targets), and a link that only an alias matches goes straight to the page, so an `#anchor`
|
||||
* survives (a redirect page drops it). Like permalinks, aliases are collected up front, so every
|
||||
* worker thread knows all of them, not only those of the files it parsed.
|
||||
*/
|
||||
export type Aliases = Record<string, FullSlug>
|
||||
|
||||
export interface CollectAliasesOptions {
|
||||
/** All content files, relative to the content directory. */
|
||||
files: string[]
|
||||
/** Alias slugs of a Markdown file (from its frontmatter); empty when it has none. */
|
||||
aliasesOf: (file: string) => readonly FullSlug[]
|
||||
permalinks?: Permalinks
|
||||
}
|
||||
|
||||
/**
|
||||
* Aliases of `files`. An alias that is a page's address (a file path or a permalink) is left
|
||||
* out: the page wins, as the redirect pages never replace a page either. Of two notes with the
|
||||
* same alias, the first keeps it.
|
||||
*/
|
||||
export function collectAliases({ files, aliasesOf, permalinks }: CollectAliasesOptions): Aliases {
|
||||
const pages = new Set<string>(files.map((f) => slugifyFilePath(f as FilePath)))
|
||||
for (const slug of Object.values(permalinks ?? {})) pages.add(slug)
|
||||
const aliases: Aliases = {}
|
||||
for (const file of files) {
|
||||
if (!file.endsWith(".md")) continue
|
||||
const page = slugForFile(file, permalinks)
|
||||
for (const alias of aliasesOf(file)) {
|
||||
if (alias === page || pages.has(alias) || Object.hasOwn(aliases, alias)) continue
|
||||
aliases[alias] = page
|
||||
}
|
||||
}
|
||||
return aliases
|
||||
}
|
||||
@@ -11,6 +11,7 @@ describe("workerCtx", () => {
|
||||
allSlugs: ["index", "elsewhere/moved"] as FullSlug[],
|
||||
allFiles: ["index.md", "Moved.md"] as FilePath[],
|
||||
permalinks: { "Moved.md": "elsewhere/moved" as FullSlug },
|
||||
aliases: { "old-name": "index" as FullSlug },
|
||||
incremental: false,
|
||||
virtualPages: [],
|
||||
trie: {},
|
||||
@@ -20,6 +21,10 @@ describe("workerCtx", () => {
|
||||
assert.deepStrictEqual(workerCtx(ctx).permalinks, { "Moved.md": "elsewhere/moved" })
|
||||
})
|
||||
|
||||
test("carries aliases to worker threads", () => {
|
||||
assert.deepStrictEqual(workerCtx(ctx).aliases, { "old-name": "index" })
|
||||
})
|
||||
|
||||
test("holds plain data only, and survives structured cloning", () => {
|
||||
const worker = workerCtx(ctx)
|
||||
assert.ok(!("cfg" in worker) && !("trie" in worker))
|
||||
|
||||
+9
-1
@@ -40,6 +40,11 @@ export interface BuildCtx {
|
||||
* (Obsidian Publish semantics, see util/permalinks.ts). Plain data, so it reaches worker threads.
|
||||
*/
|
||||
permalinks?: Record<string, FullSlug>
|
||||
/**
|
||||
* Frontmatter aliases: alias slug → the slug of the page that has it (util/aliases.ts).
|
||||
* Plain data, so it reaches worker threads.
|
||||
*/
|
||||
aliases?: Record<string, FullSlug>
|
||||
trie?: FileTrieNode<BuildTimeTrieData>
|
||||
incremental: boolean
|
||||
/**
|
||||
@@ -95,7 +100,9 @@ export type WorkerSerializableBuildCtx = Omit<BuildCtx, "cfg" | "trie">
|
||||
|
||||
/** The plain-data fields of {@link BuildCtx} that worker threads need, each one required. */
|
||||
type WorkerCtxFields = {
|
||||
[K in "buildId" | "argv" | "allSlugs" | "allFiles" | "permalinks" | "incremental"]-?: BuildCtx[K]
|
||||
[
|
||||
K in "buildId" | "argv" | "allSlugs" | "allFiles" | "permalinks" | "aliases" | "incremental"
|
||||
]-?: BuildCtx[K]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,6 +118,7 @@ export function workerCtx(ctx: BuildCtx): WorkerSerializableBuildCtx {
|
||||
allSlugs: ctx.allSlugs,
|
||||
allFiles: ctx.allFiles,
|
||||
permalinks: ctx.permalinks ?? {},
|
||||
aliases: ctx.aliases ?? {},
|
||||
incremental: ctx.incremental,
|
||||
}
|
||||
return { ...fields, virtualPages: [] }
|
||||
|
||||
Reference in new issue
Block a user