-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
json.ts
33 lines (28 loc) · 826 Bytes
/
json.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json from "../core/loaders/json.ts";
import { merge } from "../core/utils.ts";
import type { Site } from "../core.ts";
export interface Options {
/** The list of extensions used to load files */
extensions: string[] | {
pages: string[];
data: string[];
};
}
// Default options
export const defaults: Options = {
extensions: {
data: [".json"],
pages: [".tmpl.json"],
},
};
/** A plugin to add support for JSON files */
export default function (userOptions?: Partial<Options>) {
const options = merge(defaults, userOptions);
const extensions = Array.isArray(options.extensions)
? { pages: options.extensions, data: options.extensions }
: options.extensions;
return (site: Site) => {
site.loadData(extensions.data, json);
site.loadPages(extensions.pages, json);
};
}