Skip to content

Commit 42e258b

Browse files
committed
fix(#1999): Organize results to better reflect the sitemap
1 parent 570f289 commit 42e258b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

packages/dev/docs/src/client.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,23 @@ function DocSearch() {
190190
const client = algoliasearch('1V1Q59JVTR', '44a7e2e7508ff185f25ac64c0a675f98');
191191
const searchIndex = client.initIndex('react-spectrum');
192192
const searchOptions = {
193+
distinct: 1,
193194
highlightPreTag: `<mark class="${docsStyle.docSearchBoxMark}">`,
194195
highlightPostTag: '</mark>'
195196
};
196197

198+
const sectionTitles = {
199+
'react-aria': 'React Aria',
200+
'react-spectrum': 'React Spectrum',
201+
'react-stately': 'React Stately',
202+
'internationalized': 'Internationalized',
203+
'blog': 'Blog',
204+
'architecture': 'Architecture',
205+
'contribute': 'Contribute',
206+
'releases': 'Releases',
207+
'support': 'Support'
208+
};
209+
197210
const [searchValue, setSearchValue] = useState('');
198211
const [predictions, setPredictions] = useState(null);
199212
const [suggestions, setSuggestions] = useState(null);
@@ -204,10 +217,21 @@ function DocSearch() {
204217
hits.forEach(prediction => {
205218
let hierarchy = prediction.hierarchy;
206219
let objectID = prediction.objectID;
207-
let lvl0 = hierarchy.lvl0;
208-
let section = sections.find(section => section.title === lvl0);
220+
let url = prediction.url;
221+
let sectionTitle;
222+
for (const [path, title] of Object.entries(sectionTitles)) {
223+
let regexp = new RegExp('^.+//.+/' + path + '[/.].+$', 'i');
224+
if (url.match(regexp)) {
225+
sectionTitle = title;
226+
break;
227+
}
228+
}
229+
if (!sectionTitle) {
230+
sectionTitle = 'Documentation';
231+
}
232+
let section = sections.find(section => section.title === sectionTitle);
209233
if (!section) {
210-
section = {title: lvl0, items: []};
234+
section = {title: sectionTitle, items: []};
211235
sections.push(section);
212236
}
213237
let text = [];
@@ -230,7 +254,10 @@ function DocSearch() {
230254
</Item>
231255
);
232256
});
233-
let suggestions = sections.map((section, index) => <Section key={`${index}-lvl0-${section.title}`} title={section.title}>{section.items}</Section>);
257+
let titles = Object.values(sectionTitles);
258+
sections.forEach((section, index) => console.log(index, section.title, titles.indexOf(section.title)));
259+
sections = sections.sort((a, b) => titles.indexOf(a.title) < titles.indexOf(b.title) ? -1 : 1);
260+
let suggestions = sections.map((section, index) => <Section key={`${index}-${section.title}`} title={section.title}>{section.items}</Section>);
234261
setSuggestions(suggestions);
235262
};
236263

0 commit comments

Comments
 (0)