Skip to content

Commit

Permalink
feat(bookmarks): update bookmarks page
Browse files Browse the repository at this point in the history
  • Loading branch information
noghartt committed Oct 31, 2024
1 parent 4abc7e6 commit 5b5be50
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/pages/bookmarks/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import Link from "../../components/Link.astro";
import bookmarksJson from './_bookmarks.json';
const bookmarksData = bookmarksJson.data;
const bookmarksSorted = bookmarksData.sort((a, b) =>
Math.floor(Number(b.savedAt) / 1000) -
Math.floor(Number(a.savedAt) / 1000)
);
const groupByMonth = (bookmarks) => {
const grouped = bookmarks.reduce((acc, bookmark) => {
const month = dayjs(bookmark.savedAt).format('YYYY [/] MMMM');
const month = dayjs(bookmark.savedAt).startOf('month').toISOString();
if (!acc[month]) {
acc[month] = [];
}
Expand All @@ -25,9 +21,17 @@ const groupByMonth = (bookmarks) => {
return grouped;
};
const bookmarksGroupedByMonth = groupByMonth(bookmarksSorted);
const sortByMonth = (bookmarks) =>
Object.fromEntries(
Object.entries(bookmarks)
.sort(([a], [b]) => dayjs(a).isBefore(b, 'month') ? 1 : -1)
.map(([month, bookmark]) => [dayjs(month).format('YYYY [/] MMMM'), bookmark])
);
const tableOfContents = Object.entries(bookmarksGroupedByMonth).map(([month, bookmarks]) => ({
const bookmarksGroupedByMonth = groupByMonth(bookmarksData);
const bookmarksSorted = sortByMonth(bookmarksGroupedByMonth);
const tableOfContents = Object.keys(bookmarksSorted).map((month) => ({
text: month,
url: `#${month}`,
depth: 1,
Expand Down Expand Up @@ -74,7 +78,7 @@ const tableOfContents = Object.entries(bookmarksGroupedByMonth).map(([month, boo
</ul>
</details>
<section class="bookmarks">
{Object.entries(bookmarksGroupedByMonth).map(([month, bookmarks]) => (
{Object.entries(bookmarksSorted).map(([month, bookmarks]) => (
<div class="description">
<h3 id={month}>
<a class="heading-link" href={`#${month}`}>
Expand Down

0 comments on commit 5b5be50

Please sign in to comment.