feat: support emitters defining external resources, emit link from contentindex directly
7 files modified
1 files renamed
| | |
| | | }, |
| | | ], |
| | | } |
| | | } else { |
| | | return {} |
| | | } |
| | | }, |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | const { css, js } = externalResources |
| | | const { css, js, additionalHead } = externalResources |
| | | |
| | | const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) |
| | | const path = url.pathname as FullSlug |
| | |
| | | <link rel="stylesheet" href={googleFontHref(cfg.theme)} /> |
| | | </> |
| | | )} |
| | | <link rel="preconnect" href="https://cdnjs.cloudflare.com" crossOrigin={"anonymous"} /> |
| | | <link rel="preconnect" href="https://cdnjs.cloudflare.com" crossOrigin="anonymous" /> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| | | {/* OG/Twitter meta tags */} |
| | | <meta name="og:site_name" content={cfg.pageTitle}></meta> |
| | |
| | | {js |
| | | .filter((resource) => resource.loadTime === "beforeDOMReady") |
| | | .map((res) => JSResourceToScriptElement(res, true))} |
| | | {additionalHead.map((resource) => { |
| | | if (typeof resource === "function") { |
| | | return resource(fileData) |
| | | } else { |
| | | return resource |
| | | } |
| | | })} |
| | | </head> |
| | | ) |
| | | } |
| | |
| | | }, |
| | | ...staticResources.js, |
| | | ], |
| | | additionalHead: staticResources.additionalHead, |
| | | } |
| | | |
| | | if (fileData.hasMermaidDiagram) { |
| File was renamed from quartz/plugins/emitters/contentIndex.ts |
| | |
| | | |
| | | return emitted |
| | | }, |
| | | externalResources: (ctx) => { |
| | | if (opts?.enableRSS) { |
| | | return { |
| | | additionalHead: [ |
| | | <link |
| | | rel="alternate" |
| | | type="application/rss+xml" |
| | | title="RSS Feed" |
| | | href={`https://${ctx.cfg.configuration.baseUrl}/index.xml`} |
| | | />, |
| | | ], |
| | | } |
| | | } |
| | | }, |
| | | getQuartzComponents: () => [], |
| | | } |
| | | } |
| | |
| | | const staticResources: StaticResources = { |
| | | css: [], |
| | | js: [], |
| | | additionalHead: [], |
| | | } |
| | | |
| | | for (const transformer of ctx.cfg.plugins.transformers) { |
| | | for (const transformer of [...ctx.cfg.plugins.transformers, ...ctx.cfg.plugins.emitters]) { |
| | | const res = transformer.externalResources ? transformer.externalResources(ctx) : {} |
| | | if (res?.js) { |
| | | staticResources.js.push(...res.js) |
| | |
| | | if (res?.css) { |
| | | staticResources.css.push(...res.css) |
| | | } |
| | | if (res?.additionalHead) { |
| | | staticResources.additionalHead.push(...res.additionalHead) |
| | | } |
| | | } |
| | | |
| | | // if serving locally, listen for rebuilds and reload the page |
| | |
| | | }, |
| | | ], |
| | | } |
| | | default: |
| | | return { css: [], js: [] } |
| | | } |
| | | }, |
| | | } |
| | |
| | | } |
| | | |
| | | type OptionType = object | undefined |
| | | type ExternalResourcesFn = (ctx: BuildCtx) => Partial<StaticResources> | undefined |
| | | export type QuartzTransformerPlugin<Options extends OptionType = undefined> = ( |
| | | opts?: Options, |
| | | ) => QuartzTransformerPluginInstance |
| | |
| | | textTransform?: (ctx: BuildCtx, src: string) => string |
| | | markdownPlugins?: (ctx: BuildCtx) => PluggableList |
| | | htmlPlugins?: (ctx: BuildCtx) => PluggableList |
| | | externalResources?: (ctx: BuildCtx) => Partial<StaticResources> |
| | | externalResources?: ExternalResourcesFn |
| | | } |
| | | |
| | | export type QuartzFilterPlugin<Options extends OptionType = undefined> = ( |
| | |
| | | content: ProcessedContent[], |
| | | resources: StaticResources, |
| | | ): Promise<DepGraph<FilePath>> |
| | | externalResources?: ExternalResourcesFn |
| | | } |
| | |
| | | import { randomUUID } from "crypto" |
| | | import { JSX } from "preact/jsx-runtime" |
| | | import { QuartzPluginData } from "../plugins/vfile" |
| | | |
| | | export type JSResource = { |
| | | loadTime: "beforeDOMReady" | "afterDOMReady" |
| | |
| | | export interface StaticResources { |
| | | css: CSSResource[] |
| | | js: JSResource[] |
| | | additionalHead: (JSX.Element | ((pageData: QuartzPluginData) => JSX.Element))[] |
| | | } |