mirror of
https://gitlab.com/MisterBiggs/brain-quartz.git
synced 2025-08-18 11:24:56 +00:00
.github
content
quartz
components
plugins
processors
static
styles
bootstrap-cli.mjs
bootstrap-worker.mjs
build.ts
cfg.ts
ctx.ts
glob.ts
log.ts
path.test.ts
path.ts
perf.ts
resources.tsx
sourcemap.ts
theme.ts
trace.ts
worker.ts
.gitattributes
.gitignore
.prettierignore
.prettierrc
CODE_OF_CONDUCT.md
LICENSE.txt
README.md
globals.d.ts
index.d.ts
package-lock.json
package.json
quartz.config.ts
quartz.layout.ts
tsconfig.json
40 lines
975 B
TypeScript
40 lines
975 B
TypeScript
import { randomUUID } from "crypto"
|
|
import { JSX } from "preact/jsx-runtime"
|
|
|
|
export type JSResource = {
|
|
loadTime: "beforeDOMReady" | "afterDOMReady"
|
|
moduleType?: "module"
|
|
spaPreserve?: boolean
|
|
} & (
|
|
| {
|
|
src: string
|
|
contentType: "external"
|
|
}
|
|
| {
|
|
script: string
|
|
contentType: "inline"
|
|
}
|
|
)
|
|
|
|
export function JSResourceToScriptElement(resource: JSResource, preserve?: boolean): JSX.Element {
|
|
const scriptType = resource.moduleType ?? "application/javascript"
|
|
const spaPreserve = preserve ?? resource.spaPreserve
|
|
if (resource.contentType === "external") {
|
|
return (
|
|
<script key={resource.src} src={resource.src} type={scriptType} spa-preserve={spaPreserve} />
|
|
)
|
|
} else {
|
|
const content = resource.script
|
|
return (
|
|
<script key={randomUUID()} type={scriptType} spa-preserve={spaPreserve}>
|
|
{content}
|
|
</script>
|
|
)
|
|
}
|
|
}
|
|
|
|
export interface StaticResources {
|
|
css: string[]
|
|
js: JSResource[]
|
|
}
|