diff options
author | LynithDev <61880709+LynithDev@users.noreply.github.com> | 2024-01-20 17:26:36 +0100 |
---|---|---|
committer | LynithDev <61880709+LynithDev@users.noreply.github.com> | 2024-01-20 17:26:36 +0100 |
commit | 55548a94b61ce7d1ca0ca8da69db7566f937cfeb (patch) | |
tree | 54172a78823cf76761ab88e21d6d2c64d5b965c3 /apps | |
parent | 0225e2e17d12a32467bc12f33b2402287c79e23f (diff) | |
download | Nexus-55548a94b61ce7d1ca0ca8da69db7566f937cfeb.tar.gz Nexus-55548a94b61ce7d1ca0ca8da69db7566f937cfeb.tar.bz2 Nexus-55548a94b61ce7d1ca0ca8da69db7566f937cfeb.zip |
FIX THE ICON SYSTEM
Diffstat (limited to 'apps')
-rw-r--r-- | apps/website/src/components/icons/Icon.astro | 12 | ||||
-rw-r--r-- | apps/website/src/components/logos/Logo.astro | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/apps/website/src/components/icons/Icon.astro b/apps/website/src/components/icons/Icon.astro index f57ee4f..cfb14ca 100644 --- a/apps/website/src/components/icons/Icon.astro +++ b/apps/website/src/components/icons/Icon.astro @@ -1,5 +1,4 @@ --- -import { readFile } from 'node:fs/promises'; import type { HTMLAttributes } from 'astro/types'; import { parse } from 'node-html-parser'; @@ -41,9 +40,8 @@ interface Props extends HTMLAttributes<'svg'> { size?: number | [number, number] } -async function getSVG(name: string, path = 'impl') { - const dir = new URL(`${path}`, import.meta.url).pathname; - const file = await readFile(`${dir}/${name}.svg`, { encoding: 'utf-8' }); +async function getSVG(name: string) { + const file = (await import(`./impl/${name}.svg?raw`)).default; if (!file) throw new Error(`${name} not found`); @@ -66,7 +64,6 @@ async function getSVG(name: string, path = 'impl') { const { icon, size, - path = 'impl', ...attributes } = Astro.props as Props; @@ -91,7 +88,7 @@ try { }; }; - const { attributes: baseAttributes, innerHTML } = await getSVG(icon, path); + const { attributes: baseAttributes, innerHTML } = await getSVG(icon); svgAttributes = { ...baseAttributes, ...attributes, @@ -101,7 +98,8 @@ try { const colorRegex = /(fill|stroke)=\"([^"]*)\"/g; html = innerHTML.replaceAll(colorRegex, '$1="currentColor"'); } -catch (err) { + catch (err) { + console.error(err); // ignored } --- diff --git a/apps/website/src/components/logos/Logo.astro b/apps/website/src/components/logos/Logo.astro index 6b085fa..cd780ad 100644 --- a/apps/website/src/components/logos/Logo.astro +++ b/apps/website/src/components/logos/Logo.astro @@ -18,11 +18,11 @@ const { let svg: string | undefined; try { - if (logo === undefined) + if (logo === '' || logo === undefined) return; const dir = new URL(join('..', '..', '..', 'public', 'media'), import.meta.url).pathname; - svg = (await readFile(`${dir}/${logo.replaceAll('.', '/')}.svg`, { encoding: 'utf8' })); + svg = (await readFile(`${dir}/${logo.replaceAll('.', '/')}.svg`)).toString(); if (svg === undefined) return; |