Skip to content

Commit e10a4f8

Browse files
committed
Merge branch 'v4' of github.com:jackyzha0/quartz into v4
2 parents 3e7c3c9 + 2a9290b commit e10a4f8

File tree

163 files changed

+12634
-4229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+12634
-4229
lines changed

.github/dependabot.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# To get started with Dependabot version updates, you'll need to specify which
2-
# package ecosystems to update and where the package manifests are located.
3-
# Please see the documentation for all configuration options:
4-
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5-
61
version: 2
72
updates:
83
- package-ecosystem: "npm"
94
directory: "/"
105
schedule:
116
interval: "weekly"
7+
groups:
8+
production-dependencies:
9+
applies-to: "version-updates"
10+
patterns:
11+
- "*"
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
groups:
17+
ci-dependencies:
18+
applies-to: "version-updates"
19+
patterns:
20+
- "*"

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: npm test
4646

4747
- name: Ensure Quartz builds, check bundle info
48-
run: npx quartz build --bundleInfo
48+
run: npx quartz build --bundleInfo -d docs
4949

5050
publish-tag:
5151
if: ${{ github.repository == 'jackyzha0/quartz' && github.ref == 'refs/heads/v4' }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Docker build & push image
2+
3+
on:
4+
push:
5+
branches: [v4]
6+
tags: ["v*"]
7+
pull_request:
8+
branches: [v4]
9+
paths:
10+
- .github/workflows/docker-build-push.yaml
11+
- quartz/**
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
if: ${{ github.repository == 'jackyzha0/quartz' }} # Comment this out if you want to publish your own images on a fork!
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set lowercase repository owner environment variable
20+
run: |
21+
echo "OWNER_LOWERCASE=${OWNER,,}" >> ${GITHUB_ENV}
22+
env:
23+
OWNER: "${{ github.repository_owner }}"
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 1
27+
- name: Inject slug/short variables
28+
uses: rlespinasse/[email protected]
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
with:
34+
install: true
35+
driver-opts: |
36+
image=moby/buildkit:master
37+
network=host
38+
- name: Install cosign
39+
if: github.event_name != 'pull_request'
40+
uses: sigstore/[email protected]
41+
- name: Login to GitHub Container Registry
42+
uses: docker/login-action@v3
43+
if: github.event_name != 'pull_request'
44+
with:
45+
registry: ghcr.io
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Extract metadata tags and labels on PRs
50+
if: github.event_name == 'pull_request'
51+
id: meta-pr
52+
uses: docker/metadata-action@v5
53+
with:
54+
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz
55+
tags: |
56+
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
57+
labels: |
58+
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz"
59+
- name: Extract metadata tags and labels for main, release or tag
60+
if: github.event_name != 'pull_request'
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
flavor: |
65+
latest=auto
66+
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz
67+
tags: |
68+
type=semver,pattern={{version}}
69+
type=semver,pattern={{major}}.{{minor}}
70+
type=semver,pattern={{major}}.{{minor}}.{{patch}}
71+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
72+
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
73+
labels: |
74+
maintainer=${{ github.repository_owner }}
75+
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz"
76+
77+
- name: Build and push Docker image
78+
id: build-and-push
79+
uses: docker/build-push-action@v6
80+
with:
81+
push: ${{ github.event_name != 'pull_request' }}
82+
build-args: |
83+
GIT_SHA=${{ env.GITHUB_SHA }}
84+
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
85+
tags: ${{ steps.meta.outputs.tags || steps.meta-pr.outputs.tags }}
86+
labels: ${{ steps.meta.outputs.labels || steps.meta-pr.outputs.labels }}
87+
cache-from: type=gha
88+
cache-to: type=gha

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM node:20-slim as builder
1+
FROM node:22-slim AS builder
22
WORKDIR /usr/src/app
33
COPY package.json .
44
COPY package-lock.json* .
55
RUN npm ci
66

7-
FROM node:20-slim
7+
FROM node:22-slim
88
WORKDIR /usr/src/app
99
COPY --from=builder /usr/src/app/ /usr/src/app/
1010
COPY . .

docs/advanced/creating components.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ document.addEventListener("nav", () => {
161161
})
162162
```
163163

164+
You can also add the equivalent of a `beforeunload` event for [[SPA Routing]] via the `prenav` event.
165+
166+
```ts
167+
document.addEventListener("prenav", () => {
168+
// executed after an SPA navigation is triggered but
169+
// before the page is replaced
170+
// one usage pattern is to store things in sessionStorage
171+
// in the prenav and then conditionally load then in the consequent
172+
// nav
173+
})
174+
```
175+
164176
It is best practice to track any event handlers via `window.addCleanup` to prevent memory leaks.
165177
This will get called on page navigation.
166178

docs/advanced/making plugins.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ The following sections will go into detail for what methods can be implemented f
2525
- `BuildCtx` is defined in `quartz/ctx.ts`. It consists of
2626
- `argv`: The command line arguments passed to the Quartz [[build]] command
2727
- `cfg`: The full Quartz [[configuration]]
28-
- `allSlugs`: a list of all the valid content slugs (see [[paths]] for more information on what a `ServerSlug` is)
28+
- `allSlugs`: a list of all the valid content slugs (see [[paths]] for more information on what a slug is)
2929
- `StaticResources` is defined in `quartz/resources.tsx`. It consists of
30-
- `css`: a list of URLs for stylesheets that should be loaded
30+
- `css`: a list of CSS style definitions that should be loaded. A CSS style is described with the `CSSResource` type which is also defined in `quartz/resources.tsx`. It accepts either a source URL or the inline content of the stylesheet.
3131
- `js`: a list of scripts that should be loaded. A script is described with the `JSResource` type which is also defined in `quartz/resources.tsx`. It allows you to define a load time (either before or after the DOM has been loaded), whether it should be a module, and either the source URL or the inline content of the script.
32+
- `additionalHead`: a list of JSX elements or functions that return JSX elements to be added to the `<head>` tag of the page. Functions receive the page's data as an argument and can conditionally render elements.
3233
3334
## Transformers
3435
@@ -37,7 +38,7 @@ Transformers **map** over content, taking a Markdown file and outputting modifie
3738
```ts
3839
export type QuartzTransformerPluginInstance = {
3940
name: string
40-
textTransform?: (ctx: BuildCtx, src: string | Buffer) => string | Buffer
41+
textTransform?: (ctx: BuildCtx, src: string) => string
4142
markdownPlugins?: (ctx: BuildCtx) => PluggableList
4243
htmlPlugins?: (ctx: BuildCtx) => PluggableList
4344
externalResources?: (ctx: BuildCtx) => Partial<StaticResources>
@@ -85,8 +86,10 @@ export const Latex: QuartzTransformerPlugin<Options> = (opts?: Options) => {
8586
if (engine === "katex") {
8687
return {
8788
css: [
88-
// base css
89-
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css",
89+
{
90+
// base css
91+
content: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css",
92+
},
9093
],
9194
js: [
9295
{
@@ -97,8 +100,6 @@ export const Latex: QuartzTransformerPlugin<Options> = (opts?: Options) => {
97100
},
98101
],
99102
}
100-
} else {
101-
return {}
102103
}
103104
},
104105
}
@@ -220,12 +221,26 @@ export type QuartzEmitterPlugin<Options extends OptionType = undefined> = (
220221

221222
export type QuartzEmitterPluginInstance = {
222223
name: string
223-
emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources): Promise<FilePath[]>
224+
emit(
225+
ctx: BuildCtx,
226+
content: ProcessedContent[],
227+
resources: StaticResources,
228+
): Promise<FilePath[]> | AsyncGenerator<FilePath>
229+
partialEmit?(
230+
ctx: BuildCtx,
231+
content: ProcessedContent[],
232+
resources: StaticResources,
233+
changeEvents: ChangeEvent[],
234+
): Promise<FilePath[]> | AsyncGenerator<FilePath> | null
224235
getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
225236
}
226237
```
227238
228-
An emitter plugin must define a `name` field, an `emit` function, and a `getQuartzComponents` function. `emit` is responsible for looking at all the parsed and filtered content and then appropriately creating files and returning a list of paths to files the plugin created.
239+
An emitter plugin must define a `name` field, an `emit` function, and a `getQuartzComponents` function. It can optionally implement a `partialEmit` function for incremental builds.
240+
241+
- `emit` is responsible for looking at all the parsed and filtered content and then appropriately creating files and returning a list of paths to files the plugin created.
242+
- `partialEmit` is an optional function that enables incremental builds. It receives information about which files have changed (`changeEvents`) and can selectively rebuild only the necessary files. This is useful for optimizing build times in development mode. If `partialEmit` is undefined, it will default to the `emit` function.
243+
- `getQuartzComponents` declares which Quartz components the emitter uses to construct its pages.
229244
230245
Creating new files can be done via regular Node [fs module](https://nodejs.org/api/fs.html) (i.e. `fs.cp` or `fs.writeFile`) or via the `write` function in `quartz/plugins/emitters/helpers.ts` if you are creating files that contain text. `write` has the following signature:
231246
@@ -234,7 +249,7 @@ export type WriteOptions = (data: {
234249
// the build context
235250
ctx: BuildCtx
236251
// the name of the file to emit (not including the file extension)
237-
slug: ServerSlug
252+
slug: FullSlug
238253
// the file extension
239254
ext: `.${string}` | ""
240255
// the file content to add
@@ -272,7 +287,7 @@ export const ContentPage: QuartzEmitterPlugin = () => {
272287
const allFiles = content.map((c) => c[1].data)
273288
for (const [tree, file] of content) {
274289
const slug = canonicalizeServer(file.data.slug!)
275-
const externalResources = pageResources(slug, resources)
290+
const externalResources = pageResources(slug, file.data, resources)
276291
const componentData: QuartzComponentProps = {
277292
fileData: file.data,
278293
externalResources,

docs/authoring content.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Some common frontmatter fields that are natively supported by Quartz:
3535
- `draft`: Whether to publish the page or not. This is one way to make [[private pages|pages private]] in Quartz.
3636
- `date`: A string representing the day the note was published. Normally uses `YYYY-MM-DD` format.
3737

38+
See [[Frontmatter]] for a complete list of frontmatter.
39+
3840
## Syncing your Content
3941

4042
When your Quartz is at a point you're happy with, you can save your changes to GitHub.

docs/build.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ This will start a local web server to run your Quartz on your computer. Open a w
2121
> - `--serve`: run a local hot-reloading server to preview your Quartz
2222
> - `--port`: what port to run the local preview server on
2323
> - `--concurrency`: how many threads to use to parse notes
24+
25+
> [!warning] Not to be used for production
26+
> Serve mode is intended for local previews only.
27+
> For production workloads, see the page on [[hosting]].

docs/configuration.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const config: QuartzConfig = {
2121
This part of the configuration concerns anything that can affect the whole site. The following is a list breaking down all the things you can configure:
2222

2323
- `pageTitle`: title of the site. This is also used when generating the [[RSS Feed]] for your site.
24+
- `pageTitleSuffix`: a string added to the end of the page title. This only applies to the browser tab title, not the title shown at the top of the page.
2425
- `enableSPA`: whether to enable [[SPA Routing]] on your site.
2526
- `enablePopovers`: whether to enable [[popover previews]] on your site.
2627
- `analytics`: what to use for analytics on your site. Values can be
@@ -32,18 +33,20 @@ This part of the configuration concerns anything that can affect the whole site.
3233
- `{ provider: 'posthog', apiKey: '<your-posthog-project-apiKey>', host: '<your-posthog-host>' }`: use [Posthog](https://posthog.com/);
3334
- `{ provider: 'tinylytics', siteId: '<your-site-id>' }`: use [Tinylytics](https://tinylytics.app/);
3435
- `{ provider: 'cabin' }` or `{ provider: 'cabin', host: 'https://cabin.example.com' }` (custom domain): use [Cabin](https://withcabin.com);
36+
- `{provider: 'clarity', projectId: '<your-clarity-id-code' }`: use [Microsoft clarity](https://clarity.microsoft.com/). The project id can be found on top of the overview page.
3537
- `locale`: used for [[i18n]] and date formatting
3638
- `baseUrl`: this is used for sitemaps and RSS feeds that require an absolute URL to know where the canonical 'home' of your site lives. This is normally the deployed URL of your site (e.g. `quartz.jzhao.xyz` for this site). Do not include the protocol (i.e. `https://`) or any leading or trailing slashes.
3739
- This should also include the subpath if you are [[hosting]] on GitHub pages without a custom domain. For example, if my repository is `jackyzha0/quartz`, GitHub pages would deploy to `https://jackyzha0.github.io/quartz` and the `baseUrl` would be `jackyzha0.github.io/quartz`.
3840
- Note that Quartz 4 will avoid using this as much as possible and use relative URLs whenever it can to make sure your site works no matter _where_ you end up actually deploying it.
3941
- `ignorePatterns`: a list of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that Quartz should ignore and not search through when looking for files inside the `content` folder. See [[private pages]] for more details.
4042
- `defaultDateType`: whether to use created, modified, or published as the default date to display on pages and page listings.
4143
- `theme`: configure how the site looks.
42-
- `cdnCaching`: If `true` (default), use Google CDN to cache the fonts. This will generally will be faster. Disable (`false`) this if you want Quartz to download the fonts to be self-contained.
44+
- `cdnCaching`: if `true` (default), use Google CDN to cache the fonts. This will generally be faster. Disable (`false`) this if you want Quartz to download the fonts to be self-contained.
4345
- `typography`: what fonts to use. Any font available on [Google Fonts](https://fonts.google.com/) works here.
44-
- `header`: Font to use for headers
45-
- `code`: Font for inline and block quotes.
46-
- `body`: Font for everything
46+
- `title`: font for the title of the site (optional, same as `header` by default)
47+
- `header`: font to use for headers
48+
- `code`: font for inline and block quotes
49+
- `body`: font for everything
4750
- `colors`: controls the theming of the site.
4851
- `light`: page background
4952
- `lightgray`: borders
@@ -101,8 +104,30 @@ transformers: [
101104
]
102105
```
103106

104-
Some plugins are included by default in the[ `quartz.config.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz.config.ts), but there are more available.
107+
Some plugins are included by default in the [`quartz.config.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz.config.ts), but there are more available.
105108

106109
You can see a list of all plugins and their configuration options [[tags/plugin|here]].
107110

108111
If you'd like to make your own plugins, see the [[making plugins|making custom plugins]] guide.
112+
113+
## Fonts
114+
115+
Fonts can be specified as a `string` or a `FontSpecification`:
116+
117+
```ts
118+
// string
119+
typography: {
120+
header: "Schibsted Grotesk",
121+
...
122+
}
123+
124+
// FontSpecification
125+
typography: {
126+
header: {
127+
name: "Schibsted Grotesk",
128+
weights: [400, 700],
129+
includeItalic: true,
130+
},
131+
...
132+
}
133+
```

docs/features/Citations.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Citations
3+
tags:
4+
- feature/transformer
5+
---
6+
7+
Quartz uses [rehype-citation](https://github.com/timlrx/rehype-citation) to support parsing of a BibTex bibliography file.
8+
9+
Under the default configuration, a citation key `[@templeton2024scaling]` will be exported as `(Templeton et al., 2024)`.
10+
11+
> [!example]- BibTex file
12+
>
13+
> ```bib title="bibliography.bib"
14+
> @article{templeton2024scaling,
15+
> title={Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet},
16+
> author={Templeton, Adly and Conerly, Tom and Marcus, Jonathan and Lindsey, Jack and Bricken, Trenton and Chen, Brian and Pearce, Adam and Citro, Craig and Ameisen, Emmanuel and Jones, Andy and Cunningham, Hoagy and Turner, Nicholas L and McDougall, Callum and MacDiarmid, Monte and Freeman, C. Daniel and Sumers, Theodore R. and Rees, Edward and Batson, Joshua and Jermyn, Adam and Carter, Shan and Olah, Chris and Henighan, Tom},
17+
> year={2024},
18+
> journal={Transformer Circuits Thread},
19+
> url={https://transformer-circuits.pub/2024/scaling-monosemanticity/index.html}
20+
> }
21+
> ```
22+
23+
> [!note] Behaviour of references
24+
>
25+
> By default, the references will be included at the end of the file. To control where the references to be included, uses `[^ref]`
26+
>
27+
> Refer to `rehype-citation` docs for more information.
28+
29+
## Customization
30+
31+
Citation parsing is a functionality of the [[plugins/Citations|Citation]] plugin. **This plugin is not enabled by default**. See the plugin page for customization options.

0 commit comments

Comments
 (0)