Skip to content

Commit f4a5d58

Browse files
committed
breadcrumbs
1 parent 97bd3f4 commit f4a5d58

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/components/breadcrumbs/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ type BreadcrumbsProps = {
99
};
1010

1111
export function Breadcrumbs({leafNode}: BreadcrumbsProps) {
12-
const nodes: DocNode[] = [];
12+
const breadcrumbs: {title: string; to: string}[] = [];
13+
1314
for (let node: DocNode | undefined = leafNode; node; node = node.parent) {
1415
if (node && !node.missing) {
15-
nodes.unshift(node);
16+
const to = node.path === '/' ? node.path : `/${node.path}/`;
17+
const title = node.frontmatter.platformTitle ?? node.frontmatter.title;
18+
19+
breadcrumbs.unshift({
20+
to,
21+
title,
22+
});
1623
}
1724
}
1825

1926
return (
2027
<ul className="list-none flex p-0 flex-wrap" style={{margin: 0}}>
21-
{nodes.map(n => {
22-
const to = n.path === '/' ? n.path : `/${n.path}/`;
28+
{breadcrumbs.map(b => {
2329
return (
24-
<li className={styles['breadcrumb-item']} key={n.path}>
25-
<SmartLink to={to}>
26-
{n.frontmatter.platformTitle ?? n.frontmatter.title}
27-
</SmartLink>
30+
<li className={styles['breadcrumb-item']} key={b.to}>
31+
<SmartLink to={b.to}>{b.title}</SmartLink>
2832
</li>
2933
);
3034
})}

0 commit comments

Comments
 (0)