Sign up Log in
n/buzhidaoblog · 1mo ago · 328 views
u/buzhidao10068I don't know

From Zero to Live: A Complete Walkthrough of Building a Quartz 5 Blog

What is Quartz

Quartz is an open-source static site generator. Its official one-line definition is:

Quartz is a set of tools that helps you publish your digital garden and notes as a website for free. (A set of tools that helps you publish your digital garden and notes as a website for free.)

The author is Jacky Zhao (jzhao.xyz). The popularity of the term "digital garden" has a lot to do with his post "Networked Thought." This repo is currently on Quartz 5 (5.0.0), and the main branch is always called v5.

A few properties that need to be clear:

  • It is not a hosting service, and it is not a CMS. It does one thing: compiles Markdown in content/ into plain static HTML / CSS / JS in public/.
  • The output is pure static files. Drop it on any static host and it runs: Cloudflare Pages, GitHub Pages, Netlify, Vercel, even your own machine.
  • The stack is Node.js (requires ≥ 22) + TypeScript, the build uses esbuild, and the config is just one quartz.config.yaml at the repo root.
  • Plugin-based architecture. The obsidian preset used in this repo has 46 plugin entries; all feature toggles are in YAML, no code changes needed.

Links

Item URL
Official docs (start here) https://quartz.jzhao.xyz/
Official repo https://github.com/jackyzha0/quartz
Original "digital garden" concept post https://jzhao.xyz/posts/networked-thought
Demo site https://quartz.jzhao.xyz/
This site (the one tested in this post) https://blog.buzhidao.de5.net/
This site's source repo (private) https://github.com/buzhidao10068/Quartz
Comments data repo (giscus) https://github.com/buzhidao10068/Quartz-comments
What does Quartz do?

Turn a local note vault into a site with search, a graph, and comments, without changing a single character of the notes themselves.

Specifically, it can do:

① Publish Obsidian notes as-is. [[wikilinks]], #tags, > [!note] callouts, Mermaid diagrams, footnotes, tables, task checkboxes, .canvas, .base are all natively supported. hard-line-breaks can also treat "a single newline as <br>", matching how it looks in Obsidian.

② The navigation you'd expect from a decent site. Full-text search (browser-side index, no server dependency), Explorer, graph view, backlinks, hover previews, table of contents (TOC), dark/light toggle, multilingual UI (built-in zh-CN).

③ Fine-grained publishing controls. draft: true simply doesn't generate HTML; unlisted: true generates the page but keeps it out of lists/search/graph/RSS; the explicit-publish plugin can flip it into an allowlist where only pages with publish: true get published; encrypted-pages can even add a password to a single page.

④ Automatically generate a bunch of site-level artifacts. RSS (index.xml), sitemap.xml, search index JSON, favicon, share card images (OG image, generated at build time with satori + sharp), and CNAME for GitHub Pages.

⑤ Zero ops. Push code once, deploy once. No database, no server process, no certificates to renew manually — static hosting handles all of that.

What it doesn't do (common misunderstandings):

  • It doesn't handle the comment backend. Comments use giscus with GitHub Discussions; data lives in the comments repo, and Quartz only embeds the comment section into the page.
  • It doesn't handle hosting or domains. Domain, HTTPS, and CDN are the hosting platform's job.
  • No online editor. Writing always happens in Obsidian / any Markdown editor; Quartz only works on the "Markdown to website" stage.
1. Create the repo: go with Option A

The official install docs give two paths:

Approach origin points to Downside
Option A (recommended) On GitHub, click Use this template → Create a new repository Your own repo Almost none
Option B git clone the official repo jackyzha0/quartz You must manually change the remote afterward, otherwise pushes go back to the official repo

Option A removes exactly the most error-prone step: no more messing with git remote set-url origin. After creating it, make sure the default branch is v5 — Quartz 5 is hard-wired to this branch name across the whole pipeline (in the CLI, QUARTZ_SOURCE_BRANCH = "v5"; the CI trigger branch; Cloudflare's Production branch — all of them).

git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>
2. Install dependencies + initialize
npm i
npx quartz create

Don't ignore the prerequisites: Node.js ≥ 22, npm ≥ 10.9.2. The repo's .npmrc has engine-strict=true, so if the version is too low, npm i hard-fails instead of giving a warning.

npx quartz create asks four things in order. My choices:

Question What I picked Why
Template obsidian Move the note vault straight over; hard line breaks, wikilinks, and tags all match Obsidian behavior
content strategy new (write my own) I wrote directly in content/ afterward; doing symlinks would require enabling Windows Developer Mode first
baseUrl blog.buzhidao.de5.net No https://; trailing slashes are stripped automatically too
Link resolution shortest Matches Obsidian's [[page name]] style

Equivalent one-line non-interactive command:

npx quartz create --template obsidian --strategy new --baseUrl blog.buzhidao.de5.net
create overwrites quartz.config.yaml wholesale

It does not merge — the official docs literally say "always overwrites." Any hand-edited locale, fonts, or comment settings get reset to template defaults. If you've already changed the config, back it up first.

The differences between the four templates are actually small (I diffed three of the YAML files line by line):

Template Entry count Difference from default
default 45 Baseline
blog 45 +comments, recent-notes; −encrypted-pages
obsidian 46 +hard-line-breaks, @quartz-themes/core; +Excalidraw
ttrpg 47 = obsidian + Leaflet map (git source)

In other words, the entire meaning of the "blog template" is that it turns on the comment section and a "recent notes" sidebar. If you want the blog style, you don't need to rerun create; just flip those two enabled: false entries to true — which also conveniently avoids the risk of your config being overwritten.

3. Chinese localization

Quartz has built-in zh-CN translations; one line is enough:

configuration:
  locale: zh-CN

Fonts are another thing to watch: the default typography uses Schibsted Grotesk / Source Sans Pro, which have no Chinese glyphs, so Chinese falls back to system fonts (Microsoft YaHei on Windows), and the Chinese/English styles don't match.

  theme:
    fontOrigin: local        # Don't depend on Google Fonts; more reliable access from mainland China

fontOrigin only accepts googleFonts and local. Choosing local just uses system fonts and makes no external CDN requests. If you want Chinese and English to match, you can switch to Noto Sans SC, but then you'd have to go through Google Fonts or self-host the font files.

4. Local preview
npx quartz build --serve --port 3005 --wsPort 3006
  • --port defaults to 8080; I usually use 3005;
  • Hot reload uses WebSocket, which defaults to 3001; if it's occupied, add --wsPort 3006;
  • --serve implies watch, so editing Markdown triggers a rebuild and browser refresh automatically.
5. Gotchas specific to my machine

This section is what I actually ran into. Quartz itself is fine — it's purely the environment. If you're also running in Windows + a sandbox terminal, you may hit the same things.

Gotcha 1: mkdir quartz\.quartz-cache: Access is denied

The build dies right at the start:

✘ [ERROR] Failed to create output directory:
  mkdir ...\quartz\.quartz-cache: Access is denied.

It took me a while to track down the root cause; in the end I pinned it on Windows integrity levels (MIC): the workspace root had a Low label that gets inherited by children, so the newly created node_modules under the root also inherited Low, and every time esbuild.exe launched from there it could only run at Low. Meanwhile quartz\ and docs\, which already existed when I cloned, were still at the default Medium — a Low process writing to a Medium directory was blocked by Windows' no-write-up rule.

Two workarounds, pick one:

# A. Raise node_modules' integrity level back to Medium (thousands of files, takes a few seconds)
icacls node_modules /setintegritylevel "(OI)(CI)Medium" /T
# B. Copy esbuild.exe to a temp directory and point an env var at it
$tmp = "$env:TEMP\esbuild\esbuild.exe"
Copy-Item node_modules\esbuild\esbuild.exe $tmp
$env:ESBUILD_BINARY_PATH = $tmp
The key tell for this gotcha

Running with "full permissions" doesn't fix it, and reinstalling node_modules doesn't fix it either — because the new directory still inherits Low. Don't waste time on elevation; change the integrity label directly.

Gotcha 2: npx quartz ... hangs until OOM

Even npx quartz --version can produce no output for several minutes, then end with FATAL ERROR: Ineffective mark-compacts near heap limit.

The giveaway is clear: there's not a single line of quartz output before it crashes, which means it crashes before startup, not that the build is eating memory. The cause was that the npx cache had created a junction for this package pointing at the repo root, so every validation pass walked thousands of files and 200+ MB.

Workaround: call the entry script directly; it's completely equivalent.

node ./quartz/bootstrap-cli.mjs build --serve --port 3005

(npm cache clean --force can also fix it, but you have to redownload everything.)

Gotcha 3: In --serve mode all styles and scripts 404, page collapses to one column

The page opens, but the layout is one column, the search box doesn't respond, and the Explorer is blank. DevTools shows index.css and postscript.js all 404.

The cause is inconsistent asset naming: --serve uses names without hashes (index.css), while the production build uses names with hashes (index-bb6c1746.css). If public/ still contains production build output, the three files referenced by serve mode don't exist. And write errors during the emit phase get silently swallowed, so there's no error.

What's more insidious: losing the main stylesheet = no grid rules for #quartz-body = the page is stuck in one column, regardless of window width. I first misdiagnosed it as "the window is too narrow" and went in circles — when debugging, check whether index.css is 200 in the Network tab first; it saves a lot of time.

Fix:

# First Ctrl+C to stop the dev server, then
Remove-Item public -Recurse -Force
npx quartz build --serve --port 3005

One rule to remember: don't run another npx quartz build while the dev server is running (the production build rewrites asset names in public/, and the two fight each other). To verify the build separately, output to another directory: npx quartz build -o .build-check.

Gotcha 4: quartz.lock.json is empty and you think it's broken

{ "version": "1.0.0", "plugins": {} }

This is normal. The lockfile only records git-source plugins (github:owner/repo, git+https://…, local paths); the vast majority of Quartz 5 plugins are npm packages, whose versions are managed by package.json + package-lock.json and don't go into the lockfile. So with a pure npm setup, both an empty .quartz/plugins/ and an empty lockfile are fine.

6. Comments: giscus

Quartz's comments plugin only supports giscus as a provider, and giscus has two hard requirements that are easy to trip over:

  1. The comments repo must be public. Your site source can be private, but comments need a separate public repo for Discussions.
  2. The repo must have Discussions enabled and have the giscus App installed.

My config:

  - source: "@quartz-community/comments"
    enabled: true
    options:
      provider: giscus
      options:
        repo: buzhidao10068/Quartz-comments
        repoId: R_kgDOU74DEQ
        category: Announcements
        categoryId: DIC_kwDOU74DEc4DHDSJ
        mapping: pathname      # 关键
        strict: true
        reactionsEnabled: true
        inputPosition: bottom
        lightTheme: light
        darkTheme: dark
        lang: zh-CN
    layout:
      position: afterBody
      priority: 10

Three choices worth explaining:

① mapping: pathname instead of the default url. Comments are tied to the "page path", not the domain. When I switched from blog2.buzhidao.de5.net to blog.buzhidao.de5.net, I didn't lose a single comment — because the /notes/abc/ key didn't change. With url, changing the domain splits them into two sets, and old comments are effectively zeroed out.

② category: Announcements. By default only maintainers can create new discussions in this category, which prevents other people from creating random posts in your repo; the giscus bot has permission, so it's unaffected.

③ Comment data is not in your site repo. It lives in the comments repo's Discussions — one page maps to one Discussion, and one comment is one reply. GitHub is your comment backend: reply, delete, and lock all happen there.

Two usage reminders
  • When nobody has commented, Discussions is empty; that's normal — giscus only creates the corresponding discussion when the first comment is posted.
  • Don't actually post comments when testing on local localhost: with pathname mapping, local / and the live homepage / are the same discussion.
7. Deploy to Cloudflare Pages

Builds from code pulled from GitHub; push once, deploy once.

Config item Value
Production branch v5
Framework preset None
Build command git fetch --unshallow && npx quartz plugin install --from-config && npx quartz build
Build output directory public
Environment variable NODE_VERSION = 24

Neither prefix in the build command is optional:

  • git fetch --unshallow — Cloudflare shallow-clones by default; without this line, created-modified-date dates taken from git will be wrong;
  • plugin install --from-config — installs missing plugins based on config. Note that it only handles git-sourced plugins; npm plugins are installed automatically by npm ci before the build. Also, install failures only print warnings and don't fail the build, so a successful build ≠ plugins took effect; keep an eye on the ⚠ in the logs.

Attach a custom domain

Pages project → Custom domains → Set up a domain → enter the domain. Two cases:

  • The domain's DNS is already on Cloudflare: records are added automatically, certificates are issued automatically, and it takes effect immediately. Apex domains (example.com) can only go this route; Cloudflare uses CNAME flattening.
  • DNS is elsewhere: add a CNAME for the subdomain pointing to <project-name>.pages.dev; apex domains can't use a CNAME directly, so either move the nameserver to Cloudflare or check whether your provider supports ALIAS/ANAME.
Order matters

You must attach the domain in the Pages dashboard first, then add the DNS record. Manually adding only a CNAME in DNS gets you a 522.

After changing the domain, update baseUrl in quartz.config.yaml to match (no protocol, no trailing slash) — it determines the addresses for the sitemap, RSS, share card images (OG), and the giscus theme CSS.

Keep the old domain and set up a 301: RSS subscribers subscribe to a specific URL and won't automatically follow a domain change

8. Daily writing workflow
# 1) 在 Obsidian 里写(把 content/ 直接当 vault 打开,我是打开content的父文件夹)
# 2) 本地预览
npx quartz build --serve --port 3005 --wsPort 3006
# 3) 发布
npx quartz sync -m "content: 新增文章标题"(发布就是git操作了)

sync does git add -A + commit + pull + push. The default commit message is Quartz sync: <timestamp>; add -m if you want your own.

sync force-pushes, and it pushes "the current branch"

The code is git push -uf origin $(git rev-parse --abbrev-ref HEAD), but pull always uses origin v5. So before running it, make sure git branch --show-current is v5; otherwise you get "pull v5, force-push some other branch."

Frontmatter for each post

---
title: 文章标题
description: 一句话摘要,用于搜索和分享卡片
tags: [Quartz, 博客搭建]
created: 2026-10-26
modified: 2026-10-26
published: 2026-10-26
enableToc: true
comments: true
draft: false
unlisted: false
password:
stealth: false
publish: true
数字编号: 
---

A few easy-to-trip-on points:

Field Note
publish If the explicit-publish plugin is on, no page is generated at all unless you write publish: true — this is the easiest place for a post to "disappear" with no clue why
tags Must be an array (tags: [a, b]); a single value breaks conditions like "only show if tagged"
Dates Only created / modified / published are recognized; Quartz doesn't read the common Obsidian date: field
draft vs unlisted draft: true doesn't even generate HTML; unlisted: true generates the page but keeps it out of lists/search/graph, and it's accessible by direct link
Case enableToc, cssclasses, socialImage won't work if written as enable_toc / CSSClasses

9. Final result

Item Result
Site Static HTML, hosted on Cloudflare Pages
Domain Custom domain + automatic HTTPS
UI language zh-CN, dates formatted in Chinese
Comments giscus, data in GitHub Discussions, survives domain changes
Writing Write Markdown directly in Obsidian, content/ as the vault
Ops cost 0 (push code = deploy)
Cost 0

Synced from my blog: https://blog.buzhidao.de5.net/quartz-5%E7%9B%B8%E5%85%B3/%E4%BB%8E%E9%9B%B6%E5%88%B0%E4%B8%8A%E7%BA%BF%EF%BC%9Aquartz-5-%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA%E5%85%A8%E8%BF%87%E7%A8%8B%E6%80%BB%E7%BB%93

Translated by AI from 简体中文

1
2
Log into join the discussion.

2 replies

Sort order
  1. lovoup Diamond 3 YEARS 1mo ago #2

    Same as Hexo? Is Hugo pretty much the same thing?

    Translated by AI from 简体中文

    0
  2. buzhidao10068 I don't know OP 1mo ago #3
    Reply @lovoup: 和 hexo. Hugo 是不是差不多

    I have no idea 😭 never used Hugo

    Translated by AI from 简体中文

    0