From 4bdc17d4a11f0ba517c6d9124d296458332c536b Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sat, 03 Jun 2023 19:07:19 +0000
Subject: [PATCH] inline scripts
---
quartz/bootstrap.mjs | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/quartz/bootstrap.mjs b/quartz/bootstrap.mjs
index 1fa4538..16a0c69 100755
--- a/quartz/bootstrap.mjs
+++ b/quartz/bootstrap.mjs
@@ -1,10 +1,12 @@
#!/usr/bin/env node
-import { readFileSync } from 'fs'
+import { promises, readFileSync } from 'fs'
import yargs from 'yargs'
+import path from 'path'
import { hideBin } from 'yargs/helpers'
import esbuild from 'esbuild'
import chalk from 'chalk'
import requireFromString from 'require-from-string'
+import { sassPlugin } from 'esbuild-sass-plugin'
const fp = "./quartz.config.ts"
const { version } = JSON.parse(readFileSync("./package.json").toString())
@@ -59,7 +61,35 @@
format: "cjs",
jsx: "automatic",
jsxImportSource: "preact",
- external: ["@napi-rs/simple-git"]
+ external: ["@napi-rs/simple-git", "shiki"],
+ plugins: [
+ sassPlugin({
+ type: 'css-text'
+ }),
+ {
+ name: 'inline-script-loader',
+ setup(build) {
+ build.onLoad({ filter: /\.inline\.(ts|js)$/ }, async (args) => {
+ let text = await promises.readFile(args.path, 'utf8')
+ const transpiled = await esbuild.build({
+ stdin: {
+ contents: text,
+ sourcefile: path.relative(path.resolve('.'), args.path),
+ },
+ write: false,
+ bundle: true,
+ platform: "browser",
+ format: "esm",
+ })
+ const rawMod = transpiled.outputFiles[0].text
+ return {
+ contents: rawMod,
+ loader: 'text',
+ }
+ })
+ }
+ }
+ ]
}).catch(err => {
console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`)
console.log(`Reason: ${chalk.grey(err)}`)
--
Gitblit v1.10.0