www/components/recent-notes.tsx

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-04-28 16:37:12 +00:00
import Link from "next/link";
import NotesInfo from '../public/notes.json';
2022-04-28 16:37:12 +00:00
function RecentNotes() {
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();
}
);
2022-05-15 13:56:45 +00:00
return (
<div className='block'>
<h2>Recent Notes</h2>
<ul>
{notes?.slice(0, 5)
.map(({slug, title, mtime}) => {
return (
<li key={mtime.getTime()} >
<Link href={`/notes/${slug}`}>{title}</Link>
</li>
);
2022-05-15 13:56:45 +00:00
})
}
{
notes.length > 5 &&
<Link href='/notes'>More...</Link>
2022-05-15 13:56:45 +00:00
}
</ul>
</div>
2022-04-28 16:37:12 +00:00
);
}
export default RecentNotes;