feat: add archives page with configurable menu (#386)

* feat: add archives page with configurable menu

* optimize: compat mobile layout

* fix: update archive menu layout

* fix: hide archives page from URL if showArchives is false

* docs: add `showArchives` option in docs

Resolves #361

---------

Co-authored-by: satnaing <satnaingdev@gmail.com>
This commit is contained in:
Patrick Wilson
2024-10-14 19:49:40 +08:00
committed by GitHub
parent 58a0d25743
commit 7573617e79
7 changed files with 146 additions and 3 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { CollectionEntry } from "astro:content";
type GroupKey = string | number | symbol;
interface GroupFunction<T> {
(item: T, index?: number): GroupKey;
}
const getPostsByGroupCondition = (
posts: CollectionEntry<"blog">[],
groupFunction: GroupFunction<CollectionEntry<"blog">>
) => {
const result: Record<GroupKey, CollectionEntry<"blog">[]> = {};
for (let i = 0; i < posts.length; i++) {
const item = posts[i];
const groupKey = groupFunction(item, i);
if (!result[groupKey]) {
result[groupKey] = [];
}
result[groupKey].push(item);
}
return result;
};
export default getPostsByGroupCondition;