@docfuse/plugins 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/README.zh-CN.md +52 -0
- package/dist/client/kroki.js +221 -0
- package/dist/client/mermaid.js +366 -0
- package/dist/client/plantuml.js +221 -0
- package/dist/diagram.css +195 -0
- package/dist/external-links.d.ts +10 -0
- package/dist/external-links.js +49 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +757 -0
- package/dist/kroki.d.ts +12 -0
- package/dist/kroki.js +293 -0
- package/dist/link-card.d.ts +9 -0
- package/dist/link-card.js +87 -0
- package/dist/math.css +3 -0
- package/dist/math.d.ts +19 -0
- package/dist/math.js +140 -0
- package/dist/mermaid.d.ts +10 -0
- package/dist/mermaid.js +290 -0
- package/dist/pagefind.d.ts +66 -0
- package/dist/pagefind.js +84 -0
- package/dist/plantuml.d.ts +10 -0
- package/dist/plantuml.js +297 -0
- package/dist/reading-time.d.ts +20 -0
- package/dist/reading-time.js +90 -0
- package/package.json +122 -0
package/dist/mermaid.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// src/mermaid/index.ts
|
|
2
|
+
import { defineMarkdownPlugin } from "@docfuse/markdown";
|
|
3
|
+
|
|
4
|
+
// src/shared/diagram.ts
|
|
5
|
+
import { visit } from "unist-util-visit";
|
|
6
|
+
function displayKind(kind) {
|
|
7
|
+
if (kind === "plantuml") return "PlantUML";
|
|
8
|
+
return kind.charAt(0).toUpperCase() + kind.slice(1);
|
|
9
|
+
}
|
|
10
|
+
var DIAGRAM_LABELS = {
|
|
11
|
+
en: {
|
|
12
|
+
copy: "Copy source",
|
|
13
|
+
source: "Show source",
|
|
14
|
+
preview: "Show preview",
|
|
15
|
+
expand: "Expand diagram",
|
|
16
|
+
close: "Close expanded diagram",
|
|
17
|
+
controls: "Diagram zoom controls",
|
|
18
|
+
zoomOut: "Zoom out",
|
|
19
|
+
zoomReset: "Reset zoom",
|
|
20
|
+
zoomIn: "Zoom in",
|
|
21
|
+
imageAlt: (kind) => `${displayKind(kind)} diagram`,
|
|
22
|
+
loadingPreview: "Diagram preview loads in the browser."
|
|
23
|
+
},
|
|
24
|
+
zh: {
|
|
25
|
+
copy: "\u590D\u5236\u56FE\u8868\u6E90\u7801",
|
|
26
|
+
source: "\u663E\u793A\u56FE\u8868\u6E90\u7801",
|
|
27
|
+
preview: "\u663E\u793A\u56FE\u8868\u9884\u89C8",
|
|
28
|
+
expand: "\u653E\u5927\u56FE\u8868",
|
|
29
|
+
close: "\u5173\u95ED\u56FE\u8868\u9884\u89C8",
|
|
30
|
+
controls: "\u56FE\u8868\u7F29\u653E\u63A7\u4EF6",
|
|
31
|
+
zoomOut: "\u7F29\u5C0F\u56FE\u8868",
|
|
32
|
+
zoomReset: "\u91CD\u7F6E\u56FE\u8868\u7F29\u653E",
|
|
33
|
+
zoomIn: "\u653E\u5927\u56FE\u8868",
|
|
34
|
+
imageAlt: (kind) => `${displayKind(kind)} \u56FE\u8868`,
|
|
35
|
+
loadingPreview: "\u56FE\u8868\u9884\u89C8\u5C06\u5728\u6D4F\u89C8\u5668\u4E2D\u52A0\u8F7D\u3002"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function labelsFromFile(file) {
|
|
39
|
+
if (!file || typeof file !== "object" || !("data" in file)) return DIAGRAM_LABELS.en;
|
|
40
|
+
const data = file.data;
|
|
41
|
+
if (!data || typeof data !== "object" || !("docfuseLocale" in data)) return DIAGRAM_LABELS.en;
|
|
42
|
+
const locale = typeof data.docfuseLocale === "string" ? data.docfuseLocale.toLowerCase() : "";
|
|
43
|
+
return locale === "zh" || locale.startsWith("zh-") ? DIAGRAM_LABELS.zh : DIAGRAM_LABELS.en;
|
|
44
|
+
}
|
|
45
|
+
function languageOf(node) {
|
|
46
|
+
const code = node.children.find(
|
|
47
|
+
(child) => child.type === "element" && child.tagName === "code"
|
|
48
|
+
);
|
|
49
|
+
if (!code) return void 0;
|
|
50
|
+
const classes = Array.isArray(code.properties.className) ? code.properties.className : [];
|
|
51
|
+
const language = classes.map(String).find((className) => className.startsWith("language-"))?.slice("language-".length).toLowerCase();
|
|
52
|
+
const source = code.children.filter((child) => child.type === "text").map((child) => child.value).join("");
|
|
53
|
+
return language ? { language, source } : void 0;
|
|
54
|
+
}
|
|
55
|
+
function action(name, label, properties = {}) {
|
|
56
|
+
return {
|
|
57
|
+
type: "element",
|
|
58
|
+
tagName: "button",
|
|
59
|
+
properties: { type: "button", dataDfDiagramAction: name, ariaLabel: label, ...properties },
|
|
60
|
+
children: [{ type: "text", value: label }]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function zoomControl(name, label) {
|
|
64
|
+
return {
|
|
65
|
+
type: "element",
|
|
66
|
+
tagName: "button",
|
|
67
|
+
properties: { type: "button", dataDfDiagramAction: name, ariaLabel: label, title: label },
|
|
68
|
+
children: [{ type: "text", value: label }]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function diagramFence(options) {
|
|
72
|
+
return () => (tree, file) => {
|
|
73
|
+
const labels = labelsFromFile(file);
|
|
74
|
+
visit(tree, "element", (node, index, parent) => {
|
|
75
|
+
if (!parent || index === void 0 || node.tagName !== "pre") return;
|
|
76
|
+
const fence = languageOf(node);
|
|
77
|
+
if (!fence || !options.languages.has(fence.language)) return;
|
|
78
|
+
const imageUrl = options.imageUrl?.(fence.source, fence.language);
|
|
79
|
+
const hasVisualPreview = Boolean(imageUrl || options.kind === "mermaid");
|
|
80
|
+
const preview = imageUrl ? {
|
|
81
|
+
type: "element",
|
|
82
|
+
tagName: "img",
|
|
83
|
+
properties: {
|
|
84
|
+
className: ["df-diagram-img"],
|
|
85
|
+
src: imageUrl,
|
|
86
|
+
alt: labels.imageAlt(options.kind),
|
|
87
|
+
loading: "lazy"
|
|
88
|
+
},
|
|
89
|
+
children: []
|
|
90
|
+
} : {
|
|
91
|
+
type: "element",
|
|
92
|
+
tagName: "div",
|
|
93
|
+
properties: { className: ["df-diagram-placeholder"] },
|
|
94
|
+
children: [{ type: "text", value: labels.loadingPreview }]
|
|
95
|
+
};
|
|
96
|
+
parent.children[index] = {
|
|
97
|
+
type: "element",
|
|
98
|
+
tagName: "figure",
|
|
99
|
+
properties: {
|
|
100
|
+
className: ["df-diagram-window"],
|
|
101
|
+
dataDfPluginDiagram: options.kind,
|
|
102
|
+
dataDfSource: fence.source,
|
|
103
|
+
...options.moduleUrl ? { dataDfModuleUrl: options.moduleUrl } : {}
|
|
104
|
+
},
|
|
105
|
+
children: [
|
|
106
|
+
{
|
|
107
|
+
type: "element",
|
|
108
|
+
tagName: "figcaption",
|
|
109
|
+
properties: { className: ["df-diagram-toolbar"] },
|
|
110
|
+
children: [
|
|
111
|
+
{
|
|
112
|
+
type: "element",
|
|
113
|
+
tagName: "span",
|
|
114
|
+
properties: { className: ["df-diagram-title"] },
|
|
115
|
+
children: [{ type: "text", value: options.filename(fence.language) }]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
type: "element",
|
|
119
|
+
tagName: "span",
|
|
120
|
+
properties: { className: ["df-diagram-actions"] },
|
|
121
|
+
children: [
|
|
122
|
+
action("copy", labels.copy),
|
|
123
|
+
action("source", labels.source, { dataDfDiagramPreviewLabel: labels.preview }),
|
|
124
|
+
action("expand", labels.expand, { dataDfDiagramCloseLabel: labels.close })
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: "element",
|
|
131
|
+
tagName: "div",
|
|
132
|
+
properties: { className: ["df-diagram-stage"] },
|
|
133
|
+
children: [
|
|
134
|
+
{
|
|
135
|
+
type: "element",
|
|
136
|
+
tagName: "div",
|
|
137
|
+
properties: { className: ["df-diagram-preview"] },
|
|
138
|
+
children: [preview]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: "element",
|
|
142
|
+
tagName: "pre",
|
|
143
|
+
properties: { className: ["df-diagram-source"], hidden: true },
|
|
144
|
+
children: [
|
|
145
|
+
{
|
|
146
|
+
type: "element",
|
|
147
|
+
tagName: "code",
|
|
148
|
+
properties: {},
|
|
149
|
+
children: [{ type: "text", value: fence.source }]
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
...hasVisualPreview ? [
|
|
154
|
+
{
|
|
155
|
+
type: "element",
|
|
156
|
+
tagName: "div",
|
|
157
|
+
properties: {
|
|
158
|
+
className: ["df-diagram-zoom-controls"],
|
|
159
|
+
role: "group",
|
|
160
|
+
ariaLabel: labels.controls
|
|
161
|
+
},
|
|
162
|
+
children: [
|
|
163
|
+
zoomControl("zoom-out", labels.zoomOut),
|
|
164
|
+
zoomControl("zoom-reset", labels.zoomReset),
|
|
165
|
+
zoomControl("zoom-in", labels.zoomIn)
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
] : []
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/shared/markdownSource.ts
|
|
178
|
+
function stripColumns(value, columns) {
|
|
179
|
+
let index = 0;
|
|
180
|
+
let consumed = 0;
|
|
181
|
+
while (index < value.length && consumed < columns) {
|
|
182
|
+
if (value[index] === " ") consumed += 1;
|
|
183
|
+
else if (value[index] === " ") consumed += 4 - consumed % 4;
|
|
184
|
+
else break;
|
|
185
|
+
index += 1;
|
|
186
|
+
}
|
|
187
|
+
return consumed >= columns ? value.slice(index) : void 0;
|
|
188
|
+
}
|
|
189
|
+
function containerContent(line, state) {
|
|
190
|
+
let value = line;
|
|
191
|
+
while (true) {
|
|
192
|
+
const quote = value.match(/^ {0,3}>[ \t]?/);
|
|
193
|
+
if (!quote) break;
|
|
194
|
+
value = value.slice(quote[0].length);
|
|
195
|
+
}
|
|
196
|
+
const continued = state.listIndent > 0 ? stripColumns(value, state.listIndent) : void 0;
|
|
197
|
+
const content = continued ?? value;
|
|
198
|
+
const item = content.match(/^ {0,3}(?:[-+*]|\d{1,9}[.)])([ \t]+)(.*)$/);
|
|
199
|
+
if (item) {
|
|
200
|
+
const body = item[2] ?? "";
|
|
201
|
+
state.listIndent = (continued === void 0 ? 0 : state.listIndent) + content.length - body.length;
|
|
202
|
+
return body;
|
|
203
|
+
}
|
|
204
|
+
if (continued !== void 0 || value.trim() === "") return content;
|
|
205
|
+
state.listIndent = 0;
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
function openingFence(line) {
|
|
209
|
+
const match = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
210
|
+
if (!match?.[1]) return void 0;
|
|
211
|
+
const marker = match[1][0];
|
|
212
|
+
const info = match[2]?.trim() ?? "";
|
|
213
|
+
if (marker === "`" && info.includes("`")) return void 0;
|
|
214
|
+
return {
|
|
215
|
+
marker,
|
|
216
|
+
size: match[1].length,
|
|
217
|
+
language: info.split(/\s+/, 1)[0]?.toLowerCase() ?? ""
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function closesFence(line, fence) {
|
|
221
|
+
const match = line.match(/^ {0,3}(`+|~+)[ \t]*$/);
|
|
222
|
+
return Boolean(match?.[1]?.[0] === fence.marker && match[1].length >= fence.size);
|
|
223
|
+
}
|
|
224
|
+
function hasMarkdownFenceLanguage(source, languages) {
|
|
225
|
+
let open;
|
|
226
|
+
const container = { listIndent: 0 };
|
|
227
|
+
for (const line of source.split(/\r?\n/)) {
|
|
228
|
+
const content = containerContent(line, container);
|
|
229
|
+
if (open) {
|
|
230
|
+
if (closesFence(content, open)) open = void 0;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const fence = openingFence(content);
|
|
234
|
+
if (!fence) continue;
|
|
235
|
+
if (languages.has(fence.language)) return true;
|
|
236
|
+
open = fence;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/mermaid/index.ts
|
|
242
|
+
var PLUGIN_VERSION = "3";
|
|
243
|
+
function mermaid(options = {}) {
|
|
244
|
+
const moduleUrl = options.moduleUrl?.trim();
|
|
245
|
+
return defineMarkdownPlugin({
|
|
246
|
+
name: "mermaid",
|
|
247
|
+
version: PLUGIN_VERSION,
|
|
248
|
+
cacheKey: { moduleUrl: moduleUrl ?? null },
|
|
249
|
+
browserCompiler: {
|
|
250
|
+
module: "@docfuse/plugins/mermaid",
|
|
251
|
+
exportName: "mermaid",
|
|
252
|
+
options: moduleUrl ? { moduleUrl } : {}
|
|
253
|
+
},
|
|
254
|
+
fenceLanguages: ["mermaid"],
|
|
255
|
+
appliesTo: ({ source }) => hasMarkdownFenceLanguage(source, /* @__PURE__ */ new Set(["mermaid"])),
|
|
256
|
+
assets: {
|
|
257
|
+
clients: [
|
|
258
|
+
{
|
|
259
|
+
id: "mermaid",
|
|
260
|
+
module: "@docfuse/plugins/client/mermaid",
|
|
261
|
+
resources: [
|
|
262
|
+
{
|
|
263
|
+
module: "mermaid/dist/mermaid.esm.min.mjs",
|
|
264
|
+
output: "mermaid.esm.min.mjs",
|
|
265
|
+
directories: [
|
|
266
|
+
{
|
|
267
|
+
source: "chunks/mermaid.esm.min",
|
|
268
|
+
output: "chunks/mermaid.esm.min",
|
|
269
|
+
extensions: [".mjs"]
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
styles: [{ id: "diagrams", module: "@docfuse/plugins/diagram.css" }]
|
|
277
|
+
},
|
|
278
|
+
rehypePlugins: [
|
|
279
|
+
diagramFence({
|
|
280
|
+
languages: /* @__PURE__ */ new Set(["mermaid"]),
|
|
281
|
+
kind: "mermaid",
|
|
282
|
+
filename: () => "diagram.mmd",
|
|
283
|
+
...moduleUrl ? { moduleUrl } : {}
|
|
284
|
+
})
|
|
285
|
+
]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
export {
|
|
289
|
+
mermaid
|
|
290
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
interface PagefindOptions {
|
|
2
|
+
includeCharacters?: string;
|
|
3
|
+
keepIndexUrl?: boolean;
|
|
4
|
+
writePlayground?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface PagefindProviderPage {
|
|
7
|
+
search: boolean;
|
|
8
|
+
outputPath: string;
|
|
9
|
+
routePath: string;
|
|
10
|
+
sourceRelativePath: string;
|
|
11
|
+
}
|
|
12
|
+
interface PagefindProviderContext {
|
|
13
|
+
cwd?: string;
|
|
14
|
+
config?: unknown;
|
|
15
|
+
outputRoot: string;
|
|
16
|
+
graph: {
|
|
17
|
+
pages: PagefindProviderPage[];
|
|
18
|
+
};
|
|
19
|
+
publicPathFor(routePath: string): string;
|
|
20
|
+
resolveOutputPath(outputPath: string, label: string): string;
|
|
21
|
+
}
|
|
22
|
+
interface PagefindProvider {
|
|
23
|
+
readonly id: 'pagefind';
|
|
24
|
+
readonly client: 'pagefind';
|
|
25
|
+
readonly version: string;
|
|
26
|
+
readonly cacheKey: Readonly<Required<PagefindOptions>>;
|
|
27
|
+
write(context: PagefindProviderContext): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
interface PagefindIndex {
|
|
30
|
+
addHTMLFile(input: {
|
|
31
|
+
url: string;
|
|
32
|
+
content: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
errors: string[];
|
|
35
|
+
}>;
|
|
36
|
+
writeFiles(input: {
|
|
37
|
+
outputPath: string;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
errors: string[];
|
|
40
|
+
}>;
|
|
41
|
+
deleteIndex(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
interface PagefindApi {
|
|
44
|
+
createIndex(options: {
|
|
45
|
+
includeCharacters: string;
|
|
46
|
+
keepIndexUrl: boolean;
|
|
47
|
+
writePlayground: boolean;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
errors: string[];
|
|
50
|
+
index?: PagefindIndex;
|
|
51
|
+
}>;
|
|
52
|
+
close(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
interface PagefindDependencies {
|
|
55
|
+
pagefindApi: PagefindApi;
|
|
56
|
+
readFile(path: string, encoding: 'utf8'): Promise<string>;
|
|
57
|
+
rm(path: string, options: {
|
|
58
|
+
recursive?: boolean;
|
|
59
|
+
force?: boolean;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
join(...paths: string[]): string;
|
|
62
|
+
}
|
|
63
|
+
declare function writePagefindIndex(context: PagefindProviderContext, resolved: Required<PagefindOptions>, loadDependencies?: () => Promise<PagefindDependencies>): Promise<void>;
|
|
64
|
+
declare function pagefind(options?: PagefindOptions): PagefindProvider;
|
|
65
|
+
|
|
66
|
+
export { type PagefindOptions, type PagefindProvider, type PagefindProviderContext, pagefind, writePagefindIndex };
|
package/dist/pagefind.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/pagefind/index.ts
|
|
2
|
+
var PLUGIN_VERSION = "1";
|
|
3
|
+
var unusedPagefindUiFiles = [
|
|
4
|
+
"pagefind-ui.js",
|
|
5
|
+
"pagefind-ui.css",
|
|
6
|
+
"pagefind-modular-ui.js",
|
|
7
|
+
"pagefind-component-ui.js",
|
|
8
|
+
"pagefind-component-ui.css",
|
|
9
|
+
"pagefind-highlight.js"
|
|
10
|
+
];
|
|
11
|
+
function assertPagefind(errors, action) {
|
|
12
|
+
if (errors.length) throw new Error(`Pagefind ${action} failed:
|
|
13
|
+
${errors.join("\n")}`);
|
|
14
|
+
}
|
|
15
|
+
async function loadPagefindDependencies() {
|
|
16
|
+
const filesystemModule = "node:fs/promises";
|
|
17
|
+
const pathModule = "node:path";
|
|
18
|
+
const pagefindModule = "pagefind";
|
|
19
|
+
const [filesystem, paths, pagefindApi] = await Promise.all([
|
|
20
|
+
import(filesystemModule),
|
|
21
|
+
import(pathModule),
|
|
22
|
+
import(pagefindModule)
|
|
23
|
+
]);
|
|
24
|
+
return {
|
|
25
|
+
pagefindApi,
|
|
26
|
+
readFile: filesystem.readFile,
|
|
27
|
+
rm: filesystem.rm,
|
|
28
|
+
join: paths.join
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function writePagefindIndex(context, resolved, loadDependencies = loadPagefindDependencies) {
|
|
32
|
+
let pagefindApi;
|
|
33
|
+
let index;
|
|
34
|
+
try {
|
|
35
|
+
const dependencies = await loadDependencies();
|
|
36
|
+
pagefindApi = dependencies.pagefindApi;
|
|
37
|
+
const { join, readFile, rm } = dependencies;
|
|
38
|
+
const pagefindRoot = join(context.outputRoot, "pagefind");
|
|
39
|
+
await rm(pagefindRoot, { recursive: true, force: true });
|
|
40
|
+
await rm(join(context.outputRoot, "search"), { recursive: true, force: true });
|
|
41
|
+
const created = await pagefindApi.createIndex(resolved);
|
|
42
|
+
assertPagefind(created.errors, "initialization");
|
|
43
|
+
if (!created.index) throw new Error("Pagefind did not return an index");
|
|
44
|
+
index = created.index;
|
|
45
|
+
for (const page of context.graph.pages.filter((candidate) => candidate.search)) {
|
|
46
|
+
const htmlPath = context.resolveOutputPath(page.outputPath, `search page ${page.outputPath}`);
|
|
47
|
+
const result = await index.addHTMLFile({
|
|
48
|
+
url: context.publicPathFor(page.routePath),
|
|
49
|
+
content: await readFile(htmlPath, "utf8")
|
|
50
|
+
});
|
|
51
|
+
assertPagefind(result.errors, `indexing ${page.sourceRelativePath}`);
|
|
52
|
+
}
|
|
53
|
+
const written = await index.writeFiles({ outputPath: pagefindRoot });
|
|
54
|
+
assertPagefind(written.errors, "write");
|
|
55
|
+
await Promise.all(unusedPagefindUiFiles.map((file) => rm(join(pagefindRoot, file), { force: true })));
|
|
56
|
+
} finally {
|
|
57
|
+
try {
|
|
58
|
+
await index?.deleteIndex();
|
|
59
|
+
} finally {
|
|
60
|
+
await pagefindApi?.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function pagefind(options = {}) {
|
|
65
|
+
const resolved = {
|
|
66
|
+
includeCharacters: options.includeCharacters ?? "._-",
|
|
67
|
+
keepIndexUrl: options.keepIndexUrl ?? false,
|
|
68
|
+
writePlayground: options.writePlayground ?? false
|
|
69
|
+
};
|
|
70
|
+
const provider = Object.freeze({
|
|
71
|
+
id: "pagefind",
|
|
72
|
+
client: "pagefind",
|
|
73
|
+
version: PLUGIN_VERSION,
|
|
74
|
+
cacheKey: resolved,
|
|
75
|
+
async write(context) {
|
|
76
|
+
await writePagefindIndex(context, resolved);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return provider;
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
pagefind,
|
|
83
|
+
writePagefindIndex
|
|
84
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MarkdownPlugin } from '@docfuse/markdown';
|
|
2
|
+
|
|
3
|
+
interface PlantUmlOptions {
|
|
4
|
+
/** PlantUML server base URL. Set to false to keep source-only output. */
|
|
5
|
+
server?: string | false;
|
|
6
|
+
}
|
|
7
|
+
/** Enable PlantUML fenced code blocks as an opt-in official plugin. */
|
|
8
|
+
declare function plantUml(options?: PlantUmlOptions): MarkdownPlugin;
|
|
9
|
+
|
|
10
|
+
export { type PlantUmlOptions, plantUml };
|