1+ import type { Metadata } from "next" ;
2+
13import Date from "@/components/Date" ;
24import ShareButtons from "@/components/shareButtons/ShareButtons" ;
35
46import { checkIfSlugIsValid , getPostData } from "@/lib/news" ;
7+ import { safeJsonLdStringify } from "@/utils/jsonLd" ;
58import { notFound } from "next/navigation" ;
69
710export type Params = {
@@ -17,9 +20,10 @@ export type PostData = {
1720 date : string ;
1821 author ?: string ;
1922 contentHtml : string ;
23+ excerpt : string ;
2024} ;
2125
22- export async function generateMetadata ( { params } : Props ) {
26+ export async function generateMetadata ( { params } : Props ) : Promise < Metadata > {
2327 const { slug } = await params ;
2428
2529 if ( ! ( await checkIfSlugIsValid ( slug ) ) ) {
@@ -29,9 +33,22 @@ export async function generateMetadata({ params }: Props) {
2933 }
3034
3135 const postData : PostData = await getPostData ( slug ) ;
36+ const url = `https://rockylinux.org/news/${ slug } ` ;
37+ const author = postData . author || "Rocky Linux Team" ;
3238
3339 return {
3440 title : `${ postData . title } - Rocky Linux` ,
41+ description : postData . excerpt ,
42+ openGraph : {
43+ title : postData . title ,
44+ description : postData . excerpt ,
45+ url,
46+ siteName : "Rocky Linux" ,
47+ locale : "en_US" ,
48+ type : "article" ,
49+ publishedTime : postData . date ,
50+ authors : [ author ] ,
51+ } ,
3552 } ;
3653}
3754
@@ -43,25 +60,53 @@ export default async function Post({ params }: Props) {
4360 }
4461
4562 const postData : PostData = await getPostData ( slug ) ;
63+ const author = postData . author || "Rocky Linux Team" ;
64+
65+ const jsonLd = {
66+ "@context" : "https://schema.org" ,
67+ "@type" : "NewsArticle" ,
68+ headline : postData . title ,
69+ description : postData . excerpt ,
70+ datePublished : postData . date ,
71+ author : {
72+ "@type" : "Person" ,
73+ name : author ,
74+ } ,
75+ publisher : {
76+ "@type" : "Organization" ,
77+ name : "Rocky Linux" ,
78+ url : "https://rockylinux.org" ,
79+ } ,
80+ mainEntityOfPage : {
81+ "@type" : "WebPage" ,
82+ "@id" : `https://rockylinux.org/news/${ slug } ` ,
83+ } ,
84+ } ;
4685
4786 return (
48- < div className = "py-24 sm:py-32" >
49- < div className = "mx-auto max-w-3xl text-base leading-7" >
50- < p className = "text-base font-semibold leading-7 text-primary text-center uppercase font-display" >
51- < Date dateString = { postData . date } />
52- </ p >
53- < h1 className = "mt-2 text-3xl font-bold tracking-tight sm:text-4xl mb-2 text-center font-display" >
54- { postData . title }
55- </ h1 >
56- < p className = "text-base leading-7 text-center mb-12 italic" >
57- { postData . author ? postData . author : "Rocky Linux Team" }
58- </ p >
59- < div
60- className = "prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-pre:text-black dark:prose-pre:text-white prose-img:rounded-md max-w-none mb-12"
61- dangerouslySetInnerHTML = { { __html : postData . contentHtml } }
62- />
63- < ShareButtons url = { `https://rockylinux.org/news/${ slug } ` } />
87+ < >
88+ < script
89+ type = "application/ld+json"
90+ dangerouslySetInnerHTML = { { __html : safeJsonLdStringify ( jsonLd ) } }
91+ />
92+ < div className = "py-24 sm:py-32" >
93+ < div className = "mx-auto max-w-3xl text-base leading-7" >
94+ < p className = "text-base font-semibold leading-7 text-primary text-center uppercase font-display" >
95+ < Date dateString = { postData . date } />
96+ </ p >
97+ < h1 className = "mt-2 text-3xl font-bold tracking-tight sm:text-4xl mb-2 text-center font-display" >
98+ { postData . title }
99+ </ h1 >
100+ < p className = "text-base leading-7 text-center mb-12 italic" >
101+ { author }
102+ </ p >
103+ < div
104+ className = "prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-pre:text-black dark:prose-pre:text-white prose-img:rounded-md max-w-none mb-12"
105+ dangerouslySetInnerHTML = { { __html : postData . contentHtml } }
106+ />
107+ < ShareButtons url = { `https://rockylinux.org/news/${ slug } ` } />
108+ </ div >
64109 </ div >
65- </ div >
110+ </ >
66111 ) ;
67112}
0 commit comments