www/pages/index.tsx

55 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-12-08 03:38:31 +00:00
import Link from 'next/link';
import React from 'react';
import Layout from '../components/layout';
import Pages from '../public/pages.json';
import style from '../styles/home.module.css';
import prettyDatePrint from '../util/pretty-date';
2022-04-27 08:03:21 +00:00
import { getPostsMeta, PostMeta } from '../util/slug';
2021-12-08 03:38:31 +00:00
2022-04-27 09:10:49 +00:00
function HomePage(props: { postsMeta: PostMeta[] }) {
2022-04-27 08:03:21 +00:00
props.postsMeta.sort((x, y) => { return (x.title).localeCompare(y.title) });
2021-12-08 03:38:31 +00:00
return (
<Layout name='' title='PaulW.XYZ'>
<section className='block'>
<div className='h2'>Welcome!</div>
{
2021-12-08 03:38:31 +00:00
Pages.map(obj => {
return <span key={obj.link}>
2021-12-08 03:38:31 +00:00
<Link href={obj.link}>
2022-04-27 09:10:49 +00:00
{
obj.link.match(/^http/)
? <a className={`button blue ${style.button} ${style.blueButton}`}>{obj.title}</a>
: <a className={`${style.button} button`}>{obj.title}</a>
}
2021-12-08 03:38:31 +00:00
</Link>
</span>
2021-12-08 03:38:31 +00:00
})
}
</section>
<section className='block'>
<table style={{ width: '100%' }}>
<th className='h2'>Posts</th> <th>Posted</th>
2022-04-27 08:03:21 +00:00
{props.postsMeta?.map((post: any) => {
return <tr key={post.slug}>
<td className='h5'>
<Link href={`posts/${post.slug}`}>
{post.title}
</Link>
</td>
<td>{prettyDatePrint(new Date(post.created_at))}</td>
</tr>
})}
</table>
</section>
2021-12-08 03:38:31 +00:00
</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 HomePage;