docs on making plugins

This commit is contained in:
Jacky Zhao 2023-08-10 21:16:07 -07:00
parent ad3f7b2d5f
commit cefbca4753
11 changed files with 330 additions and 43 deletions

View file

@ -30,9 +30,8 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
for (const alias of aliases) {
const slug = path.posix.join(dir, alias) as ServerSlug
const fp = (slug + ".html") as FilePath
const redirUrl = resolveRelative(canonicalizeServer(slug), ogSlug)
await emit({
const fp = await emit({
content: `
<!DOCTYPE html>
<html lang="en-us">

View file

@ -98,7 +98,6 @@ function addGlobalPageResources(
componentResources.afterDOMLoaded.push(plausibleScript)
}
// spa
if (cfg.enableSPA) {
componentResources.afterDOMLoaded.push(spaRouterScript)
} else {

View file

@ -88,21 +88,19 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
}
if (opts?.enableSiteMap) {
await emit({
emitted.push(await emit({
content: generateSiteMap(cfg, linkIndex),
slug: "sitemap" as ServerSlug,
ext: ".xml",
})
emitted.push("sitemap.xml" as FilePath)
}))
}
if (opts?.enableRSS) {
await emit({
emitted.push(await emit({
content: generateRSSFeed(cfg, linkIndex),
slug: "index" as ServerSlug,
ext: ".xml",
})
emitted.push("index.xml" as FilePath)
}))
}
const fp = path.join("static", "contentIndex") as ServerSlug
@ -117,12 +115,11 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
}),
)
await emit({
emitted.push(await emit({
content: JSON.stringify(simplifiedIndex),
slug: fp,
ext: ".json",
})
emitted.push(`${fp}.json` as FilePath)
}))
return emitted
},

View file

@ -42,9 +42,7 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
}
const content = renderPage(slug, componentData, opts, externalResources)
const fp = (file.data.slug + ".html") as FilePath
await emit({
const fp = await emit({
content,
slug: file.data.slug!,
ext: ".html",

View file

@ -74,9 +74,7 @@ export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (userOpts) => {
}
const content = renderPage(slug, componentData, opts, externalResources)
const fp = (file.data.slug! + ".html") as FilePath
await emit({
const fp = await emit({
content,
slug: file.data.slug!,
ext: ".html",

View file

@ -80,9 +80,7 @@ export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (userOpts) => {
}
const content = renderPage(slug, componentData, opts, externalResources)
const fp = (file.data.slug + ".html") as FilePath
await emit({
const fp = await emit({
content,
slug: file.data.slug!,
ext: ".html",

View file

@ -15,25 +15,31 @@ export const Latex: QuartzTransformerPlugin<Options> = (opts?: Options) => {
return [remarkMath]
},
htmlPlugins() {
return [engine === "katex" ? [rehypeKatex, { output: "html" }] : [rehypeMathjax]]
if (engine === "katex") {
return [[rehypeKatex, { output: "html" }]]
} else {
return [rehypeMathjax]
}
},
externalResources() {
return engine === "katex"
? {
css: [
// base css
"https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css",
],
js: [
{
// fix copy behaviour: https://github.com/KaTeX/KaTeX/blob/main/contrib/copy-tex/README.md
src: "https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/contrib/copy-tex.min.js",
loadTime: "afterDOMReady",
contentType: "external",
},
],
}
: {}
if (engine === "katex") {
return {
css: [
// base css
"https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css",
],
js: [
{
// fix copy behaviour: https://github.com/KaTeX/KaTeX/blob/main/contrib/copy-tex/README.md
src: "https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/contrib/copy-tex.min.js",
loadTime: "afterDOMReady",
contentType: "external",
},
],
}
} else {
return {}
}
},
}
}