Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
cheton marked this conversation as resolved.
Show resolved Hide resolved

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
Loading