mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-19 06:54:18 +02:00
Compare commits
3 Commits
14ab357637
...
4d86830d92
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4d86830d92 | ||
![]() |
32ec711767 | ||
![]() |
39ff322777 |
8
package-lock.json
generated
8
package-lock.json
generated
@ -79,7 +79,7 @@
|
||||
"@types/d3": "^7.4.3",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^22.12.0",
|
||||
"@types/node": "^22.13.0",
|
||||
"@types/pretty-time": "^1.1.5",
|
||||
"@types/source-map-support": "^0.5.10",
|
||||
"@types/ws": "^8.5.14",
|
||||
@ -1914,9 +1914,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.12.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.12.0.tgz",
|
||||
"integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==",
|
||||
"version": "22.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.0.tgz",
|
||||
"integrity": "sha512-ClIbNe36lawluuvq3+YYhnIN2CELi+6q8NpnM7PYp4hBn/TatfboPgVSm2rwKRfnV2M+Ty9GWDFI64KEe+kysA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -102,7 +102,7 @@
|
||||
"@types/d3": "^7.4.3",
|
||||
"@types/hast": "^3.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^22.12.0",
|
||||
"@types/node": "^22.13.0",
|
||||
"@types/pretty-time": "^1.1.5",
|
||||
"@types/source-map-support": "^0.5.10",
|
||||
"@types/ws": "^8.5.14",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FullSlug, resolveRelative } from "../util/path"
|
||||
import { FullSlug, resolveRelative, slugTag } from "../util/path"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { Date, getDate } from "./Date"
|
||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||
@ -61,7 +61,7 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
|
||||
<li>
|
||||
<a
|
||||
class="internal tag-link"
|
||||
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
|
||||
href={resolveRelative(fileData.slug!, `tags/${slugTag(tag)}` as FullSlug)}
|
||||
>
|
||||
{tag}
|
||||
</a>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { FullSlug, SimpleSlug, resolveRelative } from "../util/path"
|
||||
import { FullSlug, SimpleSlug, resolveRelative, slugTag } from "../util/path"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { byDateAndAlphabetical } from "./PageList"
|
||||
import style from "./styles/recentNotes.scss"
|
||||
@ -64,7 +64,10 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
<li>
|
||||
<a
|
||||
class="internal tag-link"
|
||||
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
|
||||
href={resolveRelative(
|
||||
fileData.slug!,
|
||||
`tags/${slugTag(tag)}` as FullSlug,
|
||||
)}
|
||||
>
|
||||
{tag}
|
||||
</a>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||
import style from "../styles/listPage.scss"
|
||||
import { PageList, SortFn } from "../PageList"
|
||||
import { FullSlug, getAllSegmentPrefixes, simplifySlug } from "../../util/path"
|
||||
import { FullSlug, getAllSegmentPrefixes, simplifySlug, slugTag } from "../../util/path"
|
||||
import { QuartzPluginData } from "../../plugins/vfile"
|
||||
import { Root } from "hast"
|
||||
import { htmlToJsx } from "../../util/jsx"
|
||||
@ -63,7 +63,8 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
allFiles: pages,
|
||||
}
|
||||
|
||||
const contentPage = allFiles.filter((file) => file.slug === `tags/${tag}`).at(0)
|
||||
const tagSlug = slugTag(tag)
|
||||
const contentPage = allFiles.filter((file) => file.slug === `tags/${tagSlug}`).at(0)
|
||||
|
||||
const root = contentPage?.htmlAst
|
||||
const content =
|
||||
@ -74,7 +75,7 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
return (
|
||||
<div>
|
||||
<h2>
|
||||
<a class="internal tag-link" href={`../tags/${tag}`}>
|
||||
<a class="internal tag-link" href={`../tags/${tagSlug}`}>
|
||||
{tag}
|
||||
</a>
|
||||
</h2>
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
getAllSegmentPrefixes,
|
||||
joinSegments,
|
||||
pathToRoot,
|
||||
slugTag,
|
||||
} from "../../util/path"
|
||||
import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout"
|
||||
import { TagContent } from "../../components"
|
||||
@ -64,7 +65,7 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
for (const tag of tags) {
|
||||
graph.addEdge(
|
||||
sourcePath,
|
||||
joinSegments(ctx.argv.output, "tags", tag + ".html") as FilePath,
|
||||
joinSegments(ctx.argv.output, "tags", slugTag(tag) + ".html") as FilePath,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -80,42 +81,56 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes),
|
||||
)
|
||||
|
||||
// add base tag
|
||||
tags.add("index")
|
||||
|
||||
const tagDescriptions: Record<string, ProcessedContent> = Object.fromEntries(
|
||||
const tagDescriptions: Map<FullSlug, { tag: string; content: ProcessedContent }> = new Map(
|
||||
[...tags].map((tag) => {
|
||||
const title =
|
||||
tag === "index"
|
||||
? i18n(cfg.locale).pages.tagContent.tagIndex
|
||||
: `${i18n(cfg.locale).pages.tagContent.tag}: ${tag}`
|
||||
return [
|
||||
tag,
|
||||
defaultProcessedContent({
|
||||
slug: joinSegments("tags", tag) as FullSlug,
|
||||
frontmatter: { title, tags: [] },
|
||||
}),
|
||||
]
|
||||
const title = `${i18n(cfg.locale).pages.tagContent.tag}: ${tag}`
|
||||
const slug = joinSegments("tags", slugTag(tag)) as FullSlug
|
||||
const content = defaultProcessedContent({ slug, frontmatter: { title } })
|
||||
return [slug, { tag, content }]
|
||||
}),
|
||||
)
|
||||
|
||||
// add base tag
|
||||
tagDescriptions.set("tags/index" as FullSlug, {
|
||||
tag: "index",
|
||||
content: defaultProcessedContent({
|
||||
slug: "tags/index" as FullSlug,
|
||||
frontmatter: {
|
||||
title: i18n(cfg.locale).pages.tagContent.tagIndex,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
let tagFolder: string | undefined
|
||||
|
||||
for (const [tree, file] of content) {
|
||||
const slug = file.data.slug!
|
||||
if (slug.startsWith("tags/")) {
|
||||
const tag = slug.slice("tags/".length)
|
||||
if (tags.has(tag)) {
|
||||
tagDescriptions[tag] = [tree, file]
|
||||
if (file.data.frontmatter?.title === tag) {
|
||||
file.data.frontmatter.title = `${i18n(cfg.locale).pages.tagContent.tag}: ${tag}`
|
||||
}
|
||||
}
|
||||
if (!slug.startsWith("tags/")) {
|
||||
continue
|
||||
}
|
||||
const desc = tagDescriptions.get(slug)
|
||||
if (!desc) {
|
||||
continue
|
||||
}
|
||||
desc.content = [tree, file]
|
||||
if (file.data.frontmatter?.title === desc.tag) {
|
||||
file.data.frontmatter.title = `${i18n(cfg.locale).pages.tagContent.tag}: ${desc.tag}`
|
||||
}
|
||||
if (!tagFolder && file.data.relativePath) {
|
||||
tagFolder = file.data.relativePath.split("/").at(0)
|
||||
}
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
const slug = joinSegments("tags", tag) as FullSlug
|
||||
const [tree, file] = tagDescriptions[tag]
|
||||
const externalResources = pageResources(pathToRoot(slug), file.data, resources)
|
||||
// this is a hack to make sure our virtual `tags/index` page has the same folder as the other tag pages
|
||||
// so that the breadcrumbs render consistent capitalization etc
|
||||
if (tagFolder) {
|
||||
const path = `${tagFolder}/index.html` as FilePath
|
||||
tagDescriptions.get("tags/index" as FullSlug)!.content[1].data.relativePath = path
|
||||
}
|
||||
|
||||
for (const [slug, desc] of tagDescriptions.entries()) {
|
||||
const [tree, file] = desc.content
|
||||
const externalResources = pageResources(pathToRoot(slug as FullSlug), file.data, resources)
|
||||
const componentData: QuartzComponentProps = {
|
||||
ctx,
|
||||
fileData: file.data,
|
||||
|
@ -337,7 +337,6 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
return false
|
||||
}
|
||||
|
||||
tag = slugTag(tag)
|
||||
if (file.data.frontmatter) {
|
||||
const noteTags = file.data.frontmatter.tags ?? []
|
||||
file.data.frontmatter.tags = [...new Set([...noteTags, tag])]
|
||||
@ -345,7 +344,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
|
||||
return {
|
||||
type: "link",
|
||||
url: base + `/tags/${tag}`,
|
||||
url: `${base}/tags/${slugTag(tag)}`,
|
||||
data: {
|
||||
hProperties: {
|
||||
className: ["tag-link"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user