From 9c8fec06d2b58e4e3bbe280ddc665a99fcc4878c Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 09 Mar 2025 22:33:15 +0000
Subject: [PATCH] feat: support non-singleton search
---
quartz/cli/handlers.js | 40 +++++++++++++++++++++++++++++-----------
1 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/quartz/cli/handlers.js b/quartz/cli/handlers.js
index 5538152..6ef3805 100644
--- a/quartz/cli/handlers.js
+++ b/quartz/cli/handlers.js
@@ -15,6 +15,7 @@
import { randomUUID } from "crypto"
import { Mutex } from "async-mutex"
import { CreateArgv } from "./args.js"
+import { globby } from "globby"
import {
exitIfCancel,
escapePath,
@@ -33,13 +34,22 @@
} from "./constants.js"
/**
+ * Resolve content directory path
+ * @param contentPath path to resolve
+ */
+function resolveContentPath(contentPath) {
+ if (path.isAbsolute(contentPath)) return path.relative(cwd, contentPath)
+ return path.join(cwd, contentPath)
+}
+
+/**
* Handles `npx quartz create`
* @param {*} argv arguments for `create`
*/
export async function handleCreate(argv) {
console.log()
intro(chalk.bgGreen.black(` Quartz v${version} `))
- const contentFolder = path.join(cwd, argv.directory)
+ const contentFolder = resolveContentPath(argv.directory)
let setupStrategy = argv.strategy?.toLowerCase()
let linkResolutionStrategy = argv.links?.toLowerCase()
const sourceDirectory = argv.source
@@ -290,8 +300,8 @@
}
if (cleanupBuild) {
- await cleanupBuild()
console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
+ await cleanupBuild()
}
const result = await ctx.rebuild().catch((err) => {
@@ -355,6 +365,15 @@
source: "**/*.*",
headers: [{ key: "Content-Disposition", value: "inline" }],
},
+ {
+ source: "**/*.webp",
+ headers: [{ key: "Content-Type", value: "image/webp" }],
+ },
+ // fixes bug where avif images are displayed as text instead of images (future proof)
+ {
+ source: "**/*.avif",
+ headers: [{ key: "Content-Type", value: "image/avif" }],
+ },
],
})
const status = res.statusCode
@@ -423,13 +442,12 @@
),
)
console.log("hint: exit with ctrl+c")
+ const paths = await globby(["**/*.ts", "**/*.tsx", "**/*.scss", "package.json"])
chokidar
- .watch(["**/*.ts", "**/*.tsx", "**/*.scss", "package.json"], {
- ignoreInitial: true,
- })
- .on("all", async () => {
- build(clientRefresh)
- })
+ .watch(paths, { ignoreInitial: true })
+ .on("add", () => build(clientRefresh))
+ .on("change", () => build(clientRefresh))
+ .on("unlink", () => build(clientRefresh))
} else {
await build(() => {})
ctx.dispose()
@@ -441,7 +459,7 @@
* @param {*} argv arguments for `update`
*/
export async function handleUpdate(argv) {
- const contentFolder = path.join(cwd, argv.directory)
+ const contentFolder = resolveContentPath(argv.directory)
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
console.log("Backing up your content")
execSync(
@@ -493,7 +511,7 @@
* @param {*} argv arguments for `restore`
*/
export async function handleRestore(argv) {
- const contentFolder = path.join(cwd, argv.directory)
+ const contentFolder = resolveContentPath(argv.directory)
await popContentFolder(contentFolder)
}
@@ -502,7 +520,7 @@
* @param {*} argv arguments for `sync`
*/
export async function handleSync(argv) {
- const contentFolder = path.join(cwd, argv.directory)
+ const contentFolder = resolveContentPath(argv.directory)
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
console.log("Backing up your content")
--
Gitblit v1.10.0