add link resolution prompt to quartz create
This commit is contained in:
parent
0c5ca34c4b
commit
0b5fc92b90
@ -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
|
> “[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 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).**
|
**If you are looking for Quartz v3, you can find it on the [`hugo` branch](https://github.com/jackyzha0/quartz/tree/hugo).**
|
||||||
|
|
||||||
|
@ -54,6 +54,16 @@ function escapePath(fp) {
|
|||||||
.trim()
|
.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exitIfCancel(val) {
|
||||||
|
|
||||||
|
if (isCancel(val)) {
|
||||||
|
outro(chalk.red("Exiting"))
|
||||||
|
process.exit(0)
|
||||||
|
} else {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
yargs(hideBin(process.argv))
|
yargs(hideBin(process.argv))
|
||||||
.scriptName("quartz")
|
.scriptName("quartz")
|
||||||
.version(version)
|
.version(version)
|
||||||
@ -61,8 +71,9 @@ yargs(hideBin(process.argv))
|
|||||||
.command('create', 'Initialize Quartz', async (_argv) => {
|
.command('create', 'Initialize Quartz', async (_argv) => {
|
||||||
console.log()
|
console.log()
|
||||||
intro(chalk.bgGreen.black(` Quartz v${version} `))
|
intro(chalk.bgGreen.black(` Quartz v${version} `))
|
||||||
const contentFolder = path.join(process.cwd(), "content")
|
const cwd = process.cwd()
|
||||||
const setupStrategy = await select({
|
const contentFolder = path.join(cwd, "content")
|
||||||
|
const setupStrategy = exitIfCancel(await select({
|
||||||
message: `Choose how to initialize the content in \`${contentFolder}\``,
|
message: `Choose how to initialize the content in \`${contentFolder}\``,
|
||||||
options: [
|
options: [
|
||||||
{ value: 'new', label: "Empty Quartz" },
|
{ value: 'new', label: "Empty Quartz" },
|
||||||
@ -70,12 +81,17 @@ yargs(hideBin(process.argv))
|
|||||||
{ value: 'symlink', label: "Symlink an existing folder", hint: "don't select this unless you know what you are doing!" },
|
{ 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" },
|
{ value: 'keep', label: "Keep the existing files" },
|
||||||
]
|
]
|
||||||
})
|
}))
|
||||||
|
|
||||||
if (isCancel(setupStrategy)) {
|
// TODO
|
||||||
outro(chalk.red("Exiting"))
|
const linkResolutionStrategy = exitIfCancel(await select({
|
||||||
process.exit(0)
|
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() {
|
async function rmContentFolder() {
|
||||||
const contentStat = await fs.promises.lstat(contentFolder)
|
const contentStat = await fs.promises.lstat(contentFolder)
|
||||||
@ -89,7 +105,7 @@ yargs(hideBin(process.argv))
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (setupStrategy === 'copy' || setupStrategy === 'symlink') {
|
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",
|
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',
|
placeholder: 'On most terminal emulators, you can drag and drop a folder into the window and it will paste the full path',
|
||||||
validate(fp) {
|
validate(fp) {
|
||||||
@ -100,12 +116,7 @@ yargs(hideBin(process.argv))
|
|||||||
return "The given path is not a folder"
|
return "The given path is not a folder"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
})))
|
||||||
|
|
||||||
if (isCancel(originalFolder)) {
|
|
||||||
outro(chalk.red("Exiting"))
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
await rmContentFolder()
|
await rmContentFolder()
|
||||||
if (setupStrategy === 'copy') {
|
if (setupStrategy === 'copy') {
|
||||||
@ -127,12 +138,24 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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:
|
outro(`You're all set! Not sure what to do next? Try:
|
||||||
• Customizing Quartz a bit more by editing \`quartz.config.ts\`
|
• Customizing Quartz a bit more by editing \`quartz.config.ts\`
|
||||||
• Running \`npx quartz build --serve\` to preview your Quartz locally
|
• Running \`npx quartz build --serve\` to preview your Quartz locally
|
||||||
• Hosting your Quartz online (see: https://quartz.jzhao.xyz/setup/hosting)
|
• 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) => {
|
.command('build', 'Build Quartz into a bundle of static HTML files', BuildArgv, async (argv) => {
|
||||||
const result = await esbuild.build({
|
const result = await esbuild.build({
|
||||||
entryPoints: [fp],
|
entryPoints: [fp],
|
||||||
|
@ -9,7 +9,7 @@ import path from "path"
|
|||||||
import { JSResource } from "../../resources"
|
import { JSResource } from "../../resources"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import calloutScript from "../../components/scripts/callout.inline.ts"
|
import calloutScript from "../../components/scripts/callout.inline.ts"
|
||||||
import { FilePath, slugifyFilePath, transformInternalLink } from "../../path"
|
import { FilePath, slugifyFilePath } from "../../path"
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
comments: boolean
|
comments: boolean
|
||||||
|
@ -7,13 +7,12 @@ import { Root as HTMLRoot } from 'hast'
|
|||||||
import { ProcessedContent } from '../plugins/vfile'
|
import { ProcessedContent } from '../plugins/vfile'
|
||||||
import { PerfTimer } from '../perf'
|
import { PerfTimer } from '../perf'
|
||||||
import { read } from 'to-vfile'
|
import { read } from 'to-vfile'
|
||||||
import { FilePath, ServerSlug, slugifyFilePath } from '../path'
|
import { FilePath, QUARTZ, ServerSlug, slugifyFilePath } from '../path'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import workerpool, { Promise as WorkerPromise } from 'workerpool'
|
import workerpool, { Promise as WorkerPromise } from 'workerpool'
|
||||||
import { QuartzTransformerPluginInstance } from '../plugins/types'
|
import { QuartzTransformerPluginInstance } from '../plugins/types'
|
||||||
import { QuartzLogger } from '../log'
|
import { QuartzLogger } from '../log'
|
||||||
import chalk from 'chalk'
|
|
||||||
import { trace } from '../trace'
|
import { trace } from '../trace'
|
||||||
|
|
||||||
export type QuartzProcessor = Processor<MDRoot, HTMLRoot, void>
|
export type QuartzProcessor = Processor<MDRoot, HTMLRoot, void>
|
||||||
@ -50,7 +49,7 @@ async function transpileWorkerScript() {
|
|||||||
const fp = "./quartz/worker.ts"
|
const fp = "./quartz/worker.ts"
|
||||||
return esbuild.build({
|
return esbuild.build({
|
||||||
entryPoints: [fp],
|
entryPoints: [fp],
|
||||||
outfile: path.join("quartz", cacheFile),
|
outfile: path.join(QUARTZ, cacheFile),
|
||||||
bundle: true,
|
bundle: true,
|
||||||
keepNames: true,
|
keepNames: true,
|
||||||
platform: "node",
|
platform: "node",
|
||||||
|
Loading…
Reference in New Issue
Block a user