diff --git a/package-lock.json b/package-lock.json index 0b292c07..e53a3e58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@napi-rs/simple-git": "^0.1.8", "chalk": "^4.1.2", "cli-spinner": "^0.2.10", + "env-paths": "^3.0.0", "esbuild-sass-plugin": "^2.9.0", "github-slugger": "^2.0.0", "globby": "^13.1.4", @@ -1346,6 +1347,17 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/env-paths": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz", + "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/esbuild": { "version": "0.17.19", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.19.tgz", diff --git a/package.json b/package.json index 32175204..83ddd542 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@napi-rs/simple-git": "^0.1.8", "chalk": "^4.1.2", "cli-spinner": "^0.2.10", + "env-paths": "^3.0.0", "esbuild-sass-plugin": "^2.9.0", "github-slugger": "^2.0.0", "globby": "^13.1.4", diff --git a/quartz/bootstrap.mjs b/quartz/bootstrap.mjs index 4886e3da..16a0c695 100755 --- a/quartz/bootstrap.mjs +++ b/quartz/bootstrap.mjs @@ -1,6 +1,7 @@ #!/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' @@ -61,9 +62,34 @@ yargs(hideBin(process.argv)) jsx: "automatic", jsxImportSource: "preact", external: ["@napi-rs/simple-git", "shiki"], - plugins: [sassPlugin({ - type: 'css-text' - })] + 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)}`) diff --git a/quartz/components/Head.tsx b/quartz/components/Head.tsx index 868294dd..29050a79 100644 --- a/quartz/components/Head.tsx +++ b/quartz/components/Head.tsx @@ -8,10 +8,9 @@ export interface HeadProps { externalResources: StaticResources } -export default function({ title, description, slug, externalResources }: HeadProps) { +export function Component({ title, description, slug, externalResources }: HeadProps) { const { css, js } = externalResources const baseDir = resolveToRoot(slug) - const stylePath = baseDir + "/index.css" const iconPath = baseDir + "/static/icon.png" const ogImagePath = baseDir + "/static/og-image.png" return @@ -28,16 +27,7 @@ export default function({ title, description, slug, externalResources }: HeadPro - {css.map(href => )} - {js.filter(resource => resource.loadTime === "beforeDOMReady").map(resource =>