mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 14:34:23 +02:00
Compare commits
3 Commits
feca7844d1
...
691fd035e7
Author | SHA1 | Date | |
---|---|---|---|
![]() |
691fd035e7 | ||
![]() |
7be47742a6 | ||
![]() |
c45dca07f7 |
27
package-lock.json
generated
27
package-lock.json
generated
@ -34,7 +34,7 @@
|
|||||||
"mdast-util-to-hast": "^13.2.0",
|
"mdast-util-to-hast": "^13.2.0",
|
||||||
"mdast-util-to-string": "^4.0.0",
|
"mdast-util-to-string": "^4.0.0",
|
||||||
"micromorph": "^0.4.5",
|
"micromorph": "^0.4.5",
|
||||||
"pixi.js": "^8.6.6",
|
"pixi.js": "^8.7.3",
|
||||||
"preact": "^10.25.4",
|
"preact": "^10.25.4",
|
||||||
"preact-render-to-string": "^6.5.13",
|
"preact-render-to-string": "^6.5.13",
|
||||||
"pretty-bytes": "^6.1.1",
|
"pretty-bytes": "^6.1.1",
|
||||||
@ -79,10 +79,10 @@
|
|||||||
"@types/d3": "^7.4.3",
|
"@types/d3": "^7.4.3",
|
||||||
"@types/hast": "^3.0.4",
|
"@types/hast": "^3.0.4",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^22.10.6",
|
"@types/node": "^22.12.0",
|
||||||
"@types/pretty-time": "^1.1.5",
|
"@types/pretty-time": "^1.1.5",
|
||||||
"@types/source-map-support": "^0.5.10",
|
"@types/source-map-support": "^0.5.10",
|
||||||
"@types/ws": "^8.5.13",
|
"@types/ws": "^8.5.14",
|
||||||
"@types/yargs": "^17.0.33",
|
"@types/yargs": "^17.0.33",
|
||||||
"esbuild": "^0.24.2",
|
"esbuild": "^0.24.2",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
@ -1914,10 +1914,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.10.6",
|
"version": "22.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.12.0.tgz",
|
||||||
"integrity": "sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==",
|
"integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.20.0"
|
"undici-types": "~6.20.0"
|
||||||
}
|
}
|
||||||
@ -1943,10 +1944,11 @@
|
|||||||
"integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ=="
|
"integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ=="
|
||||||
},
|
},
|
||||||
"node_modules/@types/ws": {
|
"node_modules/@types/ws": {
|
||||||
"version": "8.5.13",
|
"version": "8.5.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz",
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.14.tgz",
|
||||||
"integrity": "sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==",
|
"integrity": "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
@ -5583,9 +5585,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pixi.js": {
|
"node_modules/pixi.js": {
|
||||||
"version": "8.6.6",
|
"version": "8.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/pixi.js/-/pixi.js-8.6.6.tgz",
|
"resolved": "https://registry.npmjs.org/pixi.js/-/pixi.js-8.7.3.tgz",
|
||||||
"integrity": "sha512-o5pw7G2yuIrnBx0G4npBlmFp+XGNcapI/Ufs62rRj/4XKxc1Zo74YJr/BtEXcXTraTKd+pQvYOLvnfxRjxBMvQ==",
|
"integrity": "sha512-wfWlhJYnGx1s4f2yoouevQjaeacbJ12LTkJGa+n9AIYNIjOnmJylBtZ2mARX7iFk3mr2xv0wuo//XPe2hk5OBw==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pixi/colord": "^2.9.6",
|
"@pixi/colord": "^2.9.6",
|
||||||
"@types/css-font-loading-module": "^0.0.12",
|
"@types/css-font-loading-module": "^0.0.12",
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
"mdast-util-to-hast": "^13.2.0",
|
"mdast-util-to-hast": "^13.2.0",
|
||||||
"mdast-util-to-string": "^4.0.0",
|
"mdast-util-to-string": "^4.0.0",
|
||||||
"micromorph": "^0.4.5",
|
"micromorph": "^0.4.5",
|
||||||
"pixi.js": "^8.6.6",
|
"pixi.js": "^8.7.3",
|
||||||
"preact": "^10.25.4",
|
"preact": "^10.25.4",
|
||||||
"preact-render-to-string": "^6.5.13",
|
"preact-render-to-string": "^6.5.13",
|
||||||
"pretty-bytes": "^6.1.1",
|
"pretty-bytes": "^6.1.1",
|
||||||
@ -102,10 +102,10 @@
|
|||||||
"@types/d3": "^7.4.3",
|
"@types/d3": "^7.4.3",
|
||||||
"@types/hast": "^3.0.4",
|
"@types/hast": "^3.0.4",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^22.10.6",
|
"@types/node": "^22.12.0",
|
||||||
"@types/pretty-time": "^1.1.5",
|
"@types/pretty-time": "^1.1.5",
|
||||||
"@types/source-map-support": "^0.5.10",
|
"@types/source-map-support": "^0.5.10",
|
||||||
"@types/ws": "^8.5.13",
|
"@types/ws": "^8.5.14",
|
||||||
"@types/yargs": "^17.0.33",
|
"@types/yargs": "^17.0.33",
|
||||||
"esbuild": "^0.24.2",
|
"esbuild": "^0.24.2",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { FilePath, FullSlug, joinSegments, resolveRelative, simplifySlug } from "../../util/path"
|
import { FilePath, joinSegments, resolveRelative, simplifySlug } from "../../util/path"
|
||||||
import { QuartzEmitterPlugin } from "../types"
|
import { QuartzEmitterPlugin } from "../types"
|
||||||
import path from "path"
|
|
||||||
import { write } from "./helpers"
|
import { write } from "./helpers"
|
||||||
import DepGraph from "../../depgraph"
|
import DepGraph from "../../depgraph"
|
||||||
|
import { getAliasSlugs } from "../transformers/frontmatter"
|
||||||
|
|
||||||
export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
||||||
name: "AliasRedirects",
|
name: "AliasRedirects",
|
||||||
@ -14,20 +14,7 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
|||||||
|
|
||||||
const { argv } = ctx
|
const { argv } = ctx
|
||||||
for (const [_tree, file] of content) {
|
for (const [_tree, file] of content) {
|
||||||
const dir = path.posix.relative(argv.directory, path.dirname(file.data.filePath!))
|
for (const slug of getAliasSlugs(file.data.frontmatter?.aliases ?? [], argv, file)) {
|
||||||
const aliases = file.data.frontmatter?.aliases ?? []
|
|
||||||
const slugs = aliases.map((alias) => path.posix.join(dir, alias) as FullSlug)
|
|
||||||
const permalink = file.data.frontmatter?.permalink
|
|
||||||
if (typeof permalink === "string") {
|
|
||||||
slugs.push(permalink as FullSlug)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let slug of slugs) {
|
|
||||||
// fix any slugs that have trailing slash
|
|
||||||
if (slug.endsWith("/")) {
|
|
||||||
slug = joinSegments(slug, "index") as FullSlug
|
|
||||||
}
|
|
||||||
|
|
||||||
graph.addEdge(file.data.filePath!, joinSegments(argv.output, slug + ".html") as FilePath)
|
graph.addEdge(file.data.filePath!, joinSegments(argv.output, slug + ".html") as FilePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,20 +27,8 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
|||||||
|
|
||||||
for (const [_tree, file] of content) {
|
for (const [_tree, file] of content) {
|
||||||
const ogSlug = simplifySlug(file.data.slug!)
|
const ogSlug = simplifySlug(file.data.slug!)
|
||||||
const dir = path.posix.relative(argv.directory, path.dirname(file.data.filePath!))
|
|
||||||
const aliases = file.data.frontmatter?.aliases ?? []
|
|
||||||
const slugs: FullSlug[] = aliases.map((alias) => path.posix.join(dir, alias) as FullSlug)
|
|
||||||
const permalink = file.data.frontmatter?.permalink
|
|
||||||
if (typeof permalink === "string") {
|
|
||||||
slugs.push(permalink as FullSlug)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let slug of slugs) {
|
|
||||||
// fix any slugs that have trailing slash
|
|
||||||
if (slug.endsWith("/")) {
|
|
||||||
slug = joinSegments(slug, "index") as FullSlug
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (const slug of file.data.aliases ?? []) {
|
||||||
const redirUrl = resolveRelative(slug, file.data.slug!)
|
const redirUrl = resolveRelative(slug, file.data.slug!)
|
||||||
const fp = await write({
|
const fp = await write({
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -3,9 +3,12 @@ import remarkFrontmatter from "remark-frontmatter"
|
|||||||
import { QuartzTransformerPlugin } from "../types"
|
import { QuartzTransformerPlugin } from "../types"
|
||||||
import yaml from "js-yaml"
|
import yaml from "js-yaml"
|
||||||
import toml from "toml"
|
import toml from "toml"
|
||||||
import { slugTag } from "../../util/path"
|
import { FilePath, FullSlug, joinSegments, slugifyFilePath, slugTag } from "../../util/path"
|
||||||
import { QuartzPluginData } from "../vfile"
|
import { QuartzPluginData } from "../vfile"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
|
import { Argv } from "../../util/ctx"
|
||||||
|
import { VFile } from "vfile"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
delimiters: string | [string, string]
|
delimiters: string | [string, string]
|
||||||
@ -40,11 +43,26 @@ function coerceToArray(input: string | string[]): string[] | undefined {
|
|||||||
.map((tag: string | number) => tag.toString())
|
.map((tag: string | number) => tag.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAliasSlugs(aliases: string[], argv: Argv, file: VFile): FullSlug[] {
|
||||||
|
const dir = path.posix.relative(argv.directory, path.dirname(file.data.filePath!))
|
||||||
|
const slugs: FullSlug[] = aliases.map(
|
||||||
|
(alias) => path.posix.join(dir, slugifyFilePath(alias as FilePath)) as FullSlug,
|
||||||
|
)
|
||||||
|
const permalink = file.data.frontmatter?.permalink
|
||||||
|
if (typeof permalink === "string") {
|
||||||
|
slugs.push(permalink as FullSlug)
|
||||||
|
}
|
||||||
|
// fix any slugs that have trailing slash
|
||||||
|
return slugs.map((slug) =>
|
||||||
|
slug.endsWith("/") ? (joinSegments(slug, "index") as FullSlug) : slug,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||||
const opts = { ...defaultOptions, ...userOpts }
|
const opts = { ...defaultOptions, ...userOpts }
|
||||||
return {
|
return {
|
||||||
name: "FrontMatter",
|
name: "FrontMatter",
|
||||||
markdownPlugins({ cfg }) {
|
markdownPlugins({ cfg, allSlugs, argv }) {
|
||||||
return [
|
return [
|
||||||
[remarkFrontmatter, ["yaml", "toml"]],
|
[remarkFrontmatter, ["yaml", "toml"]],
|
||||||
() => {
|
() => {
|
||||||
@ -67,7 +85,11 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
|||||||
if (tags) data.tags = [...new Set(tags.map((tag: string) => slugTag(tag)))]
|
if (tags) data.tags = [...new Set(tags.map((tag: string) => slugTag(tag)))]
|
||||||
|
|
||||||
const aliases = coerceToArray(coalesceAliases(data, ["aliases", "alias"]))
|
const aliases = coerceToArray(coalesceAliases(data, ["aliases", "alias"]))
|
||||||
if (aliases) data.aliases = aliases
|
if (aliases) {
|
||||||
|
data.aliases = aliases // frontmatter
|
||||||
|
const slugs = (file.data.aliases = getAliasSlugs(aliases, argv, file))
|
||||||
|
allSlugs.push(...slugs)
|
||||||
|
}
|
||||||
const cssclasses = coerceToArray(coalesceAliases(data, ["cssclasses", "cssclass"]))
|
const cssclasses = coerceToArray(coalesceAliases(data, ["cssclasses", "cssclass"]))
|
||||||
if (cssclasses) data.cssclasses = cssclasses
|
if (cssclasses) data.cssclasses = cssclasses
|
||||||
|
|
||||||
@ -98,6 +120,7 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
|||||||
|
|
||||||
declare module "vfile" {
|
declare module "vfile" {
|
||||||
interface DataMap {
|
interface DataMap {
|
||||||
|
aliases: FullSlug[]
|
||||||
frontmatter: { [key: string]: unknown } & {
|
frontmatter: { [key: string]: unknown } & {
|
||||||
title: string
|
title: string
|
||||||
} & Partial<{
|
} & Partial<{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user