Skip to content

Commit 008aac5

Browse files
author
Maya Arguelles
committed
Apply reference path replacements to search index build scripts.
1 parent 15ff0b2 commit 008aac5

File tree

8 files changed

+12
-6
lines changed

8 files changed

+12
-6
lines changed

public/search-indices/en.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/es.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/hi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/ko.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/zh-Hans.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/pages/_utils-node.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ export const getExampleCode = async (exampleId: string): Promise<string> => {
4040
const assetMigratedCode = code.replaceAll(/\(["']assets/g, "('/assets");
4141
return assetMigratedCode;
4242
};
43+
44+
export const removeNestedReferencePaths = (route: string): string =>
45+
route.replace(/constants\/|types\//, "")

src/pages/_utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { JSDOM } from "jsdom";
1313
import type { JumpToLink, JumpToState } from "../globals/state";
1414
import { categories as referenceCategories } from "../content/reference/config";
1515
import memoize from "lodash/memoize";
16+
import { removeNestedReferencePaths } from "./_utils-node";
1617

1718
interface EntryWithId {
1819
id: string;
@@ -152,7 +153,7 @@ export const getExampleCategory = (slug: string): string =>
152153
slug.split("/")[1].split("_").splice(1).join(" ");
153154

154155
export const normalizeReferenceRoute = (route: string): string =>
155-
removeLocaleAndExtension(route).replace(/constants\/|types\//, "");
156+
removeNestedReferencePaths(removeLocaleAndExtension(route));
156157

157158
export const removeLocaleAndExtension = (id: string): string =>
158159
removeContentFileExt(removeLeadingSlash(removeLocalePrefix(id)));

src/scripts/builders/search.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import keywordExtractor from "keyword-extractor";
1010
import { contentTypes } from "../../globals/globals";
1111
import { supportedLocales as localesWithSearchSupport } from "../../i18n/const";
1212
import type { LanguageName } from "keyword-extractor/types/lib/keyword_extractor";
13+
import { removeNestedReferencePaths } from "../../pages/_utils-node";
1314

1415
interface SearchIndex {
1516
[title: string]: {
@@ -236,6 +237,7 @@ export const generateSearchIndex = async (
236237
description = getKeywordsFromContent(content, locale);
237238
break;
238239
case "reference":
240+
relativeUrl = removeNestedReferencePaths(relativeUrl);
239241
title = data.title;
240242
// If the class is something like "p5.Vector"
241243
// we include the class in the title and add an alias for easier searching

0 commit comments

Comments
 (0)