Skip to content

Commit 1680d20

Browse files
committed
inline component rendering bugfix
1 parent 96ca6e2 commit 1680d20

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/components/Inline.astro

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
import fs from 'node:fs';
3-
import { fileURLToPath } from 'node:url';
4-
52
interface Props {
63
id: string;
74
alt: string;
@@ -11,16 +8,20 @@ interface Props {
118
const { id, alt, width = '20px' } = Astro.props;
129
1310
const 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;
1619
if (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;
3333
let imageSrc: ImageMetadata | undefined;
3434
3535
if (!isSvg) {

0 commit comments

Comments
 (0)