From a3fc2aa40a28a32be70b9010a6f8513eeb00f2c6 Mon Sep 17 00:00:00 2001 From: linozen Date: Sun, 10 Mar 2024 11:12:56 +0100 Subject: [PATCH] feat: add citations transformer plugin --- quartz/plugins/transformers/citations.ts | 33 ++++++++++++++++++++++++ quartz/plugins/transformers/index.ts | 1 + 2 files changed, 34 insertions(+) create mode 100644 quartz/plugins/transformers/citations.ts diff --git a/quartz/plugins/transformers/citations.ts b/quartz/plugins/transformers/citations.ts new file mode 100644 index 000000000..5595e5574 --- /dev/null +++ b/quartz/plugins/transformers/citations.ts @@ -0,0 +1,33 @@ +import rehypeCitation from "rehype-citation" +import { QuartzTransformerPlugin } from "../types" + +export interface Options { + bibliographyFile: string + suppressBibliography: boolean +} + +const defaultOptions: Options = { + bibliographyFile: "./bibliography.bib", + suppressBibliography: false, +} + +export const Citations: QuartzTransformerPlugin | undefined> = (userOpts) => { + const opts = { ...defaultOptions, ...userOpts } + return { + name: "Citations", + htmlPlugins() { + return [ + [ + rehypeCitation, + { + bibliography: opts.bibliographyFile, + suppressBibliography: opts.suppressBibliography, + // Until popovers are implemented to not show for citation links, I + // don't want to link citations + linkCitations: false, + }, + ], + ] + }, + } +} diff --git a/quartz/plugins/transformers/index.ts b/quartz/plugins/transformers/index.ts index e340f10e7..7908c865e 100644 --- a/quartz/plugins/transformers/index.ts +++ b/quartz/plugins/transformers/index.ts @@ -1,5 +1,6 @@ export { FrontMatter } from "./frontmatter" export { GitHubFlavoredMarkdown } from "./gfm" +export { Citations } from "./citations" export { CreatedModifiedDate } from "./lastmod" export { Latex } from "./latex" export { Description } from "./description"