diff --git a/client/src/collections/strapiPoleElementsLoader.mjs b/client/src/collections/strapiPoleElementsLoader.mjs new file mode 100644 index 00000000..538a9472 --- /dev/null +++ b/client/src/collections/strapiPoleElementsLoader.mjs @@ -0,0 +1,61 @@ +import { defineCollection, z } from "astro:content"; +import qs from "qs"; + +// Define a custom content collection that loads data from Strapi +const strapiPoleElementsLoader = defineCollection({ + // Async loader function that fetches data from Strapi API + loader: async () => { + // Get Strapi URL from environment variables or fallback to localhost + const BASE_URL = import.meta.env.STRAPI_URL || "http://localhost:1337"; + const path = "/api/elements"; + const url = new URL(path, BASE_URL); + + // Build query parameters using qs to populate cover image data + url.search = qs.stringify({ + populate: { + mainImage: { + fields: ["url", "alternativeText"], + }, + }, + }); + + // Fetch articles from Strapi + const poleElementsData = await fetch(url.href); + const { data }= await poleElementsData.json(); + + // Transform the API response into the desired data structure + return data.map((item) => ({ + id: item.id.toString(), + name: item.name, + title: item.name, + description: item.description, + createdAt: item.createdAt, + updatedAt: item.updatedAt, + publishedAt: item.publishedAt, + mainImage: { + id: Number(item.mainImage.id), + documentId: item.mainImage.documentId, + url: item.mainImage.url, + alternativeText: item.mainImage.alternativeText, + } + })); + }, + // Define the schema for type validation using Zod + schema: z.object({ + id: z.string(), + name: z.string(), + title: z.string(), + description: z.string(), + createdAt: z.string(), + updatedAt: z.string(), + publishedAt: z.string(), + mainImage: z.object({ + id: z.number(), + documentId: z.string(), + url: z.string(), + alternativeText: z.string(), + }), + }), +}); + +export default strapiPoleElementsLoader; \ No newline at end of file diff --git a/client/src/components/ElementsCard.astro b/client/src/components/ElementsCard.astro deleted file mode 100644 index 730d974f..00000000 --- a/client/src/components/ElementsCard.astro +++ /dev/null @@ -1,46 +0,0 @@ ---- -// BigCard component - configurable card with link -interface Props { - url: string; -} - -const { url } = Astro.props; ---- - -
\ No newline at end of file diff --git a/client/src/components/PoleElementsList.astro b/client/src/components/PoleElementsList.astro index 12b923b6..ed37698a 100644 --- a/client/src/components/PoleElementsList.astro +++ b/client/src/components/PoleElementsList.astro @@ -18,21 +18,23 @@ const BASE_URL = getStrapiBaseUrl();