From c7ef4ae15b9166c02bbee383ef855011389c173c Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Thu, 25 Dec 2025 18:45:13 +0000 Subject: [PATCH] feat: add functions to retrieve unique snippet tags and category counts --- .../lib/lua/functions/get-all-snippet-tags.ts | 17 +++++++++++++++++ .../functions/get-snippet-category-counts.ts | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 frontends/nextjs/src/lib/lua/functions/get-all-snippet-tags.ts create mode 100644 frontends/nextjs/src/lib/lua/functions/get-snippet-category-counts.ts diff --git a/frontends/nextjs/src/lib/lua/functions/get-all-snippet-tags.ts b/frontends/nextjs/src/lib/lua/functions/get-all-snippet-tags.ts new file mode 100644 index 000000000..06b7884e0 --- /dev/null +++ b/frontends/nextjs/src/lib/lua/functions/get-all-snippet-tags.ts @@ -0,0 +1,17 @@ +import { LUA_SNIPPETS } from '../snippets/lua-snippets-data' + +/** + * Get all unique tags across snippets + * @returns Sorted list of tags + */ +export const getAllSnippetTags = (): string[] => { + const tagSet = new Set() + + for (const snippet of LUA_SNIPPETS) { + for (const tag of snippet.tags) { + tagSet.add(tag) + } + } + + return Array.from(tagSet).sort() +} diff --git a/frontends/nextjs/src/lib/lua/functions/get-snippet-category-counts.ts b/frontends/nextjs/src/lib/lua/functions/get-snippet-category-counts.ts new file mode 100644 index 000000000..908d15c11 --- /dev/null +++ b/frontends/nextjs/src/lib/lua/functions/get-snippet-category-counts.ts @@ -0,0 +1,15 @@ +import { LUA_SNIPPETS } from '../snippets/lua-snippets-data' + +/** + * Get count of snippets per category + * @returns Category counts with "All" included + */ +export const getSnippetCategoryCounts = (): Record => { + const counts: Record = { All: LUA_SNIPPETS.length } + + for (const snippet of LUA_SNIPPETS) { + counts[snippet.category] = (counts[snippet.category] || 0) + 1 + } + + return counts +}