Skip to content

Commit

Permalink
merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xy-241 committed Dec 27, 2024
2 parents a701dd5 + c91cf97 commit e61b06c
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 201 deletions.
1 change: 1 addition & 0 deletions docs/features/backlinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A backlink for a note is a link from another note to that note. Links in the bac
## Customization

- Removing backlinks: delete all usages of `Component.Backlinks()` from `quartz.layout.ts`.
- Hide when empty: hide `Backlinks` if given page doesn't contain any backlinks (default to `true`). To disable this, use `Component.Backlinks({ hideWhenEmpty: false })`.
- Component: `quartz/components/Backlinks.tsx`
- Style: `quartz/components/styles/backlinks.scss`
- Script: `quartz/components/scripts/search.inline.ts`
346 changes: 181 additions & 165 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"quartz": "./quartz/bootstrap-cli.mjs"
},
"dependencies": {
"@clack/prompts": "^0.8.2",
"@clack/prompts": "^0.9.0",
"@floating-ui/dom": "^1.6.12",
"@myriaddreamin/rehype-typst": "^0.5.0-rc9",
"@napi-rs/simple-git": "0.1.19",
"@tweenjs/tween.js": "^25.0.0",
"async-mutex": "^0.5.0",
"chalk": "^5.3.0",
"chokidar": "^4.0.2",
"chalk": "^5.4.1",
"chokidar": "^4.0.3",
"cli-spinner": "^0.2.10",
"d3": "^7.9.0",
"esbuild-sass-plugin": "^3.3.1",
Expand All @@ -61,8 +61,8 @@
"mdast-util-to-string": "^4.0.0",
"mermaid": "^11.4.1",
"micromorph": "^0.4.5",
"pixi.js": "^8.6.5",
"preact": "^10.25.2",
"pixi.js": "^8.6.6",
"preact": "^10.25.3",
"preact-render-to-string": "^6.5.12",
"pretty-bytes": "^6.1.1",
"pretty-time": "^1.1.0",
Expand All @@ -87,7 +87,7 @@
"satori": "^0.12.0",
"serve-handler": "^6.1.6",
"sharp": "^0.33.5",
"shiki": "^1.24.2",
"shiki": "^1.24.4",
"source-map-support": "^0.5.21",
"to-vfile": "^8.0.0",
"toml": "^3.0.0",
Expand All @@ -108,7 +108,7 @@
"@types/source-map-support": "^0.5.10",
"@types/ws": "^8.5.13",
"@types/yargs": "^17.0.33",
"esbuild": "^0.24.0",
"esbuild": "^0.24.2",
"prettier": "^3.4.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
Expand Down
72 changes: 44 additions & 28 deletions quartz/components/Backlinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,49 @@ import { resolveRelative, simplifySlug } from "../util/path"
import { i18n } from "../i18n"
import { classNames } from "../util/lang"

const Backlinks: QuartzComponent = ({
fileData,
allFiles,
displayClass,
cfg,
}: QuartzComponentProps) => {
const slug = simplifySlug(fileData.slug!)
const backlinkFiles = allFiles.filter((file) => file.links?.includes(slug))
return (
<div class={classNames(displayClass, "backlinks")}>
<h3>{i18n(cfg.locale).components.backlinks.title}</h3>
<ul class="overflow">
{backlinkFiles.length > 0 ? (
backlinkFiles.map((f) => (
<li>
<a href={resolveRelative(fileData.slug!, f.slug!)} class="internal">
{f.frontmatter?.title}
</a>
</li>
))
) : (
<li>{i18n(cfg.locale).components.backlinks.noBacklinksFound}</li>
)}
</ul>
</div>
)
interface BacklinksOptions {
hideWhenEmpty: boolean
}

Backlinks.css = style
export default (() => Backlinks) satisfies QuartzComponentConstructor
const defaultOptions: BacklinksOptions = {
hideWhenEmpty: true,
}

export default ((opts?: Partial<BacklinksOptions>) => {
const options: BacklinksOptions = { ...defaultOptions, ...opts }

const Backlinks: QuartzComponent = ({
fileData,
allFiles,
displayClass,
cfg,
}: QuartzComponentProps) => {
const slug = simplifySlug(fileData.slug!)
const backlinkFiles = allFiles.filter((file) => file.links?.includes(slug))
if (options.hideWhenEmpty && backlinkFiles.length == 0) {
return null
}
return (
<div class={classNames(displayClass, "backlinks")}>
<h3>{i18n(cfg.locale).components.backlinks.title}</h3>
<ul class="overflow">
{backlinkFiles.length > 0 ? (
backlinkFiles.map((f) => (
<li>
<a href={resolveRelative(fileData.slug!, f.slug!)} class="internal">
{f.frontmatter?.title}
</a>
</li>
))
) : (
<li>{i18n(cfg.locale).components.backlinks.noBacklinksFound}</li>
)}
</ul>
</div>
)
}

Backlinks.css = style

return Backlinks
}) satisfies QuartzComponentConstructor
2 changes: 1 addition & 1 deletion quartz/components/pages/TagContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default ((opts?: Partial<TagContentOptions>) => {

return (
<div class={classes}>
<article>{content}</article>
<article class="popover-hint">{content}</article>
<div class="page-listing">
<p>{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}</p>
<div>
Expand Down
15 changes: 15 additions & 0 deletions quartz/components/scripts/spa.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,22 @@ function notifyNav(url: FullSlug) {
const cleanupFns: Set<(...args: any[]) => void> = new Set()
window.addCleanup = (fn) => cleanupFns.add(fn)

function startLoading() {
const loadingBar = document.createElement("div")
loadingBar.className = "navigation-progress"
loadingBar.style.width = "0"
if (!document.body.contains(loadingBar)) {
document.body.appendChild(loadingBar)
}

setTimeout(() => {
loadingBar.style.width = "80%"
}, 100)
}

let p: DOMParser
async function navigate(url: URL, isBack: boolean = false) {
startLoading()
p = p || new DOMParser()
const contents = await fetch(`${url}`)
.then((res) => {
Expand Down Expand Up @@ -104,6 +118,7 @@ async function navigate(url: URL, isBack: boolean = false) {
if (!isBack) {
history.pushState({}, "", url)
}

notifyNav(getFullSlug(window))
delete announcer.dataset.persist
}
Expand Down
3 changes: 3 additions & 0 deletions quartz/plugins/emitters/tagPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
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}`
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions quartz/plugins/transformers/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)

const socialImage = coalesceAliases(data, ["socialImage", "image", "cover"])

const created = coalesceAliases(data, ["created", "date"])
if (created) data.created = created
const modified = coalesceAliases(data, [
"modified",
"lastmod",
"updated",
"last-modified",
])
if (modified) data.modified = modified
const published = coalesceAliases(data, ["published", "publishDate", "date"])
if (published) data.published = published

if (socialImage) data.socialImage = socialImage

// fill in frontmatter
Expand All @@ -91,6 +103,9 @@ declare module "vfile" {
} & Partial<{
tags: string[]
aliases: string[]
modified: string
created: string
published: string
description: string
publish: boolean | string
draft: boolean | string
Expand Down
11 changes: 11 additions & 0 deletions quartz/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,14 @@ iframe.pdf {
width: 100%;
border-radius: 5px;
}

.navigation-progress {
position: fixed;
top: 0;
left: 0;
width: 0;
height: 3px;
background: var(--secondary);
transition: width 0.2s ease;
z-index: 9999;
}

0 comments on commit e61b06c

Please sign in to comment.