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