Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
52 lines (42 loc) · 1.51 KB
/
Copy pathindex.ts
File metadata and controls
52 lines (42 loc) · 1.51 KB
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
/**
* Docusaurus plugin that checks project documentation against remote tags.
*/
import type { Plugin } from "@docusaurus/types";
import { PROJECTS } from "../../src/data/projects";
import {
DOCUMENTATION_FRESHNESS_PLUGIN_NAME,
type DocumentationFreshnessPluginData,
type DocumentationFreshnessResult,
} from "../../src/data/documentationFreshness";
import { resolveProjectFreshness } from "./resolver";
/** Publish one serializable freshness result for every configured project. */
export default function documentationFreshnessPlugin(): Plugin {
return {
name: DOCUMENTATION_FRESHNESS_PLUGIN_NAME,
async loadContent() {
const entries = await Promise.all(
PROJECTS.map(async (project) => {
const result = await resolveProjectFreshness(project);
return result ? ([project.id, result] as const) : undefined;
})
);
const projects: Record<string, DocumentationFreshnessResult> = {};
for (const entry of entries) {
if (!entry) {
continue;
}
const [projectId, result] = entry;
projects[projectId] = result;
if (result.verification === "fallback") {
console.warn(
`[documentation-freshness] ${projectId}: ${result.errorCode ?? "remote verification failed"}; using ${result.status} fallback status.`
);
}
}
return { projects };
},
contentLoaded({ content, actions }) {
actions.setGlobalData(content as DocumentationFreshnessPluginData);
},
};
}