aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-04-28 15:23:50 +0200
committerGitHub <[email protected]>2023-04-28 13:23:50 +0000
commit3cfeb3814703d12a9e95ed684fc2c8f94d1f2c72 (patch)
tree0c9f4148244bfd02d9131132366ff59a8b941673 /scripts/apidoc
parent971f36371bf924b334cb7766fd87afa7b484119a (diff)
downloadfaker-3cfeb3814703d12a9e95ed684fc2c8f94d1f2c72.tar.xz
faker-3cfeb3814703d12a9e95ed684fc2c8f94d1f2c72.zip
docs: fix full url to absolute conversion (#2101)
Diffstat (limited to 'scripts/apidoc')
-rw-r--r--scripts/apidoc/fakerClass.ts8
-rw-r--r--scripts/apidoc/markdown.ts4
-rw-r--r--scripts/apidoc/moduleMethods.ts22
-rw-r--r--scripts/apidoc/utils.ts4
4 files changed, 29 insertions, 9 deletions
diff --git a/scripts/apidoc/fakerClass.ts b/scripts/apidoc/fakerClass.ts
index c3a5287d..f8de8653 100644
--- a/scripts/apidoc/fakerClass.ts
+++ b/scripts/apidoc/fakerClass.ts
@@ -2,9 +2,9 @@ import type { DeclarationReflection, ProjectReflection } from 'typedoc';
import { ReflectionKind } from 'typedoc';
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
import { writeApiDocsModule } from './apiDocsWriter';
-import { processModuleMethods } from './moduleMethods';
+import { analyzeModule, processModuleMethods } from './moduleMethods';
import { analyzeSignature } from './signature';
-import { extractDescription, selectApiSignature } from './typedoc';
+import { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';
export function processFakerClass(project: ProjectReflection): ModuleSummary {
@@ -21,7 +21,7 @@ export function processFakerClass(project: ProjectReflection): ModuleSummary {
function processClass(fakerClass: DeclarationReflection): ModuleSummary {
console.log(`Processing Faker class`);
- const comment = extractDescription(fakerClass);
+ const { comment, deprecated } = analyzeModule(fakerClass);
const methods: Method[] = [];
console.debug(`- constructor`);
@@ -29,7 +29,7 @@ function processClass(fakerClass: DeclarationReflection): ModuleSummary {
methods.push(...processModuleMethods(fakerClass, 'faker.'));
- return writeApiDocsModule('Faker', 'faker', comment, undefined, methods);
+ return writeApiDocsModule('Faker', 'faker', comment, deprecated, methods);
}
function processConstructor(fakerClass: DeclarationReflection): Method {
diff --git a/scripts/apidoc/markdown.ts b/scripts/apidoc/markdown.ts
index 8505b51d..1ddd433e 100644
--- a/scripts/apidoc/markdown.ts
+++ b/scripts/apidoc/markdown.ts
@@ -2,7 +2,7 @@ import sanitizeHtml from 'sanitize-html';
import type { MarkdownRenderer } from 'vitepress';
import { createMarkdownRenderer } from 'vitepress';
import vitepressConfig from '../../docs/.vitepress/config';
-import { pathOutputDir } from './utils';
+import { adjustUrls, pathOutputDir } from './utils';
let markdown: MarkdownRenderer;
@@ -57,7 +57,7 @@ export function mdToHtml(md: string, inline: boolean = false): string {
const safeHtml: string = sanitizeHtml(rawHtml, htmlSanitizeOptions);
// Revert some escaped characters for comparison.
if (comparableSanitizedHtml(rawHtml) === comparableSanitizedHtml(safeHtml)) {
- return safeHtml.replace(/https:\/\/(next.)?fakerjs.dev\//g, '/');
+ return adjustUrls(safeHtml);
}
console.debug('Rejected unsafe md:', md);
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts
index 55b1869f..65a62528 100644
--- a/scripts/apidoc/moduleMethods.ts
+++ b/scripts/apidoc/moduleMethods.ts
@@ -15,6 +15,7 @@ import {
selectApiModules,
} from './typedoc';
import type { ModuleSummary } from './utils';
+import { adjustUrls } from './utils';
/**
* Analyzes and writes the documentation for modules and their methods such as `faker.animal.cat()`.
@@ -34,10 +35,9 @@ export function processModules(project: ProjectReflection): ModuleSummary[] {
*/
function processModule(module: DeclarationReflection): ModuleSummary {
const moduleName = extractModuleName(module);
- const moduleFieldName = extractModuleFieldName(module);
console.log(`Processing Module ${moduleName}`);
- const comment = extractDescription(module);
- const deprecated = extractDeprecated(module);
+ const moduleFieldName = extractModuleFieldName(module);
+ const { comment, deprecated } = analyzeModule(module);
const methods = processModuleMethods(module, `faker.${moduleFieldName}.`);
return writeApiDocsModule(
@@ -50,6 +50,22 @@ function processModule(module: DeclarationReflection): ModuleSummary {
}
/**
+ * Analyzes the documentation for a class.
+ *
+ * @param module The class to process.
+ * @returns The class information.
+ */
+export function analyzeModule(module: DeclarationReflection): {
+ comment: string;
+ deprecated: string | undefined;
+} {
+ return {
+ comment: adjustUrls(extractDescription(module)),
+ deprecated: extractDeprecated(module),
+ };
+}
+
+/**
* Processes all api methods of the given class. This does not include the constructor.
*
* @param module The module to process.
diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts
index 79e47507..8a002f49 100644
--- a/scripts/apidoc/utils.ts
+++ b/scripts/apidoc/utils.ts
@@ -43,6 +43,10 @@ export const pathOutputDir = resolve(pathDocsDir, 'api');
// Functions
+export function adjustUrls(description: string): string {
+ return description.replace(/https:\/\/(next.)?fakerjs.dev\//g, '/');
+}
+
export function mapByName<T extends { name: string }, V>(
input: T[],
valueExtractor: (item: T) => V