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] authored Jul 31, 2024
1 parent ad41c5e commit 993100d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/react-docs/config/sidebar-routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Flex,
Text,
Tooltip,
} from '@tonic-ui/react';
Expand Down Expand Up @@ -52,11 +51,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',
},
{ title: 'React Icons', path: 'contributing/react-icons' },
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 993100d

Please sign in to comment.