feat: add functions to retrieve unique snippet tags and category counts

This commit is contained in:
2025-12-25 18:45:13 +00:00
parent 5e4e2a3ab5
commit c7ef4ae15b
2 changed files with 32 additions and 0 deletions

View File

@@ -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<string>()
for (const snippet of LUA_SNIPPETS) {
for (const tag of snippet.tags) {
tagSet.add(tag)
}
}
return Array.from(tagSet).sort()
}

View File

@@ -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<string, number> => {
const counts: Record<string, number> = { All: LUA_SNIPPETS.length }
for (const snippet of LUA_SNIPPETS) {
counts[snippet.category] = (counts[snippet.category] || 0) + 1
}
return counts
}