Skip to content

Commit b7d0add

Browse files
committed
Fixed client-side node imports
1 parent 457ec03 commit b7d0add

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/components/ProductCatalog.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useState, type ChangeEvent } from "react";
2-
import { getIconData, iconToSVG } from "@iconify/utils";
3-
// @ts-ignore virtual module
4-
import iconCollection from "virtual:astro-icon";
5-
import { type CollectionEntry } from "astro:content";
2+
import type { CollectionEntry } from "astro:content";
3+
import type { IconifyIconBuildResult } from "@iconify/utils";
64

75
const ProductCatalog = ({
86
products,
97
}: {
10-
products: CollectionEntry<"products">[];
8+
products: (CollectionEntry<"products"> & {
9+
icon: IconifyIconBuildResult;
10+
groups: string[];
11+
})[];
1112
}) => {
1213
const [filters, setFilters] = useState<{
1314
search: string;
@@ -94,29 +95,24 @@ const ProductCatalog = ({
9495
</p>
9596
</div>
9697
)}
97-
{productList.map((product, idx) => {
98-
const iconData = getIconData(iconCollection.local, product.id);
99-
let icon = null;
100-
if (iconData) {
101-
icon = iconToSVG(iconData);
102-
}
98+
{productList.map((product) => {
10399
return (
104100
<a
105101
href={product.data.product.url}
106102
className="self-stretch p-3 border-gray-200 dark:border-gray-700 border-solid border rounded-md block !text-inherit no-underline hover:bg-gray-50 dark:hover:bg-black"
107103
>
108104
<div className="flex items-center">
109-
{icon && (
105+
{product.icon && (
110106
<div className="rounded-full p-2 bg-orange-50 mr-2 text-orange-500">
111107
<svg
112-
{...icon.attributes}
108+
{...product.icon.attributes}
113109
width={28}
114110
height={28}
115-
dangerouslySetInnerHTML={{ __html: icon.body }}
111+
dangerouslySetInnerHTML={{ __html: product.icon.body }}
116112
/>
117113
</div>
118114
)}
119-
{!icon && (
115+
{!product.icon && (
120116
<div className="flex items-center justify-center leading-none rounded-full p-2 bg-orange-50 mr-2 text-[color:var(--orange-accent-200)] text-xl font-bold w-11 h-11">
121117
{product.data.name.substr(0, 1)}
122118
</div>

src/icons/1.1.1.1.svg

Lines changed: 1 addition & 1 deletion
Loading

src/pages/products.astro

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
2-
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
32
import { getCollection, type CollectionEntry } from "astro:content";
4-
3+
// @ts-ignore virtual module
4+
import iconCollection from "virtual:astro-icon";
5+
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
6+
import { getIconData, iconToSVG } from "@iconify/utils";
57
import ProductCatalog from "~/components/ProductCatalog";
68
79
let products: CollectionEntry<"products">[] = await getCollection(
@@ -11,13 +13,22 @@ let products: CollectionEntry<"products">[] = await getCollection(
1113
},
1214
);
1315
14-
products = products.map((product) => ({
15-
...product,
16-
groups: [
17-
product.data.product.group,
18-
...(product.data.product.additional_groups || []),
19-
].filter((val) => Boolean(val)),
20-
}));
16+
products = products.map((product) => {
17+
const iconData = getIconData(iconCollection.local, product.id);
18+
let icon = null;
19+
if (iconData) {
20+
icon = iconToSVG(iconData);
21+
}
22+
23+
return {
24+
...product,
25+
icon,
26+
groups: [
27+
product.data.product.group,
28+
...(product.data.product.additional_groups || []),
29+
].filter((val) => Boolean(val)),
30+
};
31+
});
2132
2233
const frontmatter = {
2334
title: "Products",

0 commit comments

Comments
 (0)