From 52239f034e4ab2a966b2544394eda4e783837495 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:57:44 +0100 Subject: [PATCH] feat: page metadata --- public/blog/atom.xml | 2 +- public/blog/rss.xml | 2 +- src/app/(pages)/blog/[id]/page.tsx | 43 ++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/public/blog/atom.xml b/public/blog/atom.xml index 0355e4f..9bfd804 100644 --- a/public/blog/atom.xml +++ b/public/blog/atom.xml @@ -2,7 +2,7 @@ https://srizan.dev/blog Sr Izan's Blog - 2023-11-22T19:33:24.119Z + 2023-11-22T20:55:41.512Z https://github.com/jpmonette/feed Sr Izan diff --git a/public/blog/rss.xml b/public/blog/rss.xml index 2fa4116..d4edb3c 100644 --- a/public/blog/rss.xml +++ b/public/blog/rss.xml @@ -4,7 +4,7 @@ Sr Izan's Blog https://srizan.dev/blog My little donowall place on the net - Wed, 22 Nov 2023 19:33:24 GMT + Wed, 22 Nov 2023 20:55:41 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en diff --git a/src/app/(pages)/blog/[id]/page.tsx b/src/app/(pages)/blog/[id]/page.tsx index 07214db..3260d30 100644 --- a/src/app/(pages)/blog/[id]/page.tsx +++ b/src/app/(pages)/blog/[id]/page.tsx @@ -1,4 +1,3 @@ -import Head from "next/head"; import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; @@ -8,6 +7,7 @@ import '../../../_css/BlogPost.css'; import React from "react"; import jsonDataArray from '../../../../../public/blogPosts.json'; import { redirect } from "next/navigation"; +import { Metadata } from 'next'; export default async function Page({ params }: { params: { id: string } }) { const id = parseInt(params.id); @@ -29,15 +29,6 @@ export default async function Page({ params }: { params: { id: string } }) { } return (
- - {jsonData.title} - - - - - - -
{ + const id = parseInt(params.id); + if (Number.isNaN(id)) redirect('/blog') + let jsonData = { + id: 0, + title: '', + description: '', + date: '', + fileName: '', + fileContent: '' + } + + const filteredPost = jsonDataArray.filter((post) => post.id === id)[0]; + jsonData = filteredPost; + + return { + title: jsonData.title, + description: jsonData.description, + openGraph: { + title: jsonData.title, + description: jsonData.description, + authors: ['Sr Izan'], + type: 'article', + url: `https://srizan.dev/blog/${id}`, + publishedTime: new Date(jsonData.date).toISOString(), + siteName: 'Sr Izan\'s blog', + } + } +} + type BlogPostJSONResponse = { id: number; title: string; @@ -81,4 +102,4 @@ type BlogPostJSONResponse = { date: string; fileName: string; fileContent: string; -} +} \ No newline at end of file