feat: implement tag data loading and refactor tag handling in components

This commit is contained in:
sha
2025-05-01 02:30:44 +03:00
parent a49568a389
commit 9a7f61193b
7 changed files with 118 additions and 157 deletions
+27
View File
@@ -0,0 +1,27 @@
// Shared tag data loading and utilities
let tagsDataPromise = null;
let tagsData = null;
// Load tags data once and cache it
export function loadTagsData() {
if (!tagsDataPromise) {
tagsDataPromise = fetch('/data/tags.json')
.then(res => res.json())
.then(data => {
console.log('Tags data loaded successfully:', data);
tagsData = data;
return data;
})
.catch(err => {
console.error('Failed to load tags data:', err);
return {};
});
}
return tagsDataPromise;
}
// Get tag object (with color) from tag text
export function getTagObj(text) {
if (!tagsData) return { text };
return tagsData[text] ? { text, ...tagsData[text] } : { text };
}