mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
- Synced with upstream fumadocs changes - Accepted upstream changes for all conflicts - Deleted files that no longer exist upstream - Maintains @hanzo package namespace
30 lines
691 B
TypeScript
30 lines
691 B
TypeScript
import type { Pluggable } from 'unified';
|
|
import matter from 'gray-matter';
|
|
|
|
export type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
|
|
|
export function pluginOption(
|
|
def: (v: Pluggable[]) => (Pluggable | false | null)[],
|
|
options: ResolvePlugins = [],
|
|
): Pluggable[] {
|
|
const list = def(Array.isArray(options) ? options : []).filter(Boolean) as Pluggable[];
|
|
|
|
if (typeof options === 'function') {
|
|
return options(list);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* Parse frontmatter, currently powered by `gray-matter`
|
|
*/
|
|
export function parseFrontmatter(content: string) {
|
|
const out = matter(content);
|
|
|
|
return {
|
|
frontmatter: out.data,
|
|
content: out.content,
|
|
};
|
|
}
|