-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugins.ts
100 lines (91 loc) · 2.83 KB
/
plugins.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import postcss from "lume/plugins/postcss.ts";
import pagefind from "lume/plugins/pagefind.ts";
import resolveUrls from "lume/plugins/resolve_urls.ts";
import nav from "lume/plugins/nav.ts";
import title from "https://deno.land/x/[email protected]/title.ts";
import toc from "https://deno.land/x/[email protected]/toc.ts";
import footnotes from "https://deno.land/x/[email protected]/footnotes.ts";
import prism from "lume/plugins/prism.ts";
import date from "lume/plugins/date.ts";
import basePath from "lume/plugins/base_path.ts";
import favicon, { Options as FaviconOptions } from "lume/plugins/favicon.ts";
import phosphor, {
Options as IconOptions,
} from "https://deno.land/x/[email protected]/phosphor.ts";
import { alert } from "npm:@mdit/[email protected]";
import multilanguage from "lume/plugins/multilanguage.ts";
import "lume/types.ts";
export interface Options {
/**
* Options for the favicon plugin.
*/
favicon?: FaviconOptions;
/**
* Options for the phosphor plugin.
*/
icons?: IconOptions;
/**
* Language options for the multilanguage plugin.
* The first language is the default language.
*/
languages?: string[];
/**
* Language names for the multilanguage plugin.
* The key is the language code and the value is the language name.
* This is used to display the language name in the language switcher.
*/
languageNames?: Record<string, string>;
}
export default function (options: Options = {}) {
return (site: Lume.Site) => {
site.use(nav())
.use(title())
.use(toc())
.use(footnotes())
.use(postcss())
.use(pagefind())
.use(prism())
.use(resolveUrls())
.use(date())
.use(favicon(options.favicon))
.use(basePath())
.data("languages", options.languages || [])
.use(phosphor({
...options.icons,
name: "icon",
}))
.data("layout", "layout.vto")
.data("order", 0)
.mergeKey("extra_head", "stringArray")
.copy("menu.js")
.copy([
".jpg",
".jpeg",
".png",
".webp",
".svg",
".mp4",
".webm",
".gif",
]);
// Multilanguage site
if (options.languages?.length) {
site.use(multilanguage({
languages: options.languages,
defaultLanguage: options.languages[0],
}));
const names = new Map<string, string>();
options.languages.forEach((lang) => {
if (options.languageNames?.[lang]) {
names.set(lang, options.languageNames[lang]);
} else {
const dn = new Intl.DisplayNames(lang, { type: "language" });
names.set(lang, dn.of(lang) || lang);
}
});
site.filter("langName", (lang: string) => names.get(lang) || lang);
}
// Alert plugin
site.hooks.addMarkdownItPlugin(alert);
};
}