Skip to content

Commit abc3c67

Browse files
committed
refactor: centralize metadata generation and update site description
1 parent 66c3c74 commit abc3c67

File tree

10 files changed

+73
-194
lines changed

10 files changed

+73
-194
lines changed

src/app/about-us/page.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import { Metadata } from "next";
2-
import { ComingSoon } from "@/components/sections/coming-soon";
3-
import { siteConfig } from "@/lib/config";
2+
import { ComingSoon, comingSoonText } from "@/components/sections/coming-soon";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "About Us";
6-
const description = "Learn more about the ALPHA Chapter at the University of Hong Kong.";
7-
8-
export const metadata: Metadata = {
9-
title,
10-
description,
11-
openGraph: {
12-
title,
13-
description,
14-
images: [
15-
{
16-
url: siteConfig.seoImage,
17-
width: siteConfig.seoImageWidth,
18-
height: siteConfig.seoImageHeight,
19-
alt: title,
20-
},
21-
],
22-
},
23-
twitter: {
24-
card: "summary_large_image",
25-
title,
26-
description,
27-
images: [siteConfig.seoImage],
28-
},
29-
};
5+
const description = comingSoonText;
6+
export const metadata: Metadata = buildPageMetadata("/about-us", { description });
307

318
export default function AboutUs() {
329
return (

src/app/blog/page.tsx

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
import { Metadata } from "next";
2-
import { ComingSoon } from "@/components/sections/coming-soon";
3-
import { siteConfig } from "@/lib/config";
2+
import { ComingSoon, comingSoonText } from "@/components/sections/coming-soon";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "Blog";
6-
const description =
7-
"Read the latest news and articles from the ALPHA Chapter at the University of Hong Kong.";
8-
9-
export const metadata: Metadata = {
10-
title,
11-
description,
12-
openGraph: {
13-
title,
14-
description,
15-
images: [
16-
{
17-
url: siteConfig.seoImage,
18-
width: siteConfig.seoImageWidth,
19-
height: siteConfig.seoImageHeight,
20-
alt: title,
21-
},
22-
],
23-
},
24-
twitter: {
25-
card: "summary_large_image",
26-
title,
27-
description,
28-
images: [siteConfig.seoImage],
29-
},
30-
};
5+
const description = comingSoonText;
6+
export const metadata: Metadata = buildPageMetadata("/blog", { description });
317

328
export default function Blog() {
339
return (

src/app/join-us/page.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import { Metadata } from "next";
2-
import { ComingSoon } from "@/components/sections/coming-soon";
3-
import { siteConfig } from "@/lib/config";
2+
import { ComingSoon, comingSoonText } from "@/components/sections/coming-soon";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "Join Us";
6-
const description = "Join the ALPHA Chapter at the University of Hong Kong.";
7-
8-
export const metadata: Metadata = {
9-
title,
10-
description,
11-
openGraph: {
12-
title,
13-
description,
14-
images: [
15-
{
16-
url: siteConfig.seoImage,
17-
width: siteConfig.seoImageWidth,
18-
height: siteConfig.seoImageHeight,
19-
alt: title,
20-
},
21-
],
22-
},
23-
twitter: {
24-
card: "summary_large_image",
25-
title,
26-
description,
27-
images: [siteConfig.seoImage],
28-
},
29-
};
5+
const description = comingSoonText;
6+
export const metadata: Metadata = buildPageMetadata("/join-us", { description });
307

318
export default function JoinUs() {
329
return (

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { CursorFollower } from "@/components/features/cursor/cursor-follower";
1212
const siteUrl = process.env.SITE_URL;
1313

1414
const title = "ALPHA HKU";
15-
const description =
16-
"The official website for the ALPHA University Chapter at the University of Hong Kong. Join us to connect with students and professionals in the business and technology fields.";
15+
export const description =
16+
"The first and only global student initiative based in Hong Kong for constructive peace and humanity. First international student chapter of ALPHA Education.";
1717

1818
export const metadata: Metadata = {
1919
metadataBase: new URL(siteUrl!),

src/app/our-work/page.tsx

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
import { Metadata } from "next";
2-
import { ComingSoon } from "@/components/sections/coming-soon";
3-
import { siteConfig } from "@/lib/config";
2+
import { ComingSoon, comingSoonText } from "@/components/sections/coming-soon";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "Our Work";
6-
const description =
7-
"Discover the projects and initiatives by the ALPHA Chapter at the University of Hong Kong.";
8-
9-
export const metadata: Metadata = {
10-
title,
11-
description,
12-
openGraph: {
13-
title,
14-
description,
15-
images: [
16-
{
17-
url: siteConfig.seoImage,
18-
width: siteConfig.seoImageWidth,
19-
height: siteConfig.seoImageHeight,
20-
alt: title,
21-
},
22-
],
23-
},
24-
twitter: {
25-
card: "summary_large_image",
26-
title,
27-
description,
28-
images: [siteConfig.seoImage],
29-
},
30-
};
5+
const description = comingSoonText;
6+
export const metadata: Metadata = buildPageMetadata("/our-work", { description });
317

328
export default function OurWork() {
339
return (

src/app/page.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,10 @@ import { Hero } from "@/components/sections/hero";
33
import { FeaturedProgram } from "@/components/sections/featured-program";
44
import { WhoWeAre } from "@/components/sections/who-we-are";
55
import { WhatsHappening } from "@/components/sections/whats-happening";
6-
import { siteConfig } from "@/lib/config";
6+
import { buildPageMetadata } from "@/lib/config";
7+
import { description } from "@/app/layout";
78

8-
const title = "Home - ALPHA HKU";
9-
const description =
10-
"Welcome to the official website for the ALPHA University Chapter at the University of Hong Kong.";
11-
12-
export const metadata: Metadata = {
13-
title,
14-
description,
15-
openGraph: {
16-
title,
17-
description,
18-
images: [
19-
{
20-
url: siteConfig.seoImage,
21-
width: siteConfig.seoImageWidth,
22-
height: siteConfig.seoImageHeight,
23-
alt: title,
24-
},
25-
],
26-
},
27-
twitter: {
28-
card: "summary_large_image",
29-
title,
30-
description,
31-
images: [siteConfig.seoImage],
32-
},
33-
};
9+
export const metadata: Metadata = buildPageMetadata("/", { description, title: "Home - ALPHA HKU" });
3410

3511
export default function Home() {
3612
return (

src/app/resources/page.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
import { Metadata } from "next";
22
import { ResourceIframe } from "@/components/sections/resource-iframe";
3-
import { siteConfig } from "@/lib/config";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "Resources";
65
const description =
76
"Find useful resources and materials from the ALPHA Chapter at the University of Hong Kong.";
8-
9-
export const metadata: Metadata = {
10-
title,
11-
description,
12-
openGraph: {
13-
title,
14-
description,
15-
images: [
16-
{
17-
url: siteConfig.seoImage,
18-
width: siteConfig.seoImageWidth,
19-
height: siteConfig.seoImageHeight,
20-
alt: title,
21-
},
22-
],
23-
},
24-
twitter: {
25-
card: "summary_large_image",
26-
title,
27-
description,
28-
images: [siteConfig.seoImage],
29-
},
30-
};
7+
export const metadata: Metadata = buildPageMetadata("/resources", { description });
318

329
export default function Resources() {
3310
return (

src/app/upcoming-event/page.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import { Metadata } from "next";
2-
import { ComingSoon } from "@/components/sections/coming-soon";
3-
import { siteConfig } from "@/lib/config";
2+
import { ComingSoon, comingSoonText } from "@/components/sections/coming-soon";
3+
import { buildPageMetadata } from "@/lib/config";
44

5-
const title = "Events";
6-
const description = "Find out about upcoming events from the ALPHA Chapter at the University of Hong Kong.";
7-
8-
export const metadata: Metadata = {
9-
title,
10-
description,
11-
openGraph: {
12-
title,
13-
description,
14-
images: [
15-
{
16-
url: siteConfig.seoImage,
17-
width: siteConfig.seoImageWidth,
18-
height: siteConfig.seoImageHeight,
19-
alt: title,
20-
},
21-
],
22-
},
23-
twitter: {
24-
card: "summary_large_image",
25-
title,
26-
description,
27-
images: [siteConfig.seoImage],
28-
},
29-
};
5+
const description = comingSoonText;
6+
export const metadata: Metadata = buildPageMetadata("/upcoming-event", { description });
307

318
export default function Events() {
329
return (
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Construction } from "lucide-react";
22

3+
export const comingSoonText = "We're working hard to bring you this page. Stay tuned for something amazing!";
4+
35
export function ComingSoon() {
46
return (
57
<div className="flex flex-col items-center justify-center min-h-[calc(100vh-8rem)] text-center px-4">
68
<Construction className="h-16 w-16 mb-4 text-primary" />
79
<h1 className="text-4xl font-bold mb-2">Coming Soon!</h1>
8-
<p className="text-lg text-muted-foreground max-w-md">
9-
We're working hard to bring you this page. Stay tuned for something amazing!
10-
</p>
10+
<p className="text-lg text-muted-foreground max-w-md">{comingSoonText}</p>
1111
</div>
1212
);
1313
}

src/lib/config.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MetadataRoute } from "next";
22
import { isInternalHref } from "@/lib/utils";
3+
import type { Metadata } from "next";
34

45
type NavItem = {
56
href: string;
@@ -24,6 +25,9 @@ const mainNav: NavItem[] = [
2425
const utilityNav: NavItem[] = [];
2526

2627
export const siteConfig = {
28+
title: "ALPHA HKU",
29+
description:
30+
"The first and only global student initiative based in Hong Kong for constructive peace and humanity. First international student chapter of ALPHA Education.",
2731
email: "alphahku1213@gmail.com",
2832
instagram: "https://www.instagram.com/alpha.hku",
2933
github: "https://github.com/ALPHA-HKU",
@@ -41,3 +45,42 @@ export const siteConfig = {
4145
.map((item) => (item.href === "/" ? "" : item.href)),
4246
],
4347
};
48+
49+
export function getNavLabel(path: string): string | undefined {
50+
// normalize trailing slash
51+
const normalized = path === "/" ? "/" : path.replace(/\/$/, "");
52+
return siteConfig.mainNav.find((i) => i.href === normalized)?.label;
53+
}
54+
55+
export function buildPageMetadata(
56+
path: string,
57+
options?: { description?: string; title?: string }
58+
): Metadata {
59+
const inferredLabel = getNavLabel(path) || siteConfig.title;
60+
const label = options?.title || inferredLabel;
61+
62+
const description = options?.description ?? siteConfig.description;
63+
64+
return {
65+
title: label,
66+
description,
67+
openGraph: {
68+
title: label,
69+
description,
70+
images: [
71+
{
72+
url: siteConfig.seoImage,
73+
width: siteConfig.seoImageWidth,
74+
height: siteConfig.seoImageHeight,
75+
alt: label,
76+
},
77+
],
78+
},
79+
twitter: {
80+
card: "summary_large_image",
81+
title: label,
82+
description,
83+
images: [siteConfig.seoImage],
84+
},
85+
} satisfies Metadata;
86+
}

0 commit comments

Comments
 (0)