Skip to content

Commit 41fed16

Browse files
NebraskaCoderclaude
andcommitted
Add Open Graph metadata to news pages
Add OG protocol tags to improve social media sharing for news content: - /news listing: og:title, og:description, og:url, og:site_name, og:locale, og:type - /news/[slug] articles: article-specific tags including published_time and authors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ca7a551 commit 41fed16

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

app/[locale]/news/[slug]/page.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Metadata } from "next";
2+
13
import Date from "@/components/Date";
24
import ShareButtons from "@/components/shareButtons/ShareButtons";
35

@@ -17,9 +19,10 @@ export type PostData = {
1719
date: string;
1820
author?: string;
1921
contentHtml: string;
22+
excerpt: string;
2023
};
2124

22-
export async function generateMetadata({ params }: Props) {
25+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
2326
const { slug } = await params;
2427

2528
if (!(await checkIfSlugIsValid(slug))) {
@@ -29,9 +32,22 @@ export async function generateMetadata({ params }: Props) {
2932
}
3033

3134
const postData: PostData = await getPostData(slug);
35+
const url = `https://rockylinux.org/news/${slug}`;
36+
const author = postData.author || "Rocky Linux Team";
3237

3338
return {
3439
title: `${postData.title} - Rocky Linux`,
40+
description: postData.excerpt,
41+
openGraph: {
42+
title: postData.title,
43+
description: postData.excerpt,
44+
url,
45+
siteName: "Rocky Linux",
46+
locale: "en_US",
47+
type: "article",
48+
publishedTime: postData.date,
49+
authors: [author],
50+
},
3551
};
3652
}
3753

app/[locale]/news/page.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NextPage, Route } from "next";
1+
import type { Metadata, NextPage, Route } from "next";
22

33
import { getTranslations } from "next-intl/server";
44
import Link from "next/link";
@@ -14,12 +14,22 @@ import {
1414
CardTitle,
1515
} from "@/components/ui/card";
1616

17-
export async function generateMetadata() {
17+
export async function generateMetadata(): Promise<Metadata> {
1818
const t = await getTranslations("news");
19+
const title = t("title");
20+
const description = t("description");
1921

2022
return {
21-
title: `${t("title")} - Rocky Linux`,
22-
description: `${t("description")}`,
23+
title: `${title} - Rocky Linux`,
24+
description,
25+
openGraph: {
26+
title,
27+
description,
28+
url: "https://rockylinux.org/news",
29+
siteName: "Rocky Linux",
30+
locale: "en_US",
31+
type: "website",
32+
},
2333
};
2434
}
2535

0 commit comments

Comments
 (0)