summaryrefslogtreecommitdiff
path: root/src/utils/micro.ts
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2026-01-12 22:27:17 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2026-01-12 22:27:17 +0100
commit26ffc44ee72522891b4fdacac15134dfcf9c4859 (patch)
tree0a4014f93f35b348f9e5062904e17d724f228a69 /src/utils/micro.ts
parent686ccbfd2ed51723f4df79ba0b976e0f5fafce2f (diff)
Rework how tags are working and make them native
Diffstat (limited to 'src/utils/micro.ts')
-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]);
+}