Skip to content

Commit bc7bd40

Browse files
committed
feat(blog): new dynamic page to display a single blog post
1 parent e823bb6 commit bc7bd40

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

components/blog/post.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const Post = (props: BlogPost) => {
1616
<h1 className="mb-4 text-4xl text-center font-extrabold leading-tight lg:mb-6 text-white">
1717
{title}
1818
</h1>
19-
<a href="#" rel="author" className="text-xl font-bold text-white">by {author}</a>
19+
<p className="text-xl font-bold text-white">by {author}</p>
2020
<p className="text-base font-light text-gray-500 dark:text-gray-400">
21-
<time dateTime={date_created.toString()} title={date_created.toString()}>
21+
<time dateTime={date_created?.toString()} title={date_created?.toString()}>
2222
{toAgoTime(date_created)}
2323
</time>
2424
</p>
@@ -27,7 +27,7 @@ const Post = (props: BlogPost) => {
2727
</address>
2828
</header>
2929
<div className={'flex flex-col'}>
30-
{sections.map((section, index) => {
30+
{!!sections && sections.map((section, index) => {
3131
return (
3232
<Section
3333
key={index}

pages/blog/[slug].tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {NextPage} from "next";
2+
import Post from "../../components/blog/post";
3+
import React, {useEffect, useState} from "react";
4+
import {BlogPost} from "../../types/blogPost";
5+
import {useRouter} from 'next/router';
6+
import Head from "next/head";
7+
8+
const PostPage: NextPage = () => {
9+
const router = useRouter();
10+
const {slug} = router.query;
11+
const [post, setPost] = useState({} as BlogPost);
12+
13+
useEffect(() => {
14+
if (!router.isReady) return;
15+
fetch(`https://changelog.unitystation.org/posts/${slug}`)
16+
.then(response => response.json())
17+
.then(json => setPost(json))
18+
}, [router.isReady]);
19+
20+
return (
21+
<>
22+
<Head>
23+
<title key={'title'}>Unitystation - {post?.title}</title>
24+
<meta
25+
key='description'
26+
name='description'
27+
content='Read more about this interesting article on our blog!'
28+
/>
29+
<meta
30+
key='og:title'
31+
property='og:title'
32+
content='Unitystation - A blog post'
33+
/>
34+
<meta
35+
key='og:description'
36+
property='og:description'
37+
content='Read more about this interesting article on our blog!'
38+
/>
39+
</Head>
40+
41+
<main className={'pt-8 pb-16 lg:pt-16 lg:pb-24'}>
42+
<div className={'flex px-4 mx-auto max-w-screen-xl '}>
43+
{<Post
44+
key={post.slug}
45+
title={post.title}
46+
date_created={post.date_created}
47+
slug={post.slug}
48+
sections={post.sections}
49+
author={post.author}
50+
state={post.state}
51+
type={post.type}
52+
/>}
53+
</div>
54+
</main>
55+
</>
56+
57+
)
58+
}
59+
60+
export default PostPage;

0 commit comments

Comments
 (0)