diff --git a/app/posts/[id]/page.tsx b/app/posts/[id]/page.tsx index 8f83ed3..b1039e3 100644 --- a/app/posts/[id]/page.tsx +++ b/app/posts/[id]/page.tsx @@ -1,135 +1,162 @@ -import ShareButtons from '@/components/ShareButtons'; -import { getPostData, getSortedPostsData } from '@/lib/markdown'; -import { PostData, PostMetadata } from '@/types'; -import { format } from 'date-fns'; -import Image from 'next/image'; -import Link from 'next/link'; -import React from 'react'; +import ShareButtons from "@/components/ShareButtons"; +import { getPostData, getSortedPostsData } from "@/lib/markdown"; +import { PostData, PostMetadata } from "@/types"; +import { format } from "date-fns"; +import Image from "next/image"; +import Link from "next/link"; +import React from "react"; import CommentSection from "@/components/CommentSection"; -import { generateMetadata as createMetadata } from '@/components/Metadata'; -import type { Metadata } from 'next'; +import { generateMetadata as createMetadata } from "@/components/Metadata"; +import type { Metadata } from "next"; interface PageProps { - params: Promise<{ id: string }>; + params: Promise<{ id: string }>; } -export async function generateMetadata({ params }: PageProps): Promise { - const { id } = await params; - const post = await getPostData(id); - const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; +export async function generateMetadata({ + params, +}: PageProps): Promise { + const { id } = await params; + const post = await getPostData(id); + const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; - return createMetadata({ - title: post.title, - description: post.excerpt, - keywords: post.tags.join(', '), - image: post.coverImage, - url: postUrl, - type: 'article' - }); + return createMetadata({ + title: post.title, + description: post.excerpt, + keywords: post.tags.join(", "), + image: post.coverImage, + url: postUrl, + type: "article", + }); } -async function getPostAndMorePosts(id: string): Promise<{ post: PostData; morePosts: PostMetadata[] }> { - const post = await getPostData(id); - const allPosts = getSortedPostsData(); +async function getPostAndMorePosts( + id: string, +): Promise<{ post: PostData; morePosts: PostMetadata[] }> { + const post = await getPostData(id); + const allPosts = getSortedPostsData(); - // Filter out the current post and get a few related posts (by tags) - const otherPosts = allPosts.filter(p => p.id !== post.id); + // Filter out the current post and get a few related posts (by tags) + const otherPosts = allPosts.filter((p) => p.id !== post.id); - // Find posts with matching tags - const relatedPosts = otherPosts - .filter(p => p.tags.some(tag => post.tags.includes(tag))) - .slice(0, 2); + // Find posts with matching tags + const relatedPosts = otherPosts + .filter((p) => p.tags.some((tag) => post.tags.includes(tag))) + .slice(0, 2); - // If we don't have enough related posts, add recent posts - const morePosts = relatedPosts.length < 2 - ? [...relatedPosts, ...otherPosts.filter(p => !relatedPosts.includes(p))].slice(0, 2) - : relatedPosts; + // If we don't have enough related posts, add recent posts + const morePosts = + relatedPosts.length < 2 + ? [ + ...relatedPosts, + ...otherPosts.filter((p) => !relatedPosts.includes(p)), + ].slice(0, 2) + : relatedPosts; - return { post, morePosts }; + return { post, morePosts }; } export default async function PostPage({ params }: PageProps) { - const { id } = await params; - const { post, morePosts } = await getPostAndMorePosts(id); - const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; + const { id } = await params; + const { post, morePosts } = await getPostAndMorePosts(id); + const postUrl = `https://confessionsofgrace.com/posts/${post.id}`; - return ( -
-
-

{post.title}

-
- {post.author} - - -
- {post.coverImage && ( -
- {post.title} -
- )} -
- {post.tags.map(tag => ( - - {tag} - - ))} -
-
- -
+
+

{post.title}

+
+ {post.author} + + +
+ {post.coverImage && ( +
+ {post.title} +
+ )} +
+ {post.tags.map((tag) => ( + + {tag} + + ))} +
+
-
- -
+
-
-

More Posts

-
- {morePosts.slice(0, 2).map(post => ( -
-

- - {post.title} - -

-

- {format(new Date(post.date), 'MMMM d, yyyy')} -

-

{post.excerpt}

-
- ))} -
-
+
+ +
- - -
- - - - - Back to all posts +
+

More Posts

+
+ {morePosts.slice(0, 2).map((post) => ( +
+

+ + {post.title} +

+

+ {format(new Date(post.date), "MMMM d, yyyy")} +

+

{post.excerpt}

-
- ); -} \ No newline at end of file + ))} + + + + + +
+ + + + + Back to all posts + +
+ + ); +} diff --git a/components/Metadata.tsx b/components/Metadata.tsx index ea0e075..5eec1c3 100644 --- a/components/Metadata.tsx +++ b/components/Metadata.tsx @@ -1,56 +1,59 @@ -import type {Metadata} from "next"; +import type { Metadata } from "next"; interface MetaProps { - title?: string; - description?: string; - keywords?: string; - image?: string; - url?: string; - type?: string; + title?: string; + description?: string; + keywords?: string; + image?: string; + url?: string; + type?: string; } export function generateMetadata({ - title = 'Confessions of Grace', - description = 'A blog dedicated to exploring the doctrines of grace and Reformed theology.', - keywords = 'reformed theology, doctrines of grace, christianity, calvinism, theology', - image = '/images/og-default.jpg', - url = 'https://confessionsofgrace.com', - type = 'website' - }: MetaProps = {}): Metadata { - const siteTitle = title === 'Confessions of Grace' - ? 'Confessions of Grace | Confessing Christ. Rejoicing in Grace.' - : `${title} | Confessions of Grace`; + title = "Confessions of Grace", + description = "A blog dedicated to exploring the doctrines of grace and Reformed theology.", + keywords = "reformed theology, doctrines of grace, christianity, calvinism, theology", + image = "/images/og-default.jpg", + url = "https://confessionsofgrace.com", + type = "website", +}: MetaProps = {}): Metadata { + const siteTitle = + title === "Confessions of Grace" + ? "Confessions of Grace | Confessing Christ. Rejoicing in Grace." + : `${title} | Confessions of Grace`; - const fullImageUrl = image.startsWith('http') ? image : `https://www.confessionsofgrace.com${image}`; + const fullImageUrl = image.startsWith("http") + ? image + : `https://confessionsofgrace.com${image}`; - return { - title: siteTitle, - description, - keywords, - openGraph: { - type: type as any, - url, - title: siteTitle, - description, - images: [ - { - url: fullImageUrl, - alt: title || 'Confessions of Grace' - } - ], - locale: 'en_US', - siteName: 'Confessions of Grace' + return { + title: siteTitle, + description, + keywords, + openGraph: { + type: type as any, + url, + title: siteTitle, + description, + images: [ + { + url: fullImageUrl, + alt: title || "Confessions of Grace", }, - twitter: { - card: 'summary_large_image', - title: siteTitle, - description, - images: [fullImageUrl] - }, - alternates: { - canonical: url - } - }; + ], + locale: "en_US", + siteName: "Confessions of Grace", + }, + twitter: { + card: "summary_large_image", + title: siteTitle, + description, + images: [fullImageUrl], + }, + alternates: { + canonical: url, + }, + }; } // Default metadata for the site @@ -58,5 +61,5 @@ export const defaultMetadata: Metadata = generateMetadata(); // Helper function for pages that need custom metadata export function createPageMetadata(props: MetaProps): Metadata { - return generateMetadata(props); -} \ No newline at end of file + return generateMetadata(props); +}