11---
2- import fs from ' node:fs' ;
3- import { fileURLToPath } from ' node:url' ;
4-
52interface Props {
63 id: string ;
74 alt: string ;
@@ -11,16 +8,20 @@ interface Props {
118const { id, alt, width = ' 20px' } = Astro .props ;
129
1310const isSvg = id .endsWith (' .svg' );
14- let svgContent: string | undefined ;
11+ const normalizedId = id .split (' /' ).pop () || id ;
12+
13+ const allSvgs = import .meta .glob <string >(
14+ ' /src/assets/Inline/**/*.svg' ,
15+ { query: ' ?raw' , eager: true , import: ' default' }
16+ );
1517
18+ let svgContent: string | undefined ;
1619if (isSvg ) {
17- const assetsDir = fileURLToPath (new URL (' ../assets/Inline' , import .meta .url ));
18- const normalizedId = id .split (' /' ).pop () || id ;
19- const svgPath = ` ${assetsDir }/${normalizedId } ` ;
20- try {
21- svgContent = fs .readFileSync (svgPath , ' utf-8' );
22- } catch {
23- // fall through to code fallback
20+ for (const [path, raw] of Object .entries (allSvgs )) {
21+ if (path .split (' /' ).pop () === normalizedId ) {
22+ svgContent = raw ;
23+ break ;
24+ }
2425 }
2526}
2627
@@ -29,7 +30,6 @@ const allImages = isSvg ? {} : import.meta.glob<{ default: ImageMetadata }>(
2930 { eager: true }
3031);
3132
32- const normalizedId = id .split (' /' ).pop () || id ;
3333let imageSrc: ImageMetadata | undefined ;
3434
3535if (! isSvg ) {
0 commit comments