improve hot reload robustness

This commit is contained in:
Jacky Zhao 2023-08-05 15:34:10 -07:00
parent c402f0c385
commit 7c09627df4
4 changed files with 14 additions and 13 deletions

View file

@ -6,6 +6,7 @@ draft: true
- block links: https://help.obsidian.md/Linking+notes+and+files/Internal+links#Link+to+a+block+in+a+note - block links: https://help.obsidian.md/Linking+notes+and+files/Internal+links#Link+to+a+block+in+a+note
- note/header/block transcludes: https://help.obsidian.md/Linking+notes+and+files/Embedding+files - note/header/block transcludes: https://help.obsidian.md/Linking+notes+and+files/Embedding+files
- static dead link detection
## misc ## misc
@ -14,7 +15,6 @@ draft: true
- recent notes component - recent notes component
- cursor chat extension - cursor chat extension
- https://giscus.app/ extension - https://giscus.app/ extension
- custom md blocks (e.g. for poetry)
- sidenotes? https://github.com/capnfabs/paperesque - sidenotes? https://github.com/capnfabs/paperesque
- direct match in search using double quotes - direct match in search using double quotes
- https://help.obsidian.md/Advanced+topics/Using+Obsidian+URI - https://help.obsidian.md/Advanced+topics/Using+Obsidian+URI

View file

@ -6,7 +6,9 @@ Quartz is a fast, batteries-included static-site generator that transforms Markd
## 🪴 Get Started ## 🪴 Get Started
Quartz requires **at least [Node](https://nodejs.org/) v18.14** to function correctly. In your terminal of choice, enter the following commands line by line: Quartz requires **at least [Node](https://nodejs.org/) v18.14** to function correctly. Ensure you have this installed on your machine before continuing.
Then, in your terminal of choice, enter the following commands line by line:
```shell ```shell
git clone https://github.com/jackyzha0/quartz.git git clone https://github.com/jackyzha0/quartz.git
@ -22,6 +24,9 @@ When you're ready, you can edit `quartz.config.ts` to customize and configure Qu
Then, when you're ready, see how to [[build]] and [[hosting|host]] Quartz. Then, when you're ready, see how to [[build]] and [[hosting|host]] Quartz.
> [!info]
> Coming from Quartz 3? See the [[migrating from Quartz 3|migration guide]] for the differences between Quartz 3 and Quartz 4 and how to migrate.
## 🔧 Features ## 🔧 Features
- [[full-text search|Full-text search]], [[graph view]], [[backlinks]], [[Latex]], [[syntax highlighting]], [[popover previews]], and many more right out of the box - [[full-text search|Full-text search]], [[graph view]], [[backlinks]], [[Latex]], [[syntax highlighting]], [[popover previews]], and many more right out of the box

View file

View file

@ -353,9 +353,7 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
], ],
}) })
let clientRefresh = () => {} const build = async (clientRefresh) => {
let closeHandler = null
const build = async () => {
const result = await ctx.rebuild().catch((err) => { const result = await ctx.rebuild().catch((err) => {
console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`) console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`)
console.log(`Reason: ${chalk.grey(err)}`) console.log(`Reason: ${chalk.grey(err)}`)
@ -375,20 +373,17 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
// bypass module cache // bypass module cache
const { default: buildQuartz } = await import(cacheFile + `?update=${new Date()}`) const { default: buildQuartz } = await import(cacheFile + `?update=${new Date()}`)
if (closeHandler) { await buildQuartz(argv, clientRefresh)
await closeHandler()
}
closeHandler = await buildQuartz(argv, clientRefresh)
clientRefresh() clientRefresh()
} }
await build()
if (argv.serve) { if (argv.serve) {
const wss = new WebSocketServer({ port: 3001 }) const wss = new WebSocketServer({ port: 3001 })
const connections = [] const connections = []
wss.on("connection", (ws) => connections.push(ws)) wss.on("connection", (ws) => connections.push(ws))
clientRefresh = () => connections.forEach((conn) => conn.send("rebuild")) const clientRefresh = () => connections.forEach((conn) => conn.send("rebuild"))
await build(clientRefresh)
const server = http.createServer(async (req, res) => { const server = http.createServer(async (req, res) => {
await serveHandler(req, res, { await serveHandler(req, res, {
public: argv.output, public: argv.output,
@ -412,9 +407,10 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
}) })
.on("all", async () => { .on("all", async () => {
console.log(chalk.yellow("Detected a source code change, doing a hard rebuild...")) console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
await build() await build(clientRefresh)
}) })
} else { } else {
await build(() => {})
ctx.dispose() ctx.dispose()
} }
}) })