Skip to content

Commit

Permalink
reuse the sidebar sorter on pageGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hariti committed Oct 9, 2024
1 parent f738763 commit 30a2f1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/components/pageGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Link from 'next/link';

import {nodeForPath, sidebarOrderSorter} from 'sentry-docs/docTree';
import {nodeForPath} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';
import {sortPages} from 'sentry-docs/utils';

type Props = {
nextPages: boolean;
Expand All @@ -25,18 +26,23 @@ export function PageGrid({header, exclude}: Props) {
<nav>
{header && <h2>{header}</h2>}
<ul>
{parentNode.children
/* NOTE: temp fix while we figure out the reason why some nodes have empty front matter */
.filter(c => c.frontmatter.title && !exclude?.includes(c.slug))
.sort((a, b) => sidebarOrderSorter(a.frontmatter, b.frontmatter))
.map(n => (
<li key={n.path} style={{marginBottom: '1rem'}}>
<h4 style={{marginBottom: '0px'}}>
<Link href={'/' + n.path}>{n.frontmatter.title}</Link>
</h4>
{n.frontmatter.description && <p>{n.frontmatter.description}</p>}
</li>
))}
{sortPages(
parentNode.children.filter(
c =>
!c.frontmatter.sidebar_hidden &&
c.frontmatter.title &&
!exclude?.includes(c.slug)
),
// a hacky adapter to reuse the same sidebar sorter
node => ({...node, context: node.frontmatter})
).map(n => (
<li key={n.path} style={{marginBottom: '1rem'}}>
<h4 style={{marginBottom: '0px'}}>
<Link href={'/' + n.path}>{n.frontmatter.title}</Link>
</h4>
{n.frontmatter.description && <p>{n.frontmatter.description}</p>}
</li>
))}
</ul>
</nav>
);
Expand Down
2 changes: 1 addition & 1 deletion src/docTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function getDocsRootNodeUncached(): Promise<DocNode> {
);
}

export const sidebarOrderSorter = (a: FrontMatter, b: FrontMatter) => {
const sidebarOrderSorter = (a: FrontMatter, b: FrontMatter) => {
const partDiff = slugWithoutIndex(a.slug).length - slugWithoutIndex(b.slug).length;
if (partDiff !== 0) {
return partDiff;
Expand Down

0 comments on commit 30a2f1a

Please sign in to comment.