From fda44bb899efbcbac2071a199964a3e269cbd805 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sun, 14 Aug 2022 01:59:21 +0800 Subject: docs: rewrite api pages to have a right aside toc (#1265) --- scripts/apidoc/apiDocsWriter.ts | 74 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'scripts/apidoc/apiDocsWriter.ts') diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts index cb803499..76edc3c3 100644 --- a/scripts/apidoc/apiDocsWriter.ts +++ b/scripts/apidoc/apiDocsWriter.ts @@ -26,40 +26,41 @@ editLink: false * @param moduleName The name of the module to write the docs for. * @param lowerModuleName The lowercase name of the module. * @param comment The module comments. + * @param methods The methods of the module. */ export function writeApiDocsModulePage( moduleName: string, lowerModuleName: string, - comment: string + comment: string, + methods: Method[] ): void { // Write api docs page let content = ` - # ${moduleName} - + # ${moduleName} + ::: v-pre ${comment} ::: - + ${methods + .map( + (method) => ` + ## ${method.name} - + + ` + ) + .join('')} `.replace(/\n +/g, '\n'); content = vitePressInFileOptions + formatMarkdown(content); @@ -71,18 +72,26 @@ export function writeApiDocsModulePage( * Writes the api page for the given method to the correct location. * * @param methodName The name of the method to write the docs for. + * @param capitalizedMethodName The capitalized name of the method. */ -export function writeApiDocsDirectPage(methodName: string): void { +export function writeApiDocsDirectPage( + methodName: string, + capitalizedMethodName: string +): void { let content = ` - + + + + # ${capitalizedMethodName} + + ## ${methodName} + + `.replace(/\n +/g, '\n'); content = vitePressInFileOptions + formatMarkdown(content); @@ -100,18 +109,17 @@ export function writeApiDocsData( lowerModuleName: string, methods: Method[] ): void { - let contentTs = ` -import type { Method } from '../.vitepress/components/api-docs/method'; - -export const ${lowerModuleName}: Method[] = ${JSON.stringify( - methods, - null, - 2 - )}`; - - contentTs = formatTypescript(contentTs); - - writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.ts`), contentTs); + const content = JSON.stringify( + methods.reduce>( + (map, method) => ({ + ...map, + [method.name]: method, + }), + {} + ) + ); + + writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.json`), content); } /** -- cgit v1.2.3