From 26ffc44ee72522891b4fdacac15134dfcf9c4859 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Mon, 12 Jan 2026 22:27:17 +0100 Subject: Rework how tags are working and make them native --- src/utils/micro.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/utils') 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 { 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(), + ), + ].sort((a, b) => b[1] - a[1]); +} -- cgit v1.2.3