Skip to content

Commit 0002895

Browse files
committed
Refactor hideFromNav logic to support breadcrumbs
1 parent 597b78b commit 0002895

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

.changeset/neat-mirrors-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'polaris.shopify.com': patch
3+
---
4+
5+
Refactor hideFromNav logic to support breadcrumbs

polaris.shopify.com/scripts/gen-cache-json.mjs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,45 @@ const navJsonFile = `${cacheDir}/nav.json`;
1111
const genNavJson = (markdownFiles) => {
1212
let nav = {};
1313

14-
markdownFiles
15-
.filter((md) => md && !md.frontMatter?.hideFromNav)
16-
.forEach((md) => {
17-
const {
18-
title,
19-
navTitle,
20-
icon,
21-
description,
22-
order,
23-
newSection,
24-
hideChildren,
25-
color,
26-
url,
27-
status,
28-
expanded,
29-
groups,
30-
componentDescriptions,
31-
relatedResources,
32-
} = md.frontMatter;
33-
const {slug} = md;
34-
35-
const path = `children.${slug.replace(/\//g, '.children.')}`;
36-
37-
set(nav, path, {
38-
title: navTitle || title,
39-
icon,
40-
description,
41-
order,
42-
slug: url || `/${slug}`,
43-
newSection,
44-
hideChildren,
45-
color: color ? color.replace(/\\/g, '') : undefined,
46-
status,
47-
expanded,
48-
groups,
49-
componentDescriptions,
50-
relatedResources,
51-
});
14+
markdownFiles.forEach((md) => {
15+
const {
16+
title,
17+
navTitle,
18+
icon,
19+
description,
20+
order,
21+
newSection,
22+
hideChildren,
23+
color,
24+
url,
25+
status,
26+
expanded,
27+
groups,
28+
componentDescriptions,
29+
relatedResources,
30+
hideFromNav,
31+
} = md.frontMatter;
32+
const {slug} = md;
33+
34+
const path = `children.${slug.replace(/\//g, '.children.')}`;
35+
36+
set(nav, path, {
37+
title: navTitle || title,
38+
icon,
39+
description,
40+
order,
41+
slug: url || `/${slug}`,
42+
newSection,
43+
hideChildren,
44+
color: color ? color.replace(/\\/g, '') : undefined,
45+
status,
46+
expanded,
47+
groups,
48+
componentDescriptions,
49+
relatedResources,
50+
hideFromNav: hideFromNav || false,
5251
});
52+
});
5353

5454
writeFileSync(navJsonFile, JSON.stringify(nav), 'utf-8');
5555
};

polaris.shopify.com/src/components/Frame/Frame.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ function NavItem({
194194
return (
195195
<>
196196
{nav.children &&
197+
!nav.hideFromNav &&
197198
Object.entries(nav.children)
199+
.filter(([, child]) => !child.hideFromNav)
198200
.sort((_a, _b) => {
199201
const [, a] = _a as [string, NavItem];
200202
const [, b] = _b as [string, NavItem];

polaris.shopify.com/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,5 @@ export interface NavItem {
203203
status?: Status;
204204
children?: NavJSON;
205205
expanded?: boolean;
206+
hideFromNav?: boolean;
206207
}

0 commit comments

Comments
 (0)