www/pages/posts/index.tsx

48 lines
1.9 KiB
TypeScript
Raw Normal View History

import Link from 'next/link';
import Layout from '../../components/layout';
2022-10-05 03:41:59 +00:00
import date from '../../lib/date';
import { getPostsMeta, IPostMeta } from '../../lib/slug';
2022-10-05 03:41:59 +00:00
function PostsPage({ postsMeta }: { postsMeta: IPostMeta[] }) {
2022-04-30 13:56:18 +00:00
return (
<Layout name='Posts'>
2022-10-05 03:41:59 +00:00
<table>
2022-04-30 13:56:18 +00:00
<tbody>
2022-10-05 03:41:59 +00:00
{
postsMeta.length &&
postsMeta.map((post: IPostMeta, i) => {
return <tr key={i} style={{alignItems: 'center'}}>
<td style={{display: 'inline-block', textAlign: 'right', fontSize: '0.9rem'}}>
<div style={{fontStyle: 'italics', fontSize: '.8rem'}}>{
post.last_updated && `updated ${date.toRelativeDate(new Date(post.last_updated))}`
}</div>
<div>{ date.toRelativeDate(new Date(post.created_at)) }</div>
2022-04-30 13:56:18 +00:00
</td>
2022-10-05 03:41:59 +00:00
<td style={{
flex: '1 1 60%',
alignItems: 'center',
fontFamily: `'EB Garamond', 'Garamond', 'Times New Roman', Times, serif`}}>
<Link href={`/posts/${post.slug}`} style={{textDecoration: 'none'}}>{post.title}</Link>
2022-04-30 13:56:18 +00:00
</td>
</tr>
2022-10-05 03:41:59 +00:00
}) ||
<div className='text center'>
<div>**crickets**</div>
<div>No posts found...</div>
<div><Link href='/' className='link button green back'>Go Home</Link></div>
2022-10-05 03:41:59 +00:00
</div>
}
2022-04-30 13:56:18 +00:00
</tbody>
</table>
</Layout>
)
}
2022-04-27 10:39:10 +00:00
export async function getStaticProps() {
2022-04-27 08:03:21 +00:00
return {
props: { postsMeta: getPostsMeta() }
};
}
export default PostsPage;