Updated Icon Utility

This commit is contained in:
2025-08-16 12:01:55 +05:30
parent 6691f630a1
commit 653d5b005b
2 changed files with 14 additions and 4 deletions
+2
View File
@@ -22,6 +22,8 @@ npm i @wrnexus/astro
Theme Use
```bash
@import "@wrnexus/astro/theme.css";
@import "tailwindcss";
@theme {
+12 -4
View File
@@ -2,11 +2,19 @@ export const getDynamicIcon = async (name: string): Promise<string> => {
let icon = "";
let [prefix, iconName] = name.split(":");
await import(`../data/iconify/${prefix}.json`).then(module => {
const url = new URL(`../data/iconify/${prefix}.json`, import.meta.url);
try {
// @vite-ignore prevents pre-analysis of the dynamic path
const module: any = await import(/* @vite-ignore */ url.href);
icon = module.icons[iconName].body;
}).catch(error => {
console.error('Failed to load icon:', error);
});
} catch {
await import(`../data/iconify/${prefix}.json`).then(module => {
icon = module.icons[iconName].body;
}).catch(error => {
console.error('Failed to load icon:', error);
});
}
return icon
}