mirror of
https://github.com/SrIzan10/mainwebsite.git
synced 2026-06-06 00:56:58 +00:00
feat: page metadata
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<id>https://srizan.dev/blog</id>
|
||||
<title>Sr Izan's Blog</title>
|
||||
<updated>2023-11-22T19:33:24.119Z</updated>
|
||||
<updated>2023-11-22T20:55:41.512Z</updated>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<author>
|
||||
<name>Sr Izan</name>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<title>Sr Izan's Blog</title>
|
||||
<link>https://srizan.dev/blog</link>
|
||||
<description>My little donowall place on the net</description>
|
||||
<lastBuildDate>Wed, 22 Nov 2023 19:33:24 GMT</lastBuildDate>
|
||||
<lastBuildDate>Wed, 22 Nov 2023 20:55:41 GMT</lastBuildDate>
|
||||
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<language>en</language>
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<Head>
|
||||
<title>{jsonData.title}</title>
|
||||
<meta name="description" content={jsonData.description} />
|
||||
<meta name="og:title" content={jsonData.title} />
|
||||
<meta name="og:description" content={jsonData.description} />
|
||||
<meta name="og:type" content="article" />
|
||||
<meta name="og:url" content={`https://srizan.dev/blog/${jsonData.id}`} />
|
||||
<meta name="og:article:author" content="Sr Izan" />
|
||||
</Head>
|
||||
<BlogNavBar title={jsonData.title} />
|
||||
<div className={'blogPostContent'}>
|
||||
<ReactMarkdown remarkPlugins={[remarkGfm]} components={{
|
||||
@@ -74,6 +65,36 @@ export default async function Page({ params }: { params: { id: string } }) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: { params: { id: string } }): Promise<Metadata> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user