Skip to content

Commit 99e5215

Browse files
committed
Refactor parts regarding docs collection
A little bit of renaming from blog terms into docs terms. Also merge function that is used only once.
1 parent fac7476 commit 99e5215

5 files changed

Lines changed: 24 additions & 29 deletions

File tree

src/components/navigation/NavContents.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import { cn } from "@/lib/utils.ts";
44
import type {
55
groupedNavbarParents,
66
navbarParents,
7-
posts,
7+
pages,
88
} from "./navigationConfig";
99

1010
// We have to access these navbar configs via astro props because they are not available on the client side
1111
export interface NavContentsProps {
1212
mobile?: boolean;
1313
groupedNavbarParents: typeof groupedNavbarParents;
1414
navbarParents: typeof navbarParents;
15-
posts: typeof posts;
15+
pages: typeof pages;
1616
}
1717

1818
export function NavContents({
1919
mobile = false,
2020
groupedNavbarParents,
2121
navbarParents,
22-
posts,
22+
pages: pages,
2323
}: NavContentsProps) {
2424
const [expanded, setExpanded] = useState<string | undefined>();
2525

@@ -37,7 +37,7 @@ export function NavContents({
3737
return {
3838
navbarItem: i,
3939
title:
40-
posts.find((p) => p.params.slug === i.title.toLowerCase())?.props
40+
pages.find((p) => p.params.slug === i.title.toLowerCase())?.props
4141
.entry.title ?? i.title,
4242
};
4343
})

src/components/navigation/Navbar.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
import { ScrollArea } from "../ui/scroll-area";
33
import { NavContents } from "./NavContents.tsx";
4-
import { groupedNavbarParents, navbarParents, posts } from "./navigationConfig";
4+
import { groupedNavbarParents, navbarParents, pages } from "./navigationConfig";
55
---
66

77
<ScrollArea client:visible className="pr-6 h-full">
88
<div class="py-6">
99
<NavContents
1010
groupedNavbarParents={groupedNavbarParents}
1111
navbarParents={navbarParents}
12-
posts={posts}
12+
pages={pages}
1313
client:visible
1414
mobile={false}
1515
/>

src/components/navigation/Navigation.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MobileNavbar from "./MobileNavbar";
44
import Search from "./Search.astro";
55
import ThemeToggle from "./ThemeToggle.astro";
66
import { headerNavItems } from "./navigationConfig";
7-
import { groupedNavbarParents, navbarParents, posts } from "./navigationConfig";
7+
import { groupedNavbarParents, navbarParents, pages } from "./navigationConfig";
88
---
99

1010
<header
@@ -15,7 +15,7 @@ import { groupedNavbarParents, navbarParents, posts } from "./navigationConfig";
1515
<MobileNavbar
1616
groupedNavbarParents={groupedNavbarParents}
1717
navbarParents={navbarParents}
18-
posts={posts}
18+
pages={pages}
1919
client:media="(max-width: 768px)"
2020
/>
2121
<a class="hover:underline mr-6 hidden md:block" href="/">VocaDB Wiki</a>

src/components/navigation/navigationConfig.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { groupBy } from "@/lib/utils";
2-
import { getDocPaths } from "@/utils/get_paths";
2+
import { getCollection } from "astro:content";
33

44
export const navbarParents = [
55
{
@@ -29,12 +29,22 @@ export const headerNavItems = [
2929
{ name: "GitHub", href: "//github.com/VocaDB/Wiki" },
3030
];
3131

32-
export const posts = await getDocPaths();
32+
const docCollection = await getCollection("docs");
3333

34-
export const getParent = (p: (typeof posts)[number]) =>
35-
p.props.entry.parent;
34+
export const pages = docCollection.map((entry) => ({
35+
params: { slug: entry.slug },
36+
props: {
37+
entry: {
38+
slug: entry.slug,
39+
title: entry.data.title,
40+
parent: entry.data.parent,
41+
},
42+
},
43+
}));
44+
45+
export const getParent = (p: (typeof pages)[number]) => p.props.entry.parent;
3646

3747
export const groupedNavbarParents = groupBy(
38-
posts.filter((p) => getParent(p) !== undefined),
39-
(post) => getParent(post)!,
48+
pages.filter((p) => getParent(p) !== undefined),
49+
(pages) => getParent(pages)!,
4050
);

src/utils/get_paths.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)