mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-30 22:44:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d255c3a0b | ||
|
|
f5ef8f738d | ||
|
|
e7da9cebf4 | ||
|
|
28581e8e54 | ||
|
|
4ff86a7809 | ||
|
|
7688df602b | ||
|
|
fc865525b7 | ||
|
|
0f294f7139 | ||
|
|
3c7cba46ae | ||
|
|
4683f8b462 | ||
|
|
8be3806431 | ||
|
|
98cfbfabe8 | ||
|
|
6c91c6d621 |
No files matched your search
@@ -0,0 +1,10 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Links as in Obsidian 1.15.0:
|
||||
|
||||
- A Markdown link whose path is not valid percent-encoding (`[x](%zz)`, `[x](a%E2.md)`) is an external link. Before, it failed the whole build with `URI malformed`.
|
||||
- Link paths are NFC-normalized, so a link spelled with a decomposed `é` reaches `café.md`.
|
||||
- An image of a file the site doesn't have, with no alt text, gets its percent-decoded path as alt (`` → “missing pic.png”), as Obsidian names a missing embed.
|
||||
- A wikilink's `^id` no longer names its paragraph (Obsidian Flavored Markdown).
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
On Windows, regenerating `.quartz/plugins/index.ts` (`npm run install-plugins`, which also runs before every `npm run build`) no longer skips npm plugins with "dist/index.d.ts could not be found", which left exports such as `ExternalPlugin.Explorer` undefined. The package's location was read from a `file:` URL's pathname (`/C:/…`), which is not a Windows path.
|
||||
@@ -5,7 +5,7 @@
|
||||
Updated default plugins (see each plugin's changelog for details):
|
||||
|
||||
- **Changed heading ids:** with SmartyPants on (the default), a heading containing `--` now gets the same id as on GitHub: `## Range 1--2` → `range-1--2` (was `range-12`). Links that hard-code the old id need updating; `[[page#Range 1--2]]` keeps working. Links Obsidian writes to headings containing `:`, `|`, `^`, `#` or `\` now reach them, and heading ids, links and table-of-contents entries share one slug function (GitHubFlavoredMarkdown 2.1.0, TableOfContents, CrawlLinks, utils 1.1).
|
||||
- **Changed in Bases:** `file.name` includes the file's extension, as in Obsidian (`Note.md`, `Plan.canvas`); use `file.basename` for the name without it. Base views also list canvas and Excalidraw files with their real paths, `this` in a base embedded in a note is that note, `file.inFolder("")` matches the content root, and Quartz's generated pages (404, tags, folder listings) no longer appear as notes (BasesPage 1.1.0, CanvasPage, Excalidraw).
|
||||
- **Bases now behave as in Obsidian 1.15** (BasesPage 1.2.0, checked against real Obsidian): subtracting dates gives a duration (`(due - today()).days`); nested tags match (`file.tags.contains("#project")` finds `#project/x`); dates display in the site's locale, and `date()` reads only ISO-style dates; cards use Obsidian's aspect ratio and layout; `link()` with any URL is an external link; a base opens on its first view; tags link to their tag pages; `this.<property>` in an embedded base reads the embedding note. Base views also list canvas and Excalidraw files with their real paths, `this` in an embedded base is that note, and Quartz's generated pages (404, tags, folder listings) no longer appear as notes. **Changed:** `file.tags` keeps `#` and the original case, the `tags` property no longer includes inline tags, `hasTag(a, b)` matches any of its tags, the root folder is `/`, text `contains` ignores case, and the cards' `imageAspectRatio` is height/width (it was inverted). `file.name` is as in Obsidian: a Markdown note's name has no extension (`Note`), other files keep theirs (`Plan.canvas`); `file.fullname` has the extension for every file.
|
||||
- Folder pages list folders that hold only canvas, base or other generated pages (FolderPage).
|
||||
- A footnote referenced only from a table cell past the table's columns is rendered, as in Obsidian (ObsidianFlavoredMarkdown 2.1.1, with remark-obsidian 2.2.0: faster parsing and fixes for deeply nested notes and `\r\n` line endings).
|
||||
- A short wikilink to an Obsidian folder note (`[[Topic]]` for `Topic/Topic.md`) reaches the folder page (utils 1.1).
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
A local plugin source written with Windows separators (`.\my-plugin`, `..\plugins\my-plugin`) is recognised as a local path. Before, it was read as a git or npm source and failed with "Expected github:owner/repo".
|
||||
|
||||
Pretty links shorten link text the same way on every OS: Windows also cut it at a backslash (`[[a\b]]` showed `b`).
|
||||
Generated
+21
-21
@@ -16,7 +16,7 @@
|
||||
"@quartz-community/alias-redirects": "^1.0.2",
|
||||
"@quartz-community/article-title": "^1.0.2",
|
||||
"@quartz-community/backlinks": "^1.0.3",
|
||||
"@quartz-community/bases-page": "^1.1.2",
|
||||
"@quartz-community/bases-page": "^1.2.1",
|
||||
"@quartz-community/breadcrumbs": "^1.0.3",
|
||||
"@quartz-community/canvas-page": "^1.0.3",
|
||||
"@quartz-community/citations": "^1.0.1",
|
||||
@@ -38,7 +38,7 @@
|
||||
"@quartz-community/hard-line-breaks": "^1.1.0",
|
||||
"@quartz-community/latex": "^1.0.1",
|
||||
"@quartz-community/note-properties": "^1.1.4",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.1.2",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.1.3",
|
||||
"@quartz-community/og-image": "^1.1.1",
|
||||
"@quartz-community/ox-hugo": "^1.0.1",
|
||||
"@quartz-community/page-title": "^1.0.2",
|
||||
@@ -98,7 +98,7 @@
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.29.2",
|
||||
"@quartz-community/types": "^1.3.0",
|
||||
"@quartz-community/utils": "^1.1.1",
|
||||
"@quartz-community/utils": "^1.2.0",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^26.5.1",
|
||||
@@ -2420,9 +2420,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/bases-page": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.1.2.tgz",
|
||||
"integrity": "sha512-Uw45RwEjvhquTWEMuoZszG5oln4o6zMRMSWmLED1gxL4w/zl1zkHgpOIc4LFVyP+UR/lGL5Blh4rHsFAdq2Tyw==",
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.2.1.tgz",
|
||||
"integrity": "sha512-mONeRLsZTNPT5fOJfdlM1Uq97V7aGnxSRZaT0X4PsR5bbEAIjnBoVEdsYrYZWypm/c6go58/59fXbpeexKFsFw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/types": "^1.0.0",
|
||||
@@ -2917,15 +2917,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/obsidian-flavored-markdown": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.1.2.tgz",
|
||||
"integrity": "sha512-aayc91CLyI2nwq0vs4i+7Q8723QuVjADk/EaQlg47GEM3MuRS5RcgEC+NBCeA59/JnJyqqmLHTC1ZITQ9L+Yww==",
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.1.3.tgz",
|
||||
"integrity": "sha512-p5fls4M7ocUKrlF8MmfrlnNPEvBFZ5diVNVVkLsgTwCvzf19MrnczeKb3Q2yI2S1G2Xb0rXsq8kmF8faj+Q79A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/rehype-obsidian": "^1.2.0",
|
||||
"@quartz-community/remark-obsidian": "^2.2.0",
|
||||
"@quartz-community/rehype-obsidian": "^1.3.0",
|
||||
"@quartz-community/remark-obsidian": "^2.2.1",
|
||||
"@quartz-community/types": "^1.1.0",
|
||||
"@quartz-community/utils": "^1.1.0",
|
||||
"@quartz-community/utils": "^1.2.0",
|
||||
"pele": "^1.13.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -3089,18 +3089,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/rehype-obsidian": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.2.1.tgz",
|
||||
"integrity": "sha512-wuxPcG5ie4J7x7KMfOZMDSgyNKFJf6x6I+I6H4XaZ4WX4sPlEfMUDTvxBoHRHpstqfCRX5Hy73d/K9/rYAZdnw==",
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.3.0.tgz",
|
||||
"integrity": "sha512-62YFEr3NR/Z2G/wcq30/VVKTlT4RUKezWfwGTQkNC+9mAXcUb3gAwjgiUJwylXZQyZmBf+SZsCNmdhIb7CPh/g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/remark-obsidian": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/remark-obsidian/-/remark-obsidian-2.2.0.tgz",
|
||||
"integrity": "sha512-uSuUA3CA2ebAls7IXaevgQGqqbho1fR0lORKUTmhOTEUTYt8GBkl7ipaik4Y7x3q1LzUflejgFIGl/0XO83OGw==",
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/remark-obsidian/-/remark-obsidian-2.2.1.tgz",
|
||||
"integrity": "sha512-Q18F/Px8db8Evf6uwPKz0RMhZNyrsH2Okzhr6FWcsm51fYgJR+SiO98/2fmXQ3wnqV2eeJC7ZMzi81SDjK8vrg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -3342,9 +3342,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/utils": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.1.1.tgz",
|
||||
"integrity": "sha512-iHjEOlbpqznut9YkoflXxd2Bl5TaBcMFwIouRxp2HTBcbCQbmHtAsL3sdLheC1YeM9bMxeFLAN2b7rIBR2r/og==",
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.2.0.tgz",
|
||||
"integrity": "sha512-X32uBfhfNACQw2Ciw6F0XQ9qSoTMQeh78/2ZEj8cYuOk7VTowNf0dpjtSDKAxs1co6aSpIEcDZBIG6p953UPiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/types": "^1.0.0"
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@
|
||||
"@quartz-community/alias-redirects": "^1.0.2",
|
||||
"@quartz-community/article-title": "^1.0.2",
|
||||
"@quartz-community/backlinks": "^1.0.3",
|
||||
"@quartz-community/bases-page": "^1.1.2",
|
||||
"@quartz-community/bases-page": "^1.2.1",
|
||||
"@quartz-community/breadcrumbs": "^1.0.3",
|
||||
"@quartz-community/canvas-page": "^1.0.3",
|
||||
"@quartz-community/citations": "^1.0.1",
|
||||
@@ -68,7 +68,7 @@
|
||||
"@quartz-community/hard-line-breaks": "^1.1.0",
|
||||
"@quartz-community/latex": "^1.0.1",
|
||||
"@quartz-community/note-properties": "^1.1.4",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.1.2",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.1.3",
|
||||
"@quartz-community/og-image": "^1.1.1",
|
||||
"@quartz-community/ox-hugo": "^1.0.1",
|
||||
"@quartz-community/page-title": "^1.0.2",
|
||||
@@ -125,7 +125,7 @@
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.29.2",
|
||||
"@quartz-community/types": "^1.3.0",
|
||||
"@quartz-community/utils": "^1.1.1",
|
||||
"@quartz-community/utils": "^1.2.0",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^26.5.1",
|
||||
|
||||
@@ -264,6 +264,10 @@ export function isLocalSource(source) {
|
||||
if (url.startsWith("./") || url.startsWith("../") || url.startsWith("/")) {
|
||||
return true
|
||||
}
|
||||
// Windows relative paths (.\plugin, ..\plugin)
|
||||
if (url.startsWith(".\\") || url.startsWith("..\\")) {
|
||||
return true
|
||||
}
|
||||
// Windows absolute paths (e.g. C:\ or D:/)
|
||||
if (/^[A-Za-z]:[\\/]/.test(url)) {
|
||||
return true
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import test, { describe } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import YAML from "yaml"
|
||||
import { stringifyConfigYaml, parseGitSource, extractPluginName } from "./plugin-data.js"
|
||||
import {
|
||||
stringifyConfigYaml,
|
||||
parseGitSource,
|
||||
extractPluginName,
|
||||
isLocalSource,
|
||||
} from "./plugin-data.js"
|
||||
|
||||
const ORIGINAL = `# yaml-language-server: $schema=./quartz/plugins/quartz-plugins.schema.json
|
||||
configuration:
|
||||
@@ -92,3 +97,23 @@ describe("parseGitSource", () => {
|
||||
assert.throws(() => parseGitSource("github:onlyowner"), /Expected github:owner\/repo/)
|
||||
})
|
||||
})
|
||||
|
||||
describe("isLocalSource", () => {
|
||||
test("recognises local paths in POSIX and Windows spellings", () => {
|
||||
for (const source of [
|
||||
"./p",
|
||||
"../p",
|
||||
"/p",
|
||||
".\\p",
|
||||
"..\\a\\p",
|
||||
"C:\\a\\p",
|
||||
"D:/p",
|
||||
{ repo: ".\\p" },
|
||||
]) {
|
||||
assert.ok(isLocalSource(source), JSON.stringify(source))
|
||||
}
|
||||
for (const source of ["github:a/b", "a/b", "https://github.com/a/b.git"]) {
|
||||
assert.ok(!isLocalSource(source), source)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { styleText } from "node:util"
|
||||
import { isIdentifier, jsString } from "./subprocess.js"
|
||||
|
||||
@@ -135,8 +136,8 @@ export function collectPluginExports({ pluginsDir, npmPackages = [], verbose = f
|
||||
for (const pkg of npmPackages) {
|
||||
let distIndex
|
||||
try {
|
||||
const pkgJson = new URL(import.meta.resolve(`${pkg}/package.json`)).pathname
|
||||
distIndex = path.join(path.dirname(decodeURIComponent(pkgJson)), "dist", "index.d.ts")
|
||||
const pkgJson = fileURLToPath(import.meta.resolve(`${pkg}/package.json`))
|
||||
distIndex = path.join(path.dirname(pkgJson), "dist", "index.d.ts")
|
||||
} catch {
|
||||
if (verbose) console.log(styleText("yellow", `⚠`), `Skipping npm package ${pkg}: not found`)
|
||||
continue
|
||||
|
||||
@@ -46,6 +46,20 @@ function fakeSite() {
|
||||
}
|
||||
|
||||
describe("plugin index", () => {
|
||||
// npm plugins are found through import.meta.resolve, which returns a file: URL. Its pathname
|
||||
// is not a path on Windows (`/C:/…`), so every npm plugin was skipped there (#2616).
|
||||
test("npm plugins are found through their package.json", () => {
|
||||
const pluginsDir = fs.mkdtempSync(path.join(os.tmpdir(), "quartz-plugin-index-npm-"))
|
||||
const entry = collectPluginExports({
|
||||
pluginsDir,
|
||||
npmPackages: ["@quartz-community/explorer"],
|
||||
}).get("quartz-community__explorer")
|
||||
assert.ok(entry, "@quartz-community/explorer was skipped")
|
||||
assert.ok(entry.overridable.includes("Explorer"))
|
||||
assert.strictEqual(entry.importPath, "@quartz-community/explorer")
|
||||
fs.rmSync(pluginsDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
test("component constructors re-exported from a sub-module are wrapped (#2565)", () => {
|
||||
const { root, pluginsDir } = fakeSite()
|
||||
const entry = collectPluginExports({ pluginsDir }).get("my-widget")!
|
||||
|
||||
@@ -4,7 +4,7 @@ import { unified } from "unified"
|
||||
import remarkParse from "remark-parse"
|
||||
import remarkRehype from "remark-rehype"
|
||||
import { VFile } from "vfile"
|
||||
import { Element, Root } from "hast"
|
||||
import { Element, Root, Text } from "hast"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { BUILTINS, instantiateBuiltins, officialPluginName, planBuiltins, PlanInput } from "."
|
||||
import {
|
||||
@@ -361,6 +361,52 @@ describe("links built-in", () => {
|
||||
assert.strictEqual(els[1].properties.src, "../../media/a.mp4")
|
||||
})
|
||||
|
||||
// Obsidian 1.15.0 (remark-obsidian 2.2.1's triage, re-probed): a path that is not valid
|
||||
// percent-encoding names no file, so the link is external; `x:y` has a scheme, `../x:y` doesn't
|
||||
test("links Obsidian reads as external", () => {
|
||||
const { els } = run([a("%zz"), a("a%E2.md"), a("x:y"), a("../x:y")], "sub/note", {}, ["xy"])
|
||||
const classes = els.filter((e) => e.tagName === "a").map((e) => e.properties.className)
|
||||
assert.deepStrictEqual(
|
||||
classes.map((c) => (c as string[])[0]),
|
||||
["external", "external", "external", "internal"],
|
||||
)
|
||||
})
|
||||
|
||||
test("an image of a missing file without alt text shows its decoded path", () => {
|
||||
const img = (src: string, alt?: string): Element => ({
|
||||
type: "element",
|
||||
tagName: "img",
|
||||
properties: alt === undefined ? { src } : { src, alt },
|
||||
children: [],
|
||||
})
|
||||
const { els } = run(
|
||||
[
|
||||
img("missing%20pic.png"),
|
||||
img("missing%20image.png", "alt"),
|
||||
img("pic.png"),
|
||||
img("/static/x.png"),
|
||||
],
|
||||
"page",
|
||||
{ markdownLinkResolution: "absolute" },
|
||||
["page", "pic.png"],
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
els.map((e) => e.properties.alt),
|
||||
["missing pic.png", "alt", undefined, undefined],
|
||||
)
|
||||
})
|
||||
|
||||
test("pretty links keep the last /-separated part of the link text, on every OS", () => {
|
||||
const { els } = run([a("folder/note"), a("a\\b")], "page", { prettyLinks: true }, [
|
||||
"folder/note",
|
||||
"a\\b",
|
||||
])
|
||||
assert.deepStrictEqual(
|
||||
els.filter((e) => e.tagName === "a").map((e) => (e.children[0] as Text).value),
|
||||
["note", "a\\b"],
|
||||
)
|
||||
})
|
||||
|
||||
test("disableBrokenWikilinks adds a broken class to missing targets", () => {
|
||||
const { els } = run([a("missing")], "page", { disableBrokenWikilinks: true }, ["page"])
|
||||
assert.ok((els[0].properties.className as string[]).includes("broken"))
|
||||
|
||||
@@ -8,6 +8,7 @@ import { LinksConfig } from "../../cfg"
|
||||
import {
|
||||
FullSlug,
|
||||
RelativeURL,
|
||||
linkPathDecodes,
|
||||
SimpleSlug,
|
||||
TransformOptions,
|
||||
resolveRelative,
|
||||
@@ -46,7 +47,9 @@ export const legacyCrawlLinksDefaults: Partial<LinksConfig> = {
|
||||
}
|
||||
|
||||
const isAbsolute = isAbsoluteUrl as (url: string, options?: { httpOnly?: boolean }) => boolean
|
||||
const isExternalUrl = (url: string) => isAbsolute(url, { httpOnly: false })
|
||||
// As in Obsidian: a URL with a scheme (`x:y`, but not `../x:y`), or a link whose path is not valid
|
||||
// percent-encoding (`%zz`, `a%E2.md`), which names no file
|
||||
const isExternalUrl = (url: string) => isAbsolute(url, { httpOnly: false }) || !linkPathDecodes(url)
|
||||
|
||||
const EXTERNAL_ICON_PATH =
|
||||
"M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"
|
||||
@@ -163,7 +166,8 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
|
||||
!textChild.value.startsWith("#") &&
|
||||
!classes.includes("alias")
|
||||
) {
|
||||
textChild.value = path.basename(textChild.value)
|
||||
// link text is not an OS path: path.posix, or Windows would also cut at a backslash
|
||||
textChild.value = path.posix.basename(textChild.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,8 +179,20 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
|
||||
typeof node.properties.src === "string"
|
||||
) {
|
||||
if (opts.lazyLoad) node.properties.loading = "lazy"
|
||||
if (!isExternalUrl(node.properties.src)) {
|
||||
node.properties.src = resolveLink(node.properties.src as RelativeURL)
|
||||
const src = node.properties.src
|
||||
if (!isExternalUrl(src)) {
|
||||
node.properties.src = resolveLink(src as RelativeURL)
|
||||
// An embed of a file the site doesn't have: Obsidian shows its path, percent-decoded
|
||||
// (`` → “missing pic.png”). The image shows its alt text, so
|
||||
// an image without one gets the path; an author's alt text is kept.
|
||||
const target =
|
||||
node.tagName === "img" && !node.properties.alt && !src.startsWith("#")
|
||||
? canonicalSlug(node.properties.src as string, curSlug)
|
||||
: undefined
|
||||
// (quartz/static is served at static/ but holds no content files)
|
||||
if (target && !target.startsWith("static/") && !ctx.allSlugs.includes(target)) {
|
||||
node.properties.alt = decodeURI(splitAnchor(src)[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from "node:assert"
|
||||
import fs from "fs"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { parsePluginSource, readLockedCommit } from "./gitLoader"
|
||||
import { isLocalSource, parsePluginSource, readLockedCommit } from "./gitLoader"
|
||||
|
||||
describe("parsePluginSource", () => {
|
||||
test("owner/repo shorthand supports #ref", () => {
|
||||
@@ -13,6 +13,25 @@ describe("parsePluginSource", () => {
|
||||
assert.strictEqual(spec.ref, "dev")
|
||||
})
|
||||
|
||||
test("local sources are recognised in POSIX and Windows spellings", () => {
|
||||
for (const source of [
|
||||
"./plugin",
|
||||
"../plugin",
|
||||
"/abs/plugin",
|
||||
".\\plugin",
|
||||
"..\\plugins\\x",
|
||||
"C:\\sites\\plugin",
|
||||
"D:/plugin",
|
||||
{ repo: ".\\plugin" },
|
||||
]) {
|
||||
assert.ok(isLocalSource(source), JSON.stringify(source))
|
||||
}
|
||||
for (const source of ["github:a/b", "a/b", "https://github.com/a/b.git", "@scope/pkg"]) {
|
||||
assert.ok(!isLocalSource(source), source)
|
||||
}
|
||||
assert.strictEqual(parsePluginSource(".\\plugin").local, true)
|
||||
})
|
||||
|
||||
test("unknown sources get an explanatory error", () => {
|
||||
assert.throws(() => parsePluginSource("explorer"), /Expected github:owner\/repo/)
|
||||
})
|
||||
|
||||
@@ -111,6 +111,10 @@ export function isLocalSource(source: PluginSource): boolean {
|
||||
if (source.startsWith("./") || source.startsWith("../") || source.startsWith("/")) {
|
||||
return true
|
||||
}
|
||||
// Windows relative paths (.\plugin, ..\plugin)
|
||||
if (source.startsWith(".\\") || source.startsWith("..\\")) {
|
||||
return true
|
||||
}
|
||||
// Windows absolute paths (e.g. C:\ or D:/)
|
||||
if (/^[A-Za-z]:[\\/]/.test(source)) {
|
||||
return true
|
||||
|
||||
@@ -20,6 +20,7 @@ export {
|
||||
splitAnchor,
|
||||
slugTag,
|
||||
transformInternalLink,
|
||||
linkPathDecodes,
|
||||
transformLink,
|
||||
normalizeHastElement,
|
||||
} from "@quartz-community/utils"
|
||||
|
||||
Reference in new issue
Block a user