Skip to content

Commit b8000fc

Browse files
Add static path navigation configuration and scaffolding
1 parent 7b7669f commit b8000fc

File tree

10 files changed

+102
-24
lines changed

10 files changed

+102
-24
lines changed

src/components/Masthead.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PageToggle } from "./PageToggle";
1919
<PageToggle client:idle/>
2020
</MastheadToggle>
2121
<MastheadBrand>
22-
<MastheadLogo>
22+
<MastheadLogo component="a" href="/">
2323
<Brand src={pfLogo} alt="PatternFly" heights={{ default: "36px" }} />
2424
</MastheadLogo>
2525
</MastheadBrand>

src/components/Navigation.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
2+
import { getCollection } from "astro:content";
3+
24
import { Navigation as ReactNav } from "./Navigation.tsx";
5+
6+
const navEntries = await getCollection("test");
37
---
48

5-
<ReactNav client:idle />
9+
<ReactNav client:idle navEntries={navEntries} />

src/components/Navigation.tsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useState, type ReactNode } from "react";
22
import {
33
Nav,
44
NavList,
@@ -15,40 +15,50 @@ interface NavOnSelectProps {
1515
to: string;
1616
}
1717

18-
export const Navigation: React.FunctionComponent = () => {
19-
const [activeItem, setActiveItem] = useState(1);
18+
interface NavEntry {
19+
id: string;
20+
slug: string;
21+
data: {
22+
title: string;
23+
};
24+
collection: string;
25+
}
26+
27+
interface NavigationProps {
28+
navEntries: NavEntry[];
29+
}
30+
31+
export const Navigation: React.FunctionComponent<NavigationProps> = ({
32+
navEntries,
33+
}: NavigationProps) => {
34+
const [activeItem, setActiveItem] = useState("");
2035

2136
const onNavSelect = (
2237
_event: React.FormEvent<HTMLInputElement>,
2338
selectedItem: NavOnSelectProps
2439
) => {
25-
typeof selectedItem.itemId === "number" &&
40+
typeof selectedItem.itemId === "string" &&
2641
setActiveItem(selectedItem.itemId);
2742
};
2843

2944
const $isNavOpen = useStore(isNavOpen);
3045

46+
const navItems = navEntries.map((entry) => (
47+
<NavItem
48+
key={entry.id}
49+
itemId={entry.id}
50+
isActive={activeItem === entry.id}
51+
to={`/${entry.collection}/${entry.slug}`}
52+
>
53+
{entry.data.title}
54+
</NavItem>
55+
));
56+
3157
return (
3258
<PageSidebar isSidebarOpen={$isNavOpen}>
3359
<PageSidebarBody>
3460
<Nav onSelect={onNavSelect}>
35-
<NavList>
36-
<NavItem itemId={0} isActive={activeItem === 0} to="test">
37-
Test
38-
</NavItem>
39-
<NavItem itemId={1} isActive={activeItem === 1} to="#policy">
40-
Policy
41-
</NavItem>
42-
<NavItem itemId={2} isActive={activeItem === 2} to="#auth">
43-
Authentication
44-
</NavItem>
45-
<NavItem itemId={3} isActive={activeItem === 3} to="#network">
46-
Network services
47-
</NavItem>
48-
<NavItem itemId={4} isActive={activeItem === 4} to="#server">
49-
Server
50-
</NavItem>
51-
</NavList>
61+
<NavList>{navItems}</NavList>
5262
</Nav>
5363
</PageSidebarBody>
5464
</PageSidebar>

src/content/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineCollection, z } from "astro:content";
2+
3+
const testCollection = defineCollection({
4+
type: "content",
5+
schema: z.object({ title: z.string() }),
6+
});
7+
8+
export const collections = {
9+
test: testCollection,
10+
};

src/content/pages/test.md

Whitespace-only changes.

src/content/test/test-1.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
layout: '../../layouts/Main.astro'
3+
title: 'Test title 1'
4+
---
5+
6+
# Title 1
7+
8+
## Section
9+
10+
### Subsection
11+
12+
Text content
13+
14+
## Another section
15+
16+
### Another subsection
17+
18+
More text content

src/content/test/test-2.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
layout: '../../layouts/Main.astro'
3+
title: 'Test title 2'
4+
---
5+
6+
# Title 2
7+
8+
## Section
9+
10+
### Subsection
11+
12+
Text content
13+
14+
## Another section
15+
16+
### Another subsection
17+
18+
More text content

src/layouts/Main.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import '@patternfly/patternfly/patternfly.css';
3+
24
import Page from "../components/Page.astro";
35
import Masthead from "../components/Masthead.astro";
46
import Navigation from "../components/Navigation.astro";

src/pages/test/[...slug].astro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
import { getCollection } from "astro:content";
3+
4+
export async function getStaticPaths() {
5+
const testEntries = await getCollection("test");
6+
return testEntries.map((entry) => ({
7+
params: { slug: entry.slug },
8+
props: { entry },
9+
}));
10+
}
11+
12+
const { entry } = Astro.props;
13+
const { Content } = await entry.render();
14+
---
15+
16+
<Content />

src/styles/global.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@import "@patternfly/patternfly/patternfly-base.css";
1+
// custom global scss would go here

0 commit comments

Comments
 (0)