mirror of
https://gitlab.com/MisterBiggs/brain-quartz.git
synced 2025-07-23 06:41:30 +00:00
.github
content
docs
quartz
cli
components
i18n
plugins
emitters
404.tsx
aliases.ts
assets.ts
cname.ts
componentResources.ts
contentIndex.ts
contentPage.tsx
folderPage.tsx
helpers.ts
index.ts
static.ts
tagPage.tsx
filters
transformers
index.ts
types.ts
vfile.ts
processors
static
styles
util
bootstrap-cli.mjs
bootstrap-worker.mjs
build.ts
cfg.ts
depgraph.test.ts
depgraph.ts
worker.ts
.gitattributes
.gitignore
.node-version
.npmrc
.prettierignore
.prettierrc
CODE_OF_CONDUCT.md
Dockerfile
LICENSE.txt
README.md
globals.d.ts
index.d.ts
package-lock.json
package.json
quartz.config.ts
quartz.layout.ts
tsconfig.json
* fix(fast rebuild): call only required emitters, don't always copy assets * Type function
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { FilePath, joinSegments, slugifyFilePath } from "../../util/path"
|
|
import { QuartzEmitterPlugin } from "../types"
|
|
import path from "path"
|
|
import fs from "fs"
|
|
import { glob } from "../../util/glob"
|
|
import DepGraph from "../../depgraph"
|
|
import { Argv } from "../../util/ctx"
|
|
import { QuartzConfig } from "../../cfg"
|
|
|
|
const filesToCopy = async (argv: Argv, cfg: QuartzConfig) => {
|
|
// glob all non MD files in content folder and copy it over
|
|
return await glob("**", argv.directory, ["**/*.md", ...cfg.configuration.ignorePatterns])
|
|
}
|
|
|
|
export const Assets: QuartzEmitterPlugin = () => {
|
|
return {
|
|
name: "Assets",
|
|
getQuartzComponents() {
|
|
return []
|
|
},
|
|
async getDependencyGraph(ctx, _content, _resources) {
|
|
const { argv, cfg } = ctx
|
|
const graph = new DepGraph<FilePath>()
|
|
|
|
const fps = await filesToCopy(argv, cfg)
|
|
|
|
for (const fp of fps) {
|
|
const ext = path.extname(fp)
|
|
const src = joinSegments(argv.directory, fp) as FilePath
|
|
const name = (slugifyFilePath(fp as FilePath, true) + ext) as FilePath
|
|
|
|
const dest = joinSegments(argv.output, name) as FilePath
|
|
|
|
graph.addEdge(src, dest)
|
|
}
|
|
|
|
return graph
|
|
},
|
|
async emit({ argv, cfg }, _content, _resources): Promise<FilePath[]> {
|
|
const assetsPath = argv.output
|
|
const fps = await filesToCopy(argv, cfg)
|
|
const res: FilePath[] = []
|
|
for (const fp of fps) {
|
|
const ext = path.extname(fp)
|
|
const src = joinSegments(argv.directory, fp) as FilePath
|
|
const name = (slugifyFilePath(fp as FilePath, true) + ext) as FilePath
|
|
|
|
const dest = joinSegments(assetsPath, name) as FilePath
|
|
const dir = path.dirname(dest) as FilePath
|
|
await fs.promises.mkdir(dir, { recursive: true }) // ensure dir exists
|
|
await fs.promises.copyFile(src, dest)
|
|
res.push(dest)
|
|
}
|
|
|
|
return res
|
|
},
|
|
}
|
|
}
|