mirror of
https://github.com/alrayyes/wiki.git
synced 2025-06-04 21:23:14 +00:00
plugin integration round 2
This commit is contained in:
parent
a757521313
commit
ad6ce0d73f
29 changed files with 3863 additions and 100 deletions
quartz/plugins/transformers
55
quartz/plugins/transformers/frontmatter.ts
Normal file
55
quartz/plugins/transformers/frontmatter.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { PluggableList } from "unified"
|
||||
import matter from "gray-matter"
|
||||
import remarkFrontmatter from 'remark-frontmatter'
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
|
||||
export interface Options {
|
||||
language: 'yaml' | 'toml',
|
||||
delims: string | string[]
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
language: 'yaml',
|
||||
delims: '---'
|
||||
}
|
||||
|
||||
export class FrontMatter extends QuartzTransformerPlugin {
|
||||
name = "FrontMatter"
|
||||
opts: Options
|
||||
|
||||
constructor(opts?: 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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
htmlPlugins(): PluggableList {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'vfile' {
|
||||
interface DataMap {
|
||||
frontmatter: { [key: string]: any } & {
|
||||
title: string
|
||||
tags: string[]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue