2024-09-07 14:24:30 +02:00
import React from "react" ;
import { client } from "@/lib/sanity" ;
import { Metadata } from "next" ;
import BlogCards from "@/components/cards/BlogCards" ;
import { Rss } from "lucide-react" ;
import { Button } from "@/components/ui/button" ;
import Link from "next/link" ;
2024-09-07 15:58:16 +02:00
export const dynamic = "force-static" ;
2024-11-08 10:18:51 +01:00
export async function generateMetadata ( props : {
params : Promise < { id : string } > ;
} ) : Promise < Metadata > {
return {
2024-09-07 14:24:30 +02:00
title : "Blog - SVR.JS" ,
description :
"Welcome to the SVR.JS Blog! Explore our latest blog posts featuring web development, web application security, and web server administration tips. Stay tuned for the latest SVR.JS updates." ,
2024-11-08 10:18:51 +01:00
openGraph : {
title : "Blog - SVR.JS" ,
description :
"Welcome to the SVR.JS Blog! Explore our latest blog posts featuring web development, web application security, and web server administration tips. Stay tuned for the latest SVR.JS updates." ,
url : ` ${ process . env . NEXT_PUBLIC_WEBSITE_URL } /blog/page/ ${ ( await props . params ) . id } ` ,
type : "website" ,
images : [
{
url : ` ${ process . env . NEXT_PUBLIC_WEBSITE_URL } /metadata/svrjs-cover.png ` ,
width : 800 ,
height : 600 ,
alt : "Blog - SVR.JS"
}
]
} ,
twitter : {
card : "summary_large_image" ,
site : "@SVR_JS" ,
title : "Blog - SVR.JS" ,
description :
"Welcome to the SVR.JS Blog! Explore our latest blog posts featuring web development, web application security, and web server administration tips. Stay tuned for the latest SVR.JS updates." ,
images : [
` ${ process . env . NEXT_PUBLIC_WEBSITE_URL } /metadata/svrjs-cover.png `
] ,
creator : "@SVR_JS"
}
} ;
}
2024-09-07 14:24:30 +02:00
2024-11-01 09:56:38 +01:00
const BlogPage = async ( props : { params : Promise < { id : string } > } ) = > {
const params = await props . params ;
2024-09-07 14:24:30 +02:00
// Optionally, you can fetch some initial data here if needed.
2024-09-07 17:57:29 +02:00
let id = parseInt ( params . id ) ;
if ( isNaN ( id ) ) id = 1 ;
2024-09-07 14:24:30 +02:00
return (
< section
id = "blog"
className = "wrapper container py-24 md:py-28 gap-2 flex-center flex-col"
>
2024-09-07 19:15:48 +02:00
< h1 className = "text-3xl md:text-5xl pb-1 md:pb-2 font-bold text-black dark:bg-clip-text dark:text-transparent dark:bg-gradient-to-b dark:from-white dark:to-neutral-400" >
2024-09-08 17:49:50 +02:00
SVR . JS Blog
2024-09-07 14:24:30 +02:00
< / h1 >
< p className = "text-muted-foreground flex-center mb-2" >
2024-09-08 17:49:50 +02:00
Our blog has web development , web server administration , and web
application security tips .
2024-09-07 14:24:30 +02:00
< Link href = "/rss.xml" rel = "alternate" type = "application/rss+xml" >
< Button variant = { "link" } className = "mx-0 px-2" >
< Rss className = "w-5 h-5 mr-1" / > RSS feed
< / Button >
< / Link >
< / p >
2024-09-07 17:57:29 +02:00
< BlogCards page = { id } / >
2024-09-07 14:24:30 +02:00
< / section >
) ;
} ;
export async function generateStaticParams() {
2024-09-07 17:27:18 +02:00
// Change in BlogCards component and in /api/revalidate route too!
2024-09-07 14:24:30 +02:00
const cardsPerPage = 6 ;
const totalPostsQuery = ` count(*[_type == 'blog']) ` ;
2024-09-07 14:31:17 +02:00
const totalPosts : number = await client . fetch (
totalPostsQuery ,
{ } ,
{ cache : "no-store" }
) ;
2024-09-07 14:24:30 +02:00
const totalPages = Math . ceil ( totalPosts / cardsPerPage ) ;
let ids : any [ ] = [ ] ;
for ( let i = 1 ; i <= totalPages ; i ++ ) {
ids . push ( { id : i.toString ( ) } ) ;
}
return ids ;
}
export default BlogPage ;