@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
4
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
6
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
7
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
3
|
import * as React from 'react';
|
|
9
4
|
import { create, insertMultiple, search as oramaSearch } from '@orama/orama';
|
|
10
5
|
import { pluginQPS } from '@orama/plugin-qps';
|
|
@@ -12,13 +7,11 @@ import { stemmer, language } from '@orama/stemmers/english';
|
|
|
12
7
|
import { stopwords as englishStopwords } from '@orama/stopwords/english';
|
|
13
8
|
// https://github.com/oramasearch/orama/blob/main/packages/stopwords/lib/en.js
|
|
14
9
|
// Removed words that might be meaningful in a software documentation context
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
word !== 'between' && word !== 'before' && word !== 'after' && word !== 'above' && word !== 'below' && word !== 'once' && word !== 'then' && word !== 'where' && word !== 'to' && word !== 'from' && word !== 'up' && word !== 'down' && word !== 'in' && word !== 'out' && word !== 'on' && word !== 'off' && word !== 'over' && word !== 'under';
|
|
21
|
-
});
|
|
10
|
+
const stopWords = englishStopwords.filter(word => word !== 'about' && word !== 'but' &&
|
|
11
|
+
// start of button
|
|
12
|
+
word !== 'for' &&
|
|
13
|
+
// part of form
|
|
14
|
+
word !== 'between' && word !== 'before' && word !== 'after' && word !== 'above' && word !== 'below' && word !== 'once' && word !== 'then' && word !== 'where' && word !== 'to' && word !== 'from' && word !== 'up' && word !== 'down' && word !== 'in' && word !== 'out' && word !== 'on' && word !== 'off' && word !== 'over' && word !== 'under');
|
|
22
15
|
|
|
23
16
|
/**
|
|
24
17
|
* Type for our search document structure
|
|
@@ -27,7 +20,7 @@ var stopWords = englishStopwords.filter(function (word) {
|
|
|
27
20
|
/**
|
|
28
21
|
* Orama schema definition for our search document
|
|
29
22
|
*/
|
|
30
|
-
|
|
23
|
+
const searchSchema = {
|
|
31
24
|
type: 'string',
|
|
32
25
|
group: 'string',
|
|
33
26
|
title: 'string',
|
|
@@ -42,7 +35,7 @@ var searchSchema = {
|
|
|
42
35
|
sections: 'string',
|
|
43
36
|
subsections: 'string',
|
|
44
37
|
part: 'string',
|
|
45
|
-
|
|
38
|
+
export: 'string',
|
|
46
39
|
props: 'string',
|
|
47
40
|
dataAttributes: 'string',
|
|
48
41
|
cssVariables: 'string',
|
|
@@ -58,39 +51,33 @@ var searchSchema = {
|
|
|
58
51
|
* Default function to flatten a sitemap page into search results
|
|
59
52
|
*/
|
|
60
53
|
function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSections, generateSlug) {
|
|
61
|
-
|
|
62
|
-
var results = [];
|
|
54
|
+
const results = [];
|
|
63
55
|
|
|
64
56
|
// Extract top-level sections and all subsections with their slugs
|
|
65
57
|
// Re-slugify from titles using the provided slugify function to match actual page IDs
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
const sections = [];
|
|
59
|
+
const subsections = [];
|
|
68
60
|
if (page.sections) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
originalSlug = _Object$entries$_i[0],
|
|
72
|
-
sectionInfo = _Object$entries$_i[1];
|
|
61
|
+
// Top-level sections are the direct children
|
|
62
|
+
for (const [originalSlug, sectionInfo] of Object.entries(page.sections)) {
|
|
73
63
|
// Use generateSlug if provided, otherwise use the original slug from sitemap
|
|
74
|
-
|
|
64
|
+
const slug = generateSlug ? generateSlug(sectionInfo.title, []) : originalSlug;
|
|
75
65
|
sections.push({
|
|
76
66
|
title: sectionInfo.title,
|
|
77
|
-
slug
|
|
67
|
+
slug
|
|
78
68
|
});
|
|
79
69
|
|
|
80
70
|
// Subsections are all nested children (recursively)
|
|
81
71
|
if (sectionInfo.children && Object.keys(sectionInfo.children).length > 0) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
for (
|
|
85
|
-
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
86
|
-
childOriginalSlug = _Object$entries2$_i[0],
|
|
87
|
-
childData = _Object$entries2$_i[1];
|
|
72
|
+
const extractWithSlugs = (hierarchy, parentSlugs, parentTitles) => {
|
|
73
|
+
const items = [];
|
|
74
|
+
for (const [childOriginalSlug, childData] of Object.entries(hierarchy)) {
|
|
88
75
|
// Use generateSlug if provided, otherwise use the original slug from sitemap
|
|
89
76
|
// When generateSlug is provided, pass parent titles for context
|
|
90
77
|
// (e.g., for Releases pages: v1.0.0-rc.0-autocomplete)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
const childSlug = generateSlug ? generateSlug(childData.title, parentTitles) : childOriginalSlug;
|
|
79
|
+
const currentSlugs = [...parentSlugs, childSlug];
|
|
80
|
+
const currentTitles = [...parentTitles, childData.title];
|
|
94
81
|
items.push({
|
|
95
82
|
title: childData.title,
|
|
96
83
|
slug: childSlug,
|
|
@@ -98,66 +85,57 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
|
|
|
98
85
|
parentTitles: currentTitles
|
|
99
86
|
});
|
|
100
87
|
if (childData.children && Object.keys(childData.children).length > 0) {
|
|
101
|
-
items.push
|
|
88
|
+
items.push(...extractWithSlugs(childData.children, currentSlugs, currentTitles));
|
|
102
89
|
}
|
|
103
90
|
}
|
|
104
91
|
return items;
|
|
105
92
|
};
|
|
106
|
-
subsections.push
|
|
93
|
+
subsections.push(...extractWithSlugs(sectionInfo.children, [slug], [sectionInfo.title]));
|
|
107
94
|
}
|
|
108
|
-
};
|
|
109
|
-
// Top-level sections are the direct children
|
|
110
|
-
for (var _i = 0, _Object$entries = Object.entries(page.sections); _i < _Object$entries.length; _i++) {
|
|
111
|
-
_loop();
|
|
112
95
|
}
|
|
113
96
|
}
|
|
114
|
-
|
|
115
|
-
if (
|
|
97
|
+
const flattened = {};
|
|
98
|
+
if (page.keywords?.length) {
|
|
116
99
|
flattened.keywords = page.keywords.join(' ');
|
|
117
100
|
}
|
|
118
101
|
if (sections.length > 0) {
|
|
119
|
-
flattened.sections = sections.map(
|
|
120
|
-
return s.title;
|
|
121
|
-
}).join(' ');
|
|
102
|
+
flattened.sections = sections.map(s => s.title).join(' ');
|
|
122
103
|
}
|
|
123
104
|
if (subsections.length > 0) {
|
|
124
|
-
flattened.subsections = subsections.map(
|
|
125
|
-
return s.title;
|
|
126
|
-
}).join(' ');
|
|
105
|
+
flattened.subsections = subsections.map(s => s.title).join(' ');
|
|
127
106
|
}
|
|
128
107
|
|
|
129
108
|
// Add base page result
|
|
130
|
-
results.push(
|
|
109
|
+
results.push({
|
|
131
110
|
type: 'page',
|
|
132
|
-
group: includeCategoryInGroup ?
|
|
111
|
+
group: includeCategoryInGroup ? `${sectionData.title} Pages` : 'Pages',
|
|
133
112
|
page: page.title,
|
|
134
113
|
title: page.title,
|
|
135
114
|
slug: page.slug,
|
|
136
115
|
path: page.path,
|
|
137
116
|
description: page.description,
|
|
138
117
|
sectionTitle: sectionData.title,
|
|
139
|
-
prefix: sectionData.prefix
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
118
|
+
prefix: sectionData.prefix,
|
|
119
|
+
...(flattened.keywords ? {
|
|
120
|
+
keywords: flattened.keywords
|
|
121
|
+
} : {}),
|
|
122
|
+
...(excludeSections ? {} : {
|
|
123
|
+
sections: flattened.sections,
|
|
124
|
+
subsections: flattened.subsections
|
|
125
|
+
})
|
|
126
|
+
});
|
|
146
127
|
|
|
147
128
|
// Add entries for each part
|
|
148
129
|
if (page.parts && Object.keys(page.parts).length > 0) {
|
|
149
|
-
for (
|
|
150
|
-
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
151
|
-
partName = _Object$entries3$_i[0],
|
|
152
|
-
partData = _Object$entries3$_i[1];
|
|
130
|
+
for (const [partName, partData] of Object.entries(page.parts)) {
|
|
153
131
|
results.push({
|
|
154
132
|
type: 'part',
|
|
155
133
|
group: 'API Reference',
|
|
156
134
|
part: partName,
|
|
157
|
-
|
|
135
|
+
export: `${page.slug}.${partName}`,
|
|
158
136
|
slug: partName.toLowerCase(),
|
|
159
137
|
path: page.path,
|
|
160
|
-
title: page.title ?
|
|
138
|
+
title: page.title ? `${page.title} ‣ ${partName}` : partName,
|
|
161
139
|
description: page.description,
|
|
162
140
|
sectionTitle: sectionData.title,
|
|
163
141
|
prefix: sectionData.prefix,
|
|
@@ -171,16 +149,13 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
|
|
|
171
149
|
|
|
172
150
|
// Add entries for each export
|
|
173
151
|
if (page.exports && Object.keys(page.exports).length > 0) {
|
|
174
|
-
for (
|
|
175
|
-
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
176
|
-
exportName = _Object$entries4$_i[0],
|
|
177
|
-
exportData = _Object$entries4$_i[1];
|
|
152
|
+
for (const [exportName, exportData] of Object.entries(page.exports)) {
|
|
178
153
|
// If export name matches page slug (case-insensitive), use #api-reference
|
|
179
|
-
|
|
154
|
+
const exportSlug = exportName.toLowerCase() === page.slug.toLowerCase() ? 'api-reference' : exportName.toLowerCase();
|
|
180
155
|
results.push({
|
|
181
156
|
type: 'export',
|
|
182
157
|
group: 'API Reference',
|
|
183
|
-
|
|
158
|
+
export: exportSlug,
|
|
184
159
|
slug: page.slug,
|
|
185
160
|
path: page.path,
|
|
186
161
|
title: exportName,
|
|
@@ -196,15 +171,14 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
|
|
|
196
171
|
}
|
|
197
172
|
|
|
198
173
|
// Add entries for each section
|
|
199
|
-
for (
|
|
200
|
-
var sectionItem = _sections[_i5];
|
|
174
|
+
for (const sectionItem of sections) {
|
|
201
175
|
results.push({
|
|
202
176
|
type: 'section',
|
|
203
177
|
group: 'Sections',
|
|
204
178
|
section: sectionItem.title,
|
|
205
|
-
slug:
|
|
179
|
+
slug: `${page.slug}#${sectionItem.slug}`,
|
|
206
180
|
path: page.path,
|
|
207
|
-
title: page.title ?
|
|
181
|
+
title: page.title ? `${page.title} ‣ ${sectionItem.title}` : sectionItem.title,
|
|
208
182
|
description: page.description,
|
|
209
183
|
sectionTitle: sectionData.title,
|
|
210
184
|
prefix: sectionData.prefix,
|
|
@@ -213,16 +187,15 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
|
|
|
213
187
|
}
|
|
214
188
|
|
|
215
189
|
// Add entries for each subsection
|
|
216
|
-
for (
|
|
217
|
-
|
|
218
|
-
var fullTitle = subsectionItem.parentTitles.join(' ‣ ');
|
|
190
|
+
for (const subsectionItem of subsections) {
|
|
191
|
+
const fullTitle = subsectionItem.parentTitles.join(' ‣ ');
|
|
219
192
|
results.push({
|
|
220
193
|
type: 'subsection',
|
|
221
194
|
group: 'Sections',
|
|
222
195
|
subsection: fullTitle,
|
|
223
|
-
slug:
|
|
196
|
+
slug: `${page.slug}#${subsectionItem.slug.toLowerCase()}`,
|
|
224
197
|
path: page.path,
|
|
225
|
-
title: page.title ?
|
|
198
|
+
title: page.title ? `${page.title} ‣ ${fullTitle}` : fullTitle,
|
|
226
199
|
description: page.description,
|
|
227
200
|
sectionTitle: sectionData.title,
|
|
228
201
|
prefix: sectionData.prefix,
|
|
@@ -236,7 +209,7 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
|
|
|
236
209
|
* Default function to format search results
|
|
237
210
|
*/
|
|
238
211
|
function defaultFormatResult(hit) {
|
|
239
|
-
|
|
212
|
+
const base = {
|
|
240
213
|
id: hit.id,
|
|
241
214
|
title: hit.document.title,
|
|
242
215
|
description: hit.document.description,
|
|
@@ -247,50 +220,57 @@ function defaultFormatResult(hit) {
|
|
|
247
220
|
score: hit.score,
|
|
248
221
|
keywords: hit.document.keywords
|
|
249
222
|
};
|
|
250
|
-
|
|
223
|
+
const type = hit.document.type;
|
|
251
224
|
if (type === 'part') {
|
|
252
|
-
return
|
|
225
|
+
return {
|
|
226
|
+
...base,
|
|
253
227
|
type: 'part',
|
|
254
228
|
part: hit.document.part,
|
|
255
|
-
|
|
229
|
+
export: hit.document.export,
|
|
256
230
|
props: hit.document.props,
|
|
257
231
|
dataAttributes: hit.document.dataAttributes,
|
|
258
232
|
cssVariables: hit.document.cssVariables
|
|
259
|
-
}
|
|
233
|
+
};
|
|
260
234
|
}
|
|
261
235
|
if (type === 'export') {
|
|
262
|
-
return
|
|
236
|
+
return {
|
|
237
|
+
...base,
|
|
263
238
|
type: 'export',
|
|
264
|
-
|
|
239
|
+
export: hit.document.export,
|
|
265
240
|
props: hit.document.props,
|
|
266
241
|
dataAttributes: hit.document.dataAttributes,
|
|
267
242
|
cssVariables: hit.document.cssVariables
|
|
268
|
-
}
|
|
243
|
+
};
|
|
269
244
|
}
|
|
270
245
|
if (type === 'section') {
|
|
271
|
-
return
|
|
246
|
+
return {
|
|
247
|
+
...base,
|
|
272
248
|
type: 'section',
|
|
273
249
|
section: hit.document.section
|
|
274
|
-
}
|
|
250
|
+
};
|
|
275
251
|
}
|
|
276
252
|
if (type === 'subsection') {
|
|
277
|
-
return
|
|
253
|
+
return {
|
|
254
|
+
...base,
|
|
278
255
|
type: 'subsection',
|
|
279
256
|
subsection: hit.document.subsection
|
|
280
|
-
}
|
|
257
|
+
};
|
|
281
258
|
}
|
|
282
259
|
|
|
283
260
|
// Default to page type
|
|
284
|
-
return
|
|
261
|
+
return {
|
|
262
|
+
...base,
|
|
285
263
|
type: 'page',
|
|
286
|
-
page: hit.document.title
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
264
|
+
page: hit.document.title,
|
|
265
|
+
...(hit.document.sections ? {
|
|
266
|
+
sections: hit.document.sections
|
|
267
|
+
} : {}),
|
|
268
|
+
...(hit.document.subsections ? {
|
|
269
|
+
subsections: hit.document.subsections
|
|
270
|
+
} : {})
|
|
271
|
+
};
|
|
292
272
|
}
|
|
293
|
-
export
|
|
273
|
+
export const defaultSearchBoost = {
|
|
294
274
|
type: 100,
|
|
295
275
|
group: 100,
|
|
296
276
|
slug: 2,
|
|
@@ -300,7 +280,7 @@ export var defaultSearchBoost = {
|
|
|
300
280
|
pageKeywords: 15,
|
|
301
281
|
description: 1.5,
|
|
302
282
|
part: 1.5,
|
|
303
|
-
|
|
283
|
+
export: 1.3,
|
|
304
284
|
sectionTitle: 50,
|
|
305
285
|
section: 3,
|
|
306
286
|
subsection: 2.5,
|
|
@@ -319,329 +299,252 @@ export var defaultSearchBoost = {
|
|
|
319
299
|
* @returns Search state and functions
|
|
320
300
|
*/
|
|
321
301
|
export function useSearch(options) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
tolerance =
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
302
|
+
const {
|
|
303
|
+
sitemap: sitemapImport,
|
|
304
|
+
maxDefaultResults,
|
|
305
|
+
tolerance = 1,
|
|
306
|
+
limit: defaultLimit = 20,
|
|
307
|
+
boost = defaultSearchBoost,
|
|
308
|
+
enableStemming = true,
|
|
309
|
+
generateSlug,
|
|
310
|
+
flattenPage = defaultFlattenPage,
|
|
311
|
+
formatResult = defaultFormatResult
|
|
312
|
+
} = options;
|
|
313
|
+
const [index, setIndex] = React.useState(null);
|
|
314
|
+
const [defaultResults, setDefaultResults] = React.useState({
|
|
315
|
+
results: [],
|
|
316
|
+
count: 0,
|
|
317
|
+
elapsed: {
|
|
318
|
+
raw: 0,
|
|
319
|
+
formatted: '0ms'
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const [results, setResults] = React.useState({
|
|
323
|
+
results: [],
|
|
324
|
+
count: 0,
|
|
325
|
+
elapsed: {
|
|
326
|
+
raw: 0,
|
|
327
|
+
formatted: '0ms'
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
React.useEffect(() => {
|
|
331
|
+
(async () => {
|
|
332
|
+
const {
|
|
333
|
+
sitemap
|
|
334
|
+
} = await sitemapImport();
|
|
335
|
+
if (!sitemap) {
|
|
336
|
+
console.error('Sitemap is undefined');
|
|
337
|
+
return;
|
|
358
338
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
_yield$sitemapImport = _context.v;
|
|
373
|
-
sitemap = _yield$sitemapImport.sitemap;
|
|
374
|
-
if (sitemap) {
|
|
375
|
-
_context.n = 2;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
console.error('Sitemap is undefined');
|
|
379
|
-
return _context.a(2);
|
|
380
|
-
case 2:
|
|
381
|
-
_context.n = 3;
|
|
382
|
-
return create({
|
|
383
|
-
schema: searchSchema,
|
|
384
|
-
components: enableStemming ? {
|
|
385
|
-
tokenizer: {
|
|
386
|
-
stemming: true,
|
|
387
|
-
language: language,
|
|
388
|
-
stemmer: stemmer,
|
|
389
|
-
stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props'],
|
|
390
|
-
stopWords: stopWords
|
|
391
|
-
}
|
|
392
|
-
} : undefined,
|
|
393
|
-
plugins: [pluginQPS()]
|
|
394
|
-
});
|
|
395
|
-
case 3:
|
|
396
|
-
searchIndex = _context.v;
|
|
397
|
-
// Flatten the sitemap data structure to a single array of pages
|
|
398
|
-
pages = [];
|
|
399
|
-
pageResultsByGroup = {};
|
|
400
|
-
pageResultsCount = 0;
|
|
401
|
-
Object.entries(sitemap.data).forEach(function (_ref2) {
|
|
402
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
403
|
-
_sectionKey = _ref3[0],
|
|
404
|
-
sectionData = _ref3[1];
|
|
405
|
-
(sectionData.pages || []).forEach(function (page) {
|
|
406
|
-
var flattened = flattenPage(page, sectionData, options.includeCategoryInGroup || false, options.excludeSections, generateSlug);
|
|
407
|
-
pages.push.apply(pages, _toConsumableArray(flattened));
|
|
339
|
+
const searchIndex = await create({
|
|
340
|
+
schema: searchSchema,
|
|
341
|
+
components: enableStemming ? {
|
|
342
|
+
tokenizer: {
|
|
343
|
+
stemming: true,
|
|
344
|
+
language,
|
|
345
|
+
stemmer,
|
|
346
|
+
stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props'],
|
|
347
|
+
stopWords
|
|
348
|
+
}
|
|
349
|
+
} : undefined,
|
|
350
|
+
plugins: [pluginQPS()]
|
|
351
|
+
});
|
|
408
352
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
pageResultsCount += 1;
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
});
|
|
353
|
+
// Flatten the sitemap data structure to a single array of pages
|
|
354
|
+
const pages = [];
|
|
355
|
+
const pageResultsByGroup = {};
|
|
356
|
+
let pageResultsCount = 0;
|
|
357
|
+
Object.entries(sitemap.data).forEach(([_sectionKey, sectionData]) => {
|
|
358
|
+
(sectionData.pages || []).forEach(page => {
|
|
359
|
+
const flattened = flattenPage(page, sectionData, options.includeCategoryInGroup || false, options.excludeSections, generateSlug);
|
|
360
|
+
pages.push(...flattened);
|
|
421
361
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
group
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return _context.a(2);
|
|
362
|
+
// Add the first result (page type) to default results, grouped by their group
|
|
363
|
+
if ((maxDefaultResults === undefined || pageResultsCount < maxDefaultResults) && flattened.length > 0) {
|
|
364
|
+
const pageResult = flattened[0];
|
|
365
|
+
const group = pageResult.group || 'Pages';
|
|
366
|
+
if (!pageResultsByGroup[group]) {
|
|
367
|
+
pageResultsByGroup[group] = [];
|
|
368
|
+
}
|
|
369
|
+
pageResultsByGroup[group].push(pageResult);
|
|
370
|
+
pageResultsCount += 1;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Insert a dummy document with all fields to ensure QPS plugin initializes stats for all properties.
|
|
376
|
+
// This is needed because QPS only creates stats for properties that have data inserted.
|
|
377
|
+
// Using empty strings ensures no false matches while still initializing the stats.
|
|
378
|
+
const dummyDoc = {
|
|
379
|
+
type: '',
|
|
380
|
+
group: '',
|
|
381
|
+
title: '',
|
|
382
|
+
description: '',
|
|
383
|
+
slug: '',
|
|
384
|
+
sectionTitle: '',
|
|
385
|
+
prefix: '',
|
|
386
|
+
path: '',
|
|
387
|
+
keywords: '',
|
|
388
|
+
page: '',
|
|
389
|
+
pageKeywords: '',
|
|
390
|
+
sections: '',
|
|
391
|
+
subsections: '',
|
|
392
|
+
part: '',
|
|
393
|
+
export: '',
|
|
394
|
+
props: '',
|
|
395
|
+
dataAttributes: '',
|
|
396
|
+
cssVariables: '',
|
|
397
|
+
section: '',
|
|
398
|
+
subsection: ''
|
|
399
|
+
};
|
|
400
|
+
await insertMultiple(searchIndex, [dummyDoc, ...pages]);
|
|
401
|
+
const pageResultsGrouped = Object.entries(pageResultsByGroup).map(([group, items]) => ({
|
|
402
|
+
group,
|
|
403
|
+
items
|
|
404
|
+
}));
|
|
405
|
+
const defaultResultsValue = {
|
|
406
|
+
results: pageResultsGrouped,
|
|
407
|
+
count: pageResultsCount,
|
|
408
|
+
elapsed: {
|
|
409
|
+
raw: 0,
|
|
410
|
+
formatted: '0ms'
|
|
472
411
|
}
|
|
473
|
-
}
|
|
474
|
-
|
|
412
|
+
};
|
|
413
|
+
setIndex(searchIndex);
|
|
414
|
+
setDefaultResults(defaultResultsValue);
|
|
415
|
+
setResults(defaultResultsValue);
|
|
416
|
+
})();
|
|
475
417
|
}, [sitemapImport, maxDefaultResults, flattenPage, generateSlug, enableStemming, options.includeCategoryInGroup, options.excludeSections]);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
searchResults,
|
|
490
|
-
count,
|
|
491
|
-
elapsed,
|
|
492
|
-
groupedResults,
|
|
493
|
-
formattedResults,
|
|
494
|
-
_args2 = arguments;
|
|
495
|
-
return _regenerator().w(function (_context2) {
|
|
496
|
-
while (1) switch (_context2.n) {
|
|
497
|
-
case 0:
|
|
498
|
-
_ref7 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, facets = _ref7.facets, groupBy = _ref7.groupBy, _ref7$limit = _ref7.limit, limit = _ref7$limit === void 0 ? defaultLimit : _ref7$limit, where = _ref7.where;
|
|
499
|
-
if (!(!index || !value.trim())) {
|
|
500
|
-
_context2.n = 1;
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
setResults(defaultResults);
|
|
504
|
-
return _context2.a(2);
|
|
505
|
-
case 1:
|
|
506
|
-
valueLower = value.toLowerCase(); // Normalize for comparison: convert spaces/hyphens to a common format
|
|
507
|
-
valueNormalized = valueLower.replace(/[-\s]+/g, ' ').trim(); // For longer search terms, skip custom sorting and rely on Orama's scoring
|
|
508
|
-
// The overhead of checking exact/startsWith/contains isn't worth it
|
|
509
|
-
useCustomSort = valueLower.length <= 20; // Cache for computed document properties to avoid repeated string operations
|
|
510
|
-
cache = new Map();
|
|
511
|
-
getDocProps = function getDocProps(doc) {
|
|
512
|
-
var key = doc.slug; // Use slug as cache key since it's unique per document
|
|
513
|
-
var props = cache.get(key);
|
|
514
|
-
if (!props) {
|
|
515
|
-
var titleLower = doc.title.toLowerCase();
|
|
516
|
-
var slugLower = doc.slug.toLowerCase();
|
|
517
|
-
props = {
|
|
518
|
-
titleLower: titleLower,
|
|
519
|
-
slugLower: slugLower,
|
|
520
|
-
slugNormalized: slugLower.replace(/-/g, ' ')
|
|
521
|
-
};
|
|
522
|
-
cache.set(key, props);
|
|
523
|
-
}
|
|
524
|
-
return props;
|
|
525
|
-
};
|
|
526
|
-
_context2.n = 2;
|
|
527
|
-
return oramaSearch(index, {
|
|
528
|
-
term: value,
|
|
529
|
-
facets: facets,
|
|
530
|
-
groupBy: groupBy,
|
|
531
|
-
where: where,
|
|
532
|
-
limit: limit,
|
|
533
|
-
tolerance: tolerance,
|
|
534
|
-
boost: boost,
|
|
535
|
-
sortBy: useCustomSort ? function (_ref8, _ref9) {
|
|
536
|
-
var _ref0 = _slicedToArray(_ref8, 3),
|
|
537
|
-
_ = _ref0[0],
|
|
538
|
-
aScore = _ref0[1],
|
|
539
|
-
aDocument = _ref0[2];
|
|
540
|
-
var _ref1 = _slicedToArray(_ref9, 3),
|
|
541
|
-
__ = _ref1[0],
|
|
542
|
-
bScore = _ref1[1],
|
|
543
|
-
bDocument = _ref1[2];
|
|
544
|
-
var a = getDocProps(aDocument);
|
|
545
|
-
var b = getDocProps(bDocument);
|
|
418
|
+
const search = React.useCallback(async (value, {
|
|
419
|
+
facets,
|
|
420
|
+
groupBy,
|
|
421
|
+
limit = defaultLimit,
|
|
422
|
+
where
|
|
423
|
+
} = {}) => {
|
|
424
|
+
if (!index || !value.trim()) {
|
|
425
|
+
setResults(defaultResults);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const valueLower = value.toLowerCase();
|
|
429
|
+
// Normalize for comparison: convert spaces/hyphens to a common format
|
|
430
|
+
const valueNormalized = valueLower.replace(/[-\s]+/g, ' ').trim();
|
|
546
431
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (aExact !== bExact) {
|
|
551
|
-
return aExact ? -1 : 1;
|
|
552
|
-
}
|
|
432
|
+
// For longer search terms, skip custom sorting and rely on Orama's scoring
|
|
433
|
+
// The overhead of checking exact/startsWith/contains isn't worth it
|
|
434
|
+
const useCustomSort = valueLower.length <= 20;
|
|
553
435
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
436
|
+
// Cache for computed document properties to avoid repeated string operations
|
|
437
|
+
const cache = new Map();
|
|
438
|
+
const getDocProps = doc => {
|
|
439
|
+
const key = doc.slug; // Use slug as cache key since it's unique per document
|
|
440
|
+
let props = cache.get(key);
|
|
441
|
+
if (!props) {
|
|
442
|
+
const titleLower = doc.title.toLowerCase();
|
|
443
|
+
const slugLower = doc.slug.toLowerCase();
|
|
444
|
+
props = {
|
|
445
|
+
titleLower,
|
|
446
|
+
slugLower,
|
|
447
|
+
slugNormalized: slugLower.replace(/-/g, ' ')
|
|
448
|
+
};
|
|
449
|
+
cache.set(key, props);
|
|
450
|
+
}
|
|
451
|
+
return props;
|
|
452
|
+
};
|
|
453
|
+
const searchResults = await oramaSearch(index, {
|
|
454
|
+
term: value,
|
|
455
|
+
facets,
|
|
456
|
+
groupBy,
|
|
457
|
+
where,
|
|
458
|
+
limit,
|
|
459
|
+
tolerance,
|
|
460
|
+
boost,
|
|
461
|
+
sortBy: useCustomSort ? ([_, aScore, aDocument], [__, bScore, bDocument]) => {
|
|
462
|
+
const a = getDocProps(aDocument);
|
|
463
|
+
const b = getDocProps(bDocument);
|
|
560
464
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
465
|
+
// Prioritize exact matches (short-circuit on first match)
|
|
466
|
+
const aExact = a.titleLower === valueLower || a.slugLower === valueLower || a.slugNormalized === valueNormalized;
|
|
467
|
+
const bExact = b.titleLower === valueLower || b.slugLower === valueLower || b.slugNormalized === valueNormalized;
|
|
468
|
+
if (aExact !== bExact) {
|
|
469
|
+
return aExact ? -1 : 1;
|
|
470
|
+
}
|
|
567
471
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
searchResults = _context2.v;
|
|
574
|
-
count = searchResults.count;
|
|
575
|
-
elapsed = searchResults.elapsed;
|
|
576
|
-
if (!searchResults.groups) {
|
|
577
|
-
_context2.n = 3;
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
groupedResults = searchResults.groups.map(function (group) {
|
|
581
|
-
return {
|
|
582
|
-
group: group.values.join(' '),
|
|
583
|
-
items: group.result.map(formatResult)
|
|
584
|
-
};
|
|
585
|
-
});
|
|
586
|
-
setResults({
|
|
587
|
-
results: groupedResults,
|
|
588
|
-
count: count,
|
|
589
|
-
elapsed: elapsed
|
|
590
|
-
});
|
|
591
|
-
return _context2.a(2);
|
|
592
|
-
case 3:
|
|
593
|
-
formattedResults = searchResults.hits.map(formatResult);
|
|
594
|
-
setResults({
|
|
595
|
-
results: [{
|
|
596
|
-
group: 'Default',
|
|
597
|
-
items: formattedResults
|
|
598
|
-
}],
|
|
599
|
-
count: count,
|
|
600
|
-
elapsed: elapsed
|
|
601
|
-
});
|
|
602
|
-
case 4:
|
|
603
|
-
return _context2.a(2);
|
|
472
|
+
// Then prioritize startsWith matches
|
|
473
|
+
const aStartsWith = a.titleLower.startsWith(valueLower) || a.slugNormalized.startsWith(valueNormalized);
|
|
474
|
+
const bStartsWith = b.titleLower.startsWith(valueLower) || b.slugNormalized.startsWith(valueNormalized);
|
|
475
|
+
if (aStartsWith !== bStartsWith) {
|
|
476
|
+
return aStartsWith ? -1 : 1;
|
|
604
477
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
478
|
+
|
|
479
|
+
// Then prioritize contains matches
|
|
480
|
+
const aContains = a.titleLower.includes(valueLower) || a.slugNormalized.includes(valueNormalized);
|
|
481
|
+
const bContains = b.titleLower.includes(valueLower) || b.slugNormalized.includes(valueNormalized);
|
|
482
|
+
if (aContains !== bContains) {
|
|
483
|
+
return aContains ? -1 : 1;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Then sort by score descending
|
|
487
|
+
return bScore - aScore;
|
|
488
|
+
} : undefined
|
|
489
|
+
});
|
|
490
|
+
const count = searchResults.count;
|
|
491
|
+
const elapsed = searchResults.elapsed;
|
|
492
|
+
if (searchResults.groups) {
|
|
493
|
+
const groupedResults = searchResults.groups.map(group => ({
|
|
494
|
+
group: group.values.join(' '),
|
|
495
|
+
items: group.result.map(formatResult)
|
|
496
|
+
}));
|
|
497
|
+
setResults({
|
|
498
|
+
results: groupedResults,
|
|
499
|
+
count,
|
|
500
|
+
elapsed
|
|
501
|
+
});
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const formattedResults = searchResults.hits.map(formatResult);
|
|
505
|
+
setResults({
|
|
506
|
+
results: [{
|
|
507
|
+
group: 'Default',
|
|
508
|
+
items: formattedResults
|
|
509
|
+
}],
|
|
510
|
+
count,
|
|
511
|
+
elapsed
|
|
512
|
+
});
|
|
513
|
+
}, [index, defaultLimit, defaultResults, tolerance, boost, formatResult]);
|
|
611
514
|
|
|
612
515
|
/**
|
|
613
516
|
* Build a URL from a search result
|
|
614
517
|
* Handles path normalization and hash fragments for different result types
|
|
615
518
|
*/
|
|
616
|
-
|
|
617
|
-
|
|
519
|
+
const buildResultUrl = React.useCallback(result => {
|
|
520
|
+
let url = result.path.startsWith('./') ? `${result.prefix}${result.path.replace(/^\.\//, '').replace(/\/page\.mdx$/, '')}` : result.path;
|
|
618
521
|
|
|
619
522
|
// Add hash for non-page types
|
|
620
523
|
if ('type' in result && result.type !== 'page') {
|
|
621
|
-
|
|
524
|
+
let hash;
|
|
622
525
|
if (result.type === 'section' || result.type === 'subsection') {
|
|
623
526
|
// For sections and subsections, extract hash from the slug field
|
|
624
527
|
// which already contains the page slug + hash (e.g., "button#api-reference")
|
|
625
|
-
|
|
528
|
+
const hashIndex = result.slug.indexOf('#');
|
|
626
529
|
hash = hashIndex !== -1 ? result.slug.substring(hashIndex + 1) : '';
|
|
627
530
|
} else if (result.type === 'part') {
|
|
628
531
|
hash = result.part.toLowerCase();
|
|
629
532
|
} else if (result.type === 'export') {
|
|
630
|
-
hash = result
|
|
533
|
+
hash = result.export; // already lowercase or api-reference
|
|
631
534
|
} else {
|
|
632
535
|
hash = '';
|
|
633
536
|
}
|
|
634
537
|
if (hash) {
|
|
635
|
-
url +=
|
|
538
|
+
url += `#${hash}`;
|
|
636
539
|
}
|
|
637
540
|
}
|
|
638
541
|
return url;
|
|
639
542
|
}, []);
|
|
640
543
|
return {
|
|
641
|
-
results
|
|
544
|
+
results,
|
|
642
545
|
isReady: index !== null,
|
|
643
|
-
search
|
|
644
|
-
defaultResults
|
|
645
|
-
buildResultUrl
|
|
546
|
+
search,
|
|
547
|
+
defaultResults,
|
|
548
|
+
buildResultUrl
|
|
646
549
|
};
|
|
647
550
|
}
|