-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapexdocs.config.ts
53 lines (48 loc) · 1.93 KB
/
apexdocs.config.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
import {readFileSync, writeFileSync} from "fs";
import {defineMarkdownConfig, skip} from "@cparra/apexdocs";
export default defineMarkdownConfig({
sourceDir: 'expression-src',
targetDir: 'docs/src/app/docs/api',
scope: ['global'],
namespace: 'expression',
transformReference: (reference) => {
return {
outputDocPath: reference.outputDocPath.replace('.md', '/page.md'),
referencePath: reference.referencePath.replace('.md', ''),
};
},
transformReferenceGuide: () => {
return skip();
},
transformDocPage: (docPage) => {
return {
frontmatter: {
nextjs: {
metadata: {
title: docPage.source.name,
description: `Api documentation for the ${docPage.source.name} ${docPage.source.type}}`,
}
}
},
};
},
transformDocs: (docs) => {
const navFileContents = readFileSync("docs/src/lib/navigation.json", "utf8");
const navItems = JSON.parse(navFileContents);
// Find an object whose title is "Api"
let apiNavObject = navItems.find((navObject: any) => navObject.title === "Api");
apiNavObject = apiNavObject ?? {title: "Api", links: []};
apiNavObject.links = docs.map((doc) => {
return {
title: doc.source.name, href: `/docs/api/${doc.outputDocPath.replace('page.md', '').replace(/\/$/, '')}`
};
});
// replace the Api object with the new one (or add it if it didn't exist)
const newNavItems = navItems.filter((navObject: any) => navObject.title !== "Api");
newNavItems.push(apiNavObject);
// Write the new navigation.json file
const newNavFileContents = JSON.stringify(newNavItems, null, 2);
writeFileSync("docs/src/lib/navigation.json", newNavFileContents);
return docs;
},
});