summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/micro.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/micro.ts b/src/utils/micro.ts
index 51d336b..7f06b41 100644
--- a/src/utils/micro.ts
+++ b/src/utils/micro.ts
@@ -18,3 +18,23 @@ export async function getAllMicroPosts(): Promise<MicroEntry[]> {
return [];
}
}
+
+/** Extract all tags from micro posts */
+export function getAllMicroTags(entries: MicroEntry[]): string[] {
+ return entries.flatMap((entry) => entry.data.tags ?? []);
+}
+
+/** Get unique tags from micro posts */
+export function getUniqueMicroTags(entries: MicroEntry[]): string[] {
+ return [...new Set(getAllMicroTags(entries))];
+}
+
+/** Get unique tags with counts from micro posts */
+export function getUniqueMicroTagsWithCount(entries: MicroEntry[]): [string, number][] {
+ return [
+ ...getAllMicroTags(entries).reduce(
+ (acc, t) => acc.set(t, (acc.get(t) ?? 0) + 1),
+ new Map<string, number>(),
+ ),
+ ].sort((a, b) => b[1] - a[1]);
+}