www/pages/notes/index.tsx

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-04-28 16:37:12 +00:00
import Link from 'next/link';
2022-04-28 16:37:12 +00:00
import Layout from '../../components/layout';
import { toRelativeDate } from '../../lib/date';
import NotesInfo from '../../public/notes.json';
2022-04-28 16:37:12 +00:00
function NoteEntry({ note }: { note: { title: string, mtime: string, slug: string } }) {
2022-04-28 16:37:12 +00:00
return (
<tr>
<td style={{ flex: '1 0 50%' }}>
<Link href={`/notes/${note.slug}`}>
{note.title}
</Link>
</td>
<td style={{ fontStyle: 'italic' }}>
{note.mtime && toRelativeDate(note.mtime)}
</td>
</tr>
);
}
function NotesPage() {
const notes = Object.entries(NotesInfo)
.map(([slug, note]) => {
return {
slug,
title: note.title,
mtime: new Date(note.mtime)
}
})
.sort(
(a, b) => {
return b.mtime.getTime() - a.mtime.getTime();
}
);
return (
<Layout>
{
!notes || notes.length === 0
&& <>No notes found</>
|| <table>
<tbody>
{notes.map(
(note: any, i: number) => {
return (<NoteEntry note={note} key={i} />);
}
)}
</tbody>
</table>
}
2022-04-28 16:37:12 +00:00
</Layout>
)
}
export default NotesPage;