2022-02-14 20:32:58 +00:00
|
|
|
import Layout from '../../components/layout';
|
|
|
|
import ReactMarkdown from 'react-markdown';
|
2022-04-24 04:27:51 +00:00
|
|
|
import style from '../../styles/post.module.css';
|
2023-10-30 04:18:38 +00:00
|
|
|
import PostsInfo from '../../public/posts.json';
|
|
|
|
import readMarkdown from '../../lib/read-markdown';
|
2024-02-13 23:01:07 +00:00
|
|
|
import DateTool from '../../lib/date';
|
2022-02-14 20:32:58 +00:00
|
|
|
|
2023-10-30 04:18:38 +00:00
|
|
|
interface Post {
|
|
|
|
title: string;
|
|
|
|
mtime: string;
|
|
|
|
otime?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Posts {
|
|
|
|
[slug: string]: Post
|
|
|
|
}
|
|
|
|
|
2024-02-13 23:01:07 +00:00
|
|
|
|
|
|
|
function TimeBlock({ mtime, otime }: { mtime: string, otime: string }) {
|
|
|
|
const ampm = (h: number) => { if (h >= 12) return 'p.m.'; return 'a.m.'; };
|
|
|
|
|
|
|
|
const mdate = new Date(mtime);
|
|
|
|
const odate = new Date(otime);
|
|
|
|
|
|
|
|
const format = (date: Date) => {
|
|
|
|
const day = date.getDay();
|
|
|
|
const ord = <sup>{DateTool.getOrdinalDaySuffix(date.getDay())}</sup>;
|
|
|
|
const month = DateTool.getFullMonth(date.getMonth());
|
|
|
|
const year = date.getFullYear();
|
|
|
|
const hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
|
|
|
|
const minPrefix = date.getMinutes() < 10 ? '0' : '';
|
|
|
|
const minutes = date.getMinutes();
|
|
|
|
const twelveSfx = ampm(date.getHours());
|
|
|
|
return <>{day}{ord} {month} {year} at {hours}:{minPrefix}{minutes} {twelveSfx}</>
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ textAlign: 'right', fontSize: '16px', fontFamily: 'Cantarell', fontStyle: 'italic' }}>
|
|
|
|
{
|
|
|
|
mtime ?
|
|
|
|
<div className='mtime' data-text={mdate.toISOString()}>
|
|
|
|
Last updated: {format(mdate)}
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<></>
|
|
|
|
}
|
|
|
|
<div className='otime'>
|
|
|
|
{format(odate)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Post({ post }: { post: Post & { content: string, cover?: string, otime: string, mtime?: string } }) {
|
2022-04-24 04:27:51 +00:00
|
|
|
return (<>
|
2023-10-30 04:18:38 +00:00
|
|
|
<Layout removeContainer={true} >
|
|
|
|
{<div className={style.imageBlock}
|
|
|
|
style={{
|
|
|
|
backgroundImage:
|
|
|
|
post.cover ?
|
|
|
|
`url(/assets/images/${post.cover})` :
|
2023-11-02 21:09:23 +00:00
|
|
|
'linear-gradient(to bottom right, rgb(5, 51, 11), rgb(5, 45, 13) 15%, rgb(5, 39,15) 40%, rgb(0, 30, 16) 80%)'
|
2022-10-05 03:41:59 +00:00
|
|
|
}}></div>}
|
2023-11-02 21:09:23 +00:00
|
|
|
<div className={`${style.spacer} ${post.cover ? style.background : ''}`}></div>
|
2022-05-15 13:56:45 +00:00
|
|
|
<section className={`${style.block} block`}>
|
2022-10-05 03:41:59 +00:00
|
|
|
<div className='container'>
|
2024-02-13 23:01:07 +00:00
|
|
|
<TimeBlock mtime={post.mtime} otime={post.otime} />
|
2022-10-05 03:41:59 +00:00
|
|
|
<ReactMarkdown>{post.content}</ReactMarkdown>
|
|
|
|
</div>
|
2022-05-15 13:56:45 +00:00
|
|
|
</section>
|
2023-11-02 21:09:23 +00:00
|
|
|
<div className={style.spacer}></div>
|
2022-02-14 20:32:58 +00:00
|
|
|
</Layout>
|
2022-04-27 09:10:49 +00:00
|
|
|
|
2022-04-24 04:27:51 +00:00
|
|
|
</>
|
2022-02-14 20:32:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-24 04:27:51 +00:00
|
|
|
export async function getStaticProps({ params }: any) {
|
2023-10-30 04:18:38 +00:00
|
|
|
const postsInfo: Posts = PostsInfo;
|
|
|
|
const post: Post = postsInfo[params.post];
|
2022-02-14 20:32:58 +00:00
|
|
|
return {
|
2023-10-30 04:18:38 +00:00
|
|
|
props: {
|
|
|
|
post: {
|
|
|
|
...post,
|
|
|
|
content: await readMarkdown('posts', params.post, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-14 20:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
return {
|
2023-10-30 04:18:38 +00:00
|
|
|
paths: Object.keys(PostsInfo).map((post: string) => {
|
2022-02-14 20:32:58 +00:00
|
|
|
return {
|
|
|
|
params: {
|
2023-10-30 04:18:38 +00:00
|
|
|
post
|
2022-02-14 20:32:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
fallback: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Post;
|