From 55548a94b61ce7d1ca0ca8da69db7566f937cfeb Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:26:36 +0100 Subject: FIX THE ICON SYSTEM --- apps/website/src/components/icons/Icon.astro | 12 +++++------- 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; -- cgit