refactor plugins to be functions instead of classes

This commit is contained in:
Jacky Zhao 2023-06-11 23:26:43 -07:00
parent b8c011410d
commit 352075ae81
20 changed files with 464 additions and 507 deletions
quartz/plugins/transformers

View file

@ -1,4 +1,3 @@
import { PluggableList } from "unified"
import matter from "gray-matter"
import remarkFrontmatter from 'remark-frontmatter'
import { QuartzTransformerPlugin } from "../types"
@ -13,35 +12,30 @@ const defaultOptions: Options = {
delims: '---'
}
export class FrontMatter extends QuartzTransformerPlugin {
name = "FrontMatter"
opts: Options
export const FrontMatter: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
const opts = { ...defaultOptions, ...userOpts }
return {
name: "FrontMatter",
markdownPlugins() {
return [
remarkFrontmatter,
() => {
return (_, file) => {
const { data } = matter(file.value, opts)
constructor(opts?: Partial<Options>) {
super()
this.opts = { ...defaultOptions, ...opts }
}
markdownPlugins(): PluggableList {
return [
remarkFrontmatter,
() => {
return (_, file) => {
const { data } = matter(file.value, this.opts)
// fill in frontmatter
file.data.frontmatter = {
title: file.stem ?? "Untitled",
tags: [],
...data
// fill in frontmatter
file.data.frontmatter = {
title: file.stem ?? "Untitled",
tags: [],
...data
}
}
}
}
]
}
htmlPlugins(): PluggableList {
return []
]
},
htmlPlugins() {
return []
}
}
}