|
1 | 1 | import {readFileSync, writeFileSync} from "fs";
|
2 |
| -import {OutputDir, TargetFile} from "@cparra/apexdocs/lib/settings"; |
| 2 | +import {defineMarkdownConfig, skip} from "@cparra/apexdocs"; |
3 | 3 |
|
4 |
| -function onBeforeFileWrite(file: TargetFile): TargetFile { |
5 |
| - const outputDir: OutputDir = { |
6 |
| - baseDir: file.dir.baseDir, |
7 |
| - fileDir: file.name |
8 |
| - }; |
| 4 | +export default defineMarkdownConfig({ |
| 5 | + sourceDir: 'expression-src', |
| 6 | + targetDir: 'docs/src/app/docs/api', |
| 7 | + scope: ['global'], |
| 8 | + namespace: 'expression', |
| 9 | + documentationRootDir: '/docs/api', |
| 10 | + transformReference: (reference) => { |
| 11 | + return { |
| 12 | + outputDocPath: reference.outputDocPath.replace('.md', '/page.md'), |
| 13 | + referencePath: reference.referencePath.replace('.md', ''), |
| 14 | + }; |
| 15 | + }, |
| 16 | + transformReferenceGuide: () => { |
| 17 | + return skip(); |
| 18 | + }, |
| 19 | + transformDocPage: (docPage) => { |
| 20 | + return { |
| 21 | + frontmatter: { |
| 22 | + nextjs: { |
| 23 | + metadata: { |
| 24 | + title: docPage.source.name, |
| 25 | + description: `Api documentation for the ${docPage.source.name} ${docPage.source.type}}`, |
| 26 | + } |
| 27 | + } |
| 28 | + }, |
| 29 | + }; |
| 30 | + }, |
| 31 | + transformDocs: (docs) => { |
| 32 | + const navFileContents = readFileSync("docs/src/lib/navigation.json", "utf8"); |
| 33 | + const navItems = JSON.parse(navFileContents); |
| 34 | + // Find an object whose title is "Api" |
| 35 | + let apiNavObject = navItems.find((navObject: any) => navObject.title === "Api"); |
| 36 | + apiNavObject = apiNavObject ?? {title: "Api", links: []}; |
9 | 37 |
|
10 |
| - return { |
11 |
| - name: 'page', |
12 |
| - extension: '.md', |
13 |
| - dir: outputDir |
14 |
| - } |
15 |
| -} |
| 38 | + apiNavObject.links = docs.map((doc) => { |
| 39 | + return { |
| 40 | + title: doc.source.name, href: `/docs/api/${doc.outputDocPath.replace('page.md', '').replace(/\/$/, '')}` |
| 41 | + }; |
| 42 | + }); |
16 | 43 |
|
17 |
| -function onAfterProcess(files: TargetFile[]) { |
18 |
| - const navFileContents = readFileSync("docs/src/lib/navigation.json", "utf8"); |
19 |
| - const navItems = JSON.parse(navFileContents); |
20 |
| - // Find an object whose title is "Api" |
21 |
| - let apiNavObject = navItems.find((navObject: any) => navObject.title === "Api"); |
22 |
| - apiNavObject = apiNavObject ?? {title: "Api", links: []}; |
| 44 | + // replace the Api object with the new one (or add it if it didn't exist) |
| 45 | + const newNavItems = navItems.filter((navObject: any) => navObject.title !== "Api"); |
| 46 | + newNavItems.push(apiNavObject); |
23 | 47 |
|
24 |
| - apiNavObject.links = files.filter((file) => file.dir.fileDir !== 'index').map((file) => { |
25 |
| - return {title: file.dir.fileDir, href: `/docs/api/${file.dir.fileDir}`}; |
26 |
| - }); |
| 48 | + // Write the new navigation.json file |
| 49 | + const newNavFileContents = JSON.stringify(newNavItems, null, 2); |
| 50 | + console.log("Writing new navigation.json file"); |
| 51 | + writeFileSync("docs/src/lib/navigation.json", newNavFileContents); |
27 | 52 |
|
28 |
| - // replace the Api object with the new one (or add it if it didn't exist) |
29 |
| - const newNavItems = navItems.filter((navObject: any) => navObject.title !== "Api"); |
30 |
| - newNavItems.push(apiNavObject); |
31 |
| - |
32 |
| - // Write the new navigation.json file |
33 |
| - const newNavFileContents = JSON.stringify(newNavItems, null, 2); |
34 |
| - console.log("Writing new navigation.json file"); |
35 |
| - writeFileSync("docs/src/lib/navigation.json", newNavFileContents); |
36 |
| -} |
37 |
| - |
38 |
| -export default { |
39 |
| - onBeforeFileWrite, |
40 |
| - onAfterProcess |
41 |
| -}; |
| 53 | + return docs; |
| 54 | + }, |
| 55 | +}); |
0 commit comments