Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix api search #1361

Merged
merged 2 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/ApiIndex.vue
Expand Up @@ -84,7 +84,7 @@ function slugify(text: string): string {
<ul>
<li v-for="h of item.headers" :key="h.anchor">
<a :href="item.link + '.html#' + slugify(h.anchor)">{{
h.anchor
h.text
}}</a>
</li>
</ul>
Expand Down
11 changes: 6 additions & 5 deletions scripts/apidoc/apiDocsWriter.ts
Expand Up @@ -5,7 +5,7 @@ import { ReflectionKind } from 'typedoc';
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
import type { APIGroup, APIItem } from '../../docs/api/api-types';
import { selectDirectMethods } from './directMethods';
import { extractModuleName, selectApiModules } from './moduleMethods';
import { extractModuleName, selectApiModules, slugify } from './moduleMethods';
import type { PageIndex } from './utils';
import {
formatMarkdown,
Expand Down Expand Up @@ -167,16 +167,17 @@ export function writeApiSearchIndex(project: ProjectReflection): void {

moduleApiSection.items = [...apiModules, ...directMethods]
.map((module) => {
const moduleName = extractModuleName(module);
const apiSection: APIItem = {
text: extractModuleName(module),
link: module.name.toLowerCase(),
text: moduleName,
link: moduleName.toLowerCase(),
headers: [],
};
if (module.kind !== ReflectionKind.Property) {
apiSection.headers = module
.getChildrenByKind(ReflectionKind.Method)
.map((child) => ({
anchor: child.name,
anchor: slugify(child.name),
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
text: child.name,
}));
} else {
Expand All @@ -187,7 +188,7 @@ export function writeApiSearchIndex(project: ProjectReflection): void {

apiSection.headers = [
{
anchor: module.name,
anchor: slugify(module.name),
text: module.name,
},
];
Expand Down
4 changes: 4 additions & 0 deletions scripts/apidoc/moduleMethods.ts
Expand Up @@ -49,6 +49,10 @@ function extractModuleFieldName(module: DeclarationReflection): string {
return moduleName.substring(0, 1).toLowerCase() + moduleName.substring(1);
}

export function slugify(value: string): string {
return value.toLowerCase().replace(/\_/g, '-');
}

/**
* Analyzes and writes the documentation for a module and its methods such as `faker.animal.cat()`.
*
Expand Down