Skip to content

Commit 16cf767

Browse files
committed
refactor: centralize navigation config and add sitemap metadata support
1 parent b6d0ac5 commit 16cf767

File tree

4 files changed

+59
-44
lines changed

4 files changed

+59
-44
lines changed

src/app/sitemap.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { MetadataRoute } from "next";
2-
3-
export const staticRoutes = [
4-
"",
5-
"/about-us",
6-
"/upcoming-event",
7-
"/blog",
8-
"/our-work",
9-
"/resources",
10-
"/join-us",
11-
];
2+
import { siteConfig } from "@/lib/config";
123

134
export default function sitemap(): MetadataRoute.Sitemap {
145
const siteUrl = process.env.SITE_URL;
6+
const allNavs = [...siteConfig.mainNav, ...siteConfig.utilityNav];
157

16-
return staticRoutes.map((route) => ({
17-
url: `${siteUrl}${route}`,
18-
lastModified: new Date(),
19-
}));
8+
return allNavs.map((route) => {
9+
return {
10+
url: `${siteUrl}${route.href}`,
11+
lastModified: new Date(),
12+
...(route.changeFrequency && { changeFrequency: route.changeFrequency }),
13+
...(route.priority && { priority: route.priority }),
14+
};
15+
});
2016
}

src/components/layout/footer.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@ import { Mail } from "lucide-react";
33
import { SiGithub, SiInstagram } from "@icons-pack/react-simple-icons";
44
import { FaLinkedin } from "react-icons/fa";
55
import Link from "next/link";
6-
import { staticRoutes } from "@/app/sitemap";
76

8-
const sitemapLinks = staticRoutes.map((route) => {
9-
if (route === "") {
10-
return { href: "/", label: "Home" };
11-
}
12-
const label = route.replace("/", "").replace("-", " ");
13-
return { href: route, label: label.charAt(0).toUpperCase() + label.slice(1) };
14-
});
7+
const sitemapLinks = [...siteConfig.mainNav, ...siteConfig.utilityNav];
8+
159

1610
export function Footer() {
1711
return (

src/components/layout/header.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ import { Button } from "@/components/ui/button";
1818
import { AnimatePresence, motion } from "framer-motion";
1919
import { useState } from "react";
2020

21-
const navLinks = [
22-
{ href: "/", label: "Home" },
23-
{ href: "/about-us", label: "About Us" },
24-
{ href: "/upcoming-event", label: "Upcoming Event" },
25-
{ href: "/blog", label: "Blog" },
26-
{ href: "/our-work", label: "Our Work" },
27-
{ href: "/resources", label: "Resources" },
28-
];
21+
2922

3023
export function Header() {
3124
const [isOpen, setIsOpen] = useState(false);
@@ -55,7 +48,7 @@ export function Header() {
5548
<nav className="hidden lg:flex items-center gap-6 text-sm">
5649
<NavigationMenu>
5750
<NavigationMenuList>
58-
{navLinks.map((link) => (
51+
{siteConfig.mainNav.map((link) => (
5952
<NavigationMenuItem key={link.href}>
6053
<NavigationMenuLink asChild>
6154
<Link href={link.href}>{link.label}</Link>
@@ -74,12 +67,15 @@ export function Header() {
7467
>
7568
Donation
7669
</a>
77-
<a
78-
href="/join-us"
79-
className="hidden sm:block"
80-
>
81-
Join Us
82-
</a>
70+
{siteConfig.utilityNav.map((link) => (
71+
<a
72+
key={link.href}
73+
href={link.href}
74+
className="hidden sm:block"
75+
>
76+
{link.label}
77+
</a>
78+
))}
8379
<div className="hidden lg:flex items-center gap-4">
8480
<a
8581
href={siteConfig.github}
@@ -142,7 +138,7 @@ export function Header() {
142138
<div className="border-b border-t bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80">
143139
<div className="container px-4 lg:px-6 py-4">
144140
<nav className="grid gap-4 text-sm">
145-
{navLinks.map((link) => (
141+
{siteConfig.mainNav.map((link) => (
146142
<Link
147143
key={link.href}
148144
href={link.href}
@@ -157,12 +153,15 @@ export function Header() {
157153
>
158154
Donation
159155
</Link>
160-
<Link
161-
href="/join-us"
162-
className="hover:text-foreground/80"
163-
>
164-
Join Us
165-
</Link>
156+
{siteConfig.utilityNav.map((link) => (
157+
<Link
158+
key={link.href}
159+
href={link.href}
160+
className="hover:text-foreground/80"
161+
>
162+
{link.label}
163+
</Link>
164+
))}
166165
</nav>
167166
</div>
168167
</div>

src/lib/config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
import { MetadataRoute } from "next";
2+
3+
type NavItem = {
4+
href: string;
5+
label: string;
6+
priority?: MetadataRoute.Sitemap[0]["priority"];
7+
changeFrequency?: MetadataRoute.Sitemap[0]["changeFrequency"];
8+
};
9+
10+
const mainNav: NavItem[] = [
11+
{ href: "/", label: "Home" },
12+
{ href: "/about-us", label: "About Us" },
13+
{ href: "/upcoming-event", label: "Upcoming Event" },
14+
{ href: "/blog", label: "Blog" },
15+
{ href: "/our-work", label: "Our Work" },
16+
{ href: "/resources", label: "Resources" },
17+
];
18+
19+
const utilityNav: NavItem[] = [{ href: "/join-us", label: "Join Us" }];
20+
121
export const siteConfig = {
222
email: "alphahku1213@gmail.com",
323
instagram: "https://www.instagram.com/alpha.hku",
@@ -6,4 +26,10 @@ export const siteConfig = {
626
donate: "mailto:alphahku1213@gmail.com?subject=Donation Inquiry",
727
parentOrg: "https://alphaeducation.org",
828
seoImage: "/ALPHA-HKU.png",
29+
mainNav,
30+
utilityNav,
31+
staticRoutes: [
32+
...mainNav.map((item) => (item.href === "/" ? "" : item.href)),
33+
...utilityNav.map((item) => item.href),
34+
],
935
};

0 commit comments

Comments
 (0)