Jacky Zhao
2023-07-16 8e0ba45789a81ee28f6c67468f7fcf9ea45832db
add link resolution prompt to quartz create
4 files modified
62 ■■■■■ changed files
README.md 4 ●●●● patch | view | raw | blame | history
quartz/bootstrap-cli.mjs 51 ●●●● patch | view | raw | blame | history
quartz/plugins/transformers/ofm.ts 2 ●●● patch | view | raw | blame | history
quartz/processors/parse.ts 5 ●●●●● patch | view | raw | blame | history
README.md
@@ -3,9 +3,9 @@
> “[One] who works with the door open gets all kinds of interruptions, but [they] also occasionally gets clues as to what the world is and what might be important.” — Richard Hamming
Quartz is a set of tools that helps you publish your [digital garden](https://jzhao.xyz/posts/networked-thought) and notes as a website for free.
Quartz v4 features a from-the-ground rewrite focussing on end-user extensibility and ease-of-use.
Quartz v4 features a from-the-ground rewrite focusing on end-user extensibility and ease-of-use.
Please note that v4 is still beta software and *will* contain bugs. Use with caution!
Please note that v4 is still beta software and will probably contain bugs. Use with caution!
**If you are looking for Quartz v3, you can find it on the [`hugo` branch](https://github.com/jackyzha0/quartz/tree/hugo).**
quartz/bootstrap-cli.mjs
@@ -54,6 +54,16 @@
    .trim()
}
function exitIfCancel(val) {
  if (isCancel(val)) {
    outro(chalk.red("Exiting"))
    process.exit(0)
  } else {
    return val
  }
}
yargs(hideBin(process.argv))
  .scriptName("quartz")
  .version(version)
@@ -61,8 +71,9 @@
  .command('create', 'Initialize Quartz', async (_argv) => {
    console.log()
    intro(chalk.bgGreen.black(` Quartz v${version} `))
    const contentFolder = path.join(process.cwd(), "content")
    const setupStrategy = await select({
    const cwd = process.cwd()
    const contentFolder = path.join(cwd, "content")
    const setupStrategy = exitIfCancel(await select({
      message: `Choose how to initialize the content in \`${contentFolder}\``,
      options: [
        { value: 'new', label: "Empty Quartz" },
@@ -70,12 +81,17 @@
        { value: 'symlink', label: "Symlink an existing folder", hint: "don't select this unless you know what you are doing!" },
        { value: 'keep', label: "Keep the existing files" },
      ]
    })
    }))
    if (isCancel(setupStrategy)) {
      outro(chalk.red("Exiting"))
      process.exit(0)
    }
    // TODO
    const linkResolutionStrategy = exitIfCancel(await select({
      message: `Choose how Quartz should resolve links in your content. You can change this later in \`quartz.config.ts\`.`,
      options: [
        { value: 'absolute', label: "Treat links as absolute path", hint: "for content made for Quartz 3 and Hugo" },
        { value: 'shortest', label: "Treat links as shortest path", hint: "for most Obsidian vaults" },
        { value: 'relative', label: "Treat links as relative paths", hint: "for just normal Markdown files" },
      ]
    }))
    async function rmContentFolder() {
      const contentStat = await fs.promises.lstat(contentFolder)
@@ -89,7 +105,7 @@
    }
    if (setupStrategy === 'copy' || setupStrategy === 'symlink') {
      const originalFolder = escapePath(await text({
      const originalFolder = escapePath(exitIfCancel(await text({
        message: "Enter the full path to existing content folder",
        placeholder: 'On most terminal emulators, you can drag and drop a folder into the window and it will paste the full path',
        validate(fp) {
@@ -100,12 +116,7 @@
            return "The given path is not a folder"
          }
        }
      }))
      if (isCancel(originalFolder)) {
        outro(chalk.red("Exiting"))
        process.exit(0)
      }
      })))
      await rmContentFolder()
      if (setupStrategy === 'copy') {
@@ -127,12 +138,24 @@
      )
    }
    // now, do config changes
    const configFilePath = path.join(cwd, "quartz.config.ts")
    let configContent = await fs.promises.readFile(configFilePath, { encoding: 'utf-8' })
    configContent = configContent.replace(/markdownLinkResolution: '(.+)'/, `markdownLinkResolution: '${linkResolutionStrategy}'`)
    await fs.promises.writeFile(configFilePath, configContent)
    outro(`You're all set! Not sure what to do next? Try:
   • Customizing Quartz a bit more by editing \`quartz.config.ts\`
   • Running \`npx quartz build --serve\` to preview your Quartz locally
   • Hosting your Quartz online (see: https://quartz.jzhao.xyz/setup/hosting)
`)
  })
  .command('update', 'Get the latest Quartz updates', () => {
    // TODO
  })
  .command('push', 'Push your Quartz updates to GitHub', () => {
    // TODO
  })
  .command('build', 'Build Quartz into a bundle of static HTML files', BuildArgv, async (argv) => {
    const result = await esbuild.build({
      entryPoints: [fp],
quartz/plugins/transformers/ofm.ts
@@ -9,7 +9,7 @@
import { JSResource } from "../../resources"
// @ts-ignore
import calloutScript from "../../components/scripts/callout.inline.ts"
import { FilePath, slugifyFilePath, transformInternalLink } from "../../path"
import { FilePath, slugifyFilePath } from "../../path"
export interface Options {
  comments: boolean
quartz/processors/parse.ts
@@ -7,13 +7,12 @@
import { ProcessedContent } from '../plugins/vfile'
import { PerfTimer } from '../perf'
import { read } from 'to-vfile'
import { FilePath, ServerSlug, slugifyFilePath } from '../path'
import { FilePath, QUARTZ, ServerSlug, slugifyFilePath } from '../path'
import path from 'path'
import os from 'os'
import workerpool, { Promise as WorkerPromise } from 'workerpool'
import { QuartzTransformerPluginInstance } from '../plugins/types'
import { QuartzLogger } from '../log'
import chalk from 'chalk'
import { trace } from '../trace'
export type QuartzProcessor = Processor<MDRoot, HTMLRoot, void>
@@ -50,7 +49,7 @@
  const fp = "./quartz/worker.ts"
  return esbuild.build({
    entryPoints: [fp],
    outfile: path.join("quartz", cacheFile),
    outfile: path.join(QUARTZ, cacheFile),
    bundle: true,
    keepNames: true,
    platform: "node",