Skip to content

Commit

Permalink
docs: enforce string format to ensure Algolia search indexing functio…
Browse files Browse the repository at this point in the history
…ns correctly (#902)

* docs: enforce string format to ensure Algolia search indexing functions correctly

* refactor: improve the string validation function to exclude whitespace-only strings

Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>

---------

Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
  • Loading branch information
cheton and codiumai-pr-agent-free[bot] committed Sep 18, 2024
1 parent 6b77e81 commit 33946eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/react-docs/config/sidebar-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const routes = [
{ title: 'Publishing', path: 'contributing/publishing' },
{ title: 'React Documentation Site', path: 'contributing/react-documentation-site' },
{
title: <Flex columnGap="2x">React Components <sub>PART 1</sub></Flex>,
title: 'React Components - Part 1',
path: 'contributing/react-components-part-1',
},
{
title: <Flex columnGap="2x">React Components <sub>PART 2</sub></Flex>,
title: 'React Components - Part 2',
path: 'contributing/react-components-part-2',
},
],
Expand Down
9 changes: 5 additions & 4 deletions packages/react-docs/scripts/algolia-search-indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ const ZERO_UUID = '00000000-0000-0000-0000-000000000000';

const stateKey = Symbol('state');

const isNonEmptyString = (x) => typeof x === 'string' && x.trim().length > 0;

const flatten = (data, options) => {
const stack = [...data];
const childrenKey = options?.childrenKey ?? 'children';
const results = [];

while (stack.length > 0) {
const node = stack.shift();
const { title = '', icon = '', path = '', [stateKey]: state = {} } = node;
const { title = '', path = '', [stateKey]: state = {} } = node;
const { level = 0, parent = null } = state;

if (node[childrenKey]) {
Expand All @@ -27,16 +29,15 @@ const flatten = (data, options) => {
level: level + 1,
parent: {
title,
icon,
path,
},
},
})));
}

if (title && path) {
if (isNonEmptyString(title) && isNonEmptyString(path)) {
const object = {
data: { title, icon, path },
data: { title, path },
level,
parent,
};
Expand Down

0 comments on commit 33946eb

Please sign in to comment.