diff --git a/src/components/Image.astro b/src/components/Image.astro index 4582c7c..6d634fb 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -1,7 +1,7 @@ --- import type { ImageMetadata } from "astro"; import { Picture as AstroImage } from "astro:assets"; -import { inferRemoteSize, inferSize } from "astro/assets/utils"; +import { inferRemoteSize } from "astro/assets/utils"; import { getProcessedImage } from "@helpers/image"; interface Props { src: ImageMetadata & { fsPath?: string; src?: string }; @@ -21,7 +21,7 @@ async function checkImage( const src = typeof image === "string" ? image : image.src; if (!src) return; try { - if (src.startsWith("/@fs") || src.startsWith("/_astro")) return {}; + if (src.startsWith("/@fs") || src.startsWith("/_astro")) return image; const res = await inferRemoteSize(src); if (res.format) { image.format = res.format; diff --git a/src/pages/resources/resources.ts b/src/content/resources.ts similarity index 100% rename from src/pages/resources/resources.ts rename to src/content/resources.ts diff --git a/src/pages/resources/[resourceType]/[resourceName].astro b/src/pages/resources/[resourceType]/[resourceName].astro index 2be48d8..e4fd782 100644 --- a/src/pages/resources/[resourceType]/[resourceName].astro +++ b/src/pages/resources/[resourceType]/[resourceName].astro @@ -3,7 +3,7 @@ import Layout from "@layouts/Layout.astro"; import { useTranslatedPath } from "@i18n/utils"; import ResourceDisplay from "@components/resources/Display.astro"; import * as memorium from "@helpers/memorium"; -import { resources as resourceTypes } from "../resources.ts"; +import { resources as resourceTypes } from "@content/resources.ts"; const { resourceType, resourceName } = Astro?.params; diff --git a/src/pages/resources/[resourceType]/index.astro b/src/pages/resources/[resourceType]/index.astro index 05d4ca6..db82eb0 100644 --- a/src/pages/resources/[resourceType]/index.astro +++ b/src/pages/resources/[resourceType]/index.astro @@ -2,7 +2,7 @@ import Layout from "@layouts/Layout.astro"; import HeroCard from "@components/HeroCard.astro"; import * as memorium from "@helpers/memorium"; -import { resources as resourceTypes } from "../resources.ts"; +import { resources as resourceTypes } from "@content/resources.ts"; import { useTranslations } from "@i18n/utils"; import ClientSearch from "@components/ClientSearch.svelte"; @@ -34,15 +34,19 @@ function isValidResource(res: any) { return !!res?.content?._type; } -function buildSearchTerm(res:any){ - if(!res) return ""; - return Object.keys(res).map((key) => { - if(key.startsWith("_")) return; - const value = res[key]; - if(Array.isArray(value)) return value.join(" "); - if(typeof value === "object") return buildSearchTerm(value); - return value - }).filter(s => !!s?.length).join(" ").toLowerCase(); +function buildSearchTerm(res: any) { + if (!res) return ""; + return Object.keys(res) + .map((key) => { + if (key.startsWith("_")) return; + const value = res[key]; + if (Array.isArray(value)) return value.join(" "); + if (typeof value === "object") return buildSearchTerm(value); + return value; + }) + .filter((s) => !!s?.length) + .join(" ") + .toLowerCase(); } --- @@ -52,7 +56,7 @@ function buildSearchTerm(res:any){ -
+
{ resources?.content .filter((res: any) => isValidResource(res)) diff --git a/src/pages/resources/index.astro b/src/pages/resources/index.astro index 1c45885..2a0725d 100644 --- a/src/pages/resources/index.astro +++ b/src/pages/resources/index.astro @@ -1,49 +1,54 @@ --- import Layout from "@layouts/Layout.astro"; import HeroCard from "@components/HeroCard.astro"; -import { resources } from "./resources.ts"; +import { resources } from "@content/resources.ts"; import { useTranslations } from "@i18n/utils"; import * as memorium from "@helpers/memorium"; const t = useTranslations(Astro.url); -async function getCoverImage(resourceName:string){ +async function getCoverImage(resourceName: string) { const resources = await memorium.listResource(resourceName); - if(!resources?.content) return ""; + if (!resources?.content) return ""; let amount = 0; - while (true){ + while (true) { amount++; - const randomResource = resources?.content[Math.floor(Math.random() * resources?.content.length)]; - const cover = randomResource?.content?.cover || randomResource?.content?.image; - if(cover){ - if(cover.startsWith("https://") || cover.startsWith("http://")){ + const randomResource = + resources?.content[Math.floor(Math.random() * resources?.content.length)]; + const cover = + randomResource?.content?.cover || randomResource?.content?.image; + if (cover) { + if (cover.startsWith("https://") || cover.startsWith("http://")) { continue; } return `https://marka.max-richter.dev/${cover}`; } - if(amount > 50) { + if (amount > 50) { break; } } } - --- { - await Promise.all(resources.map(async (resource) => { - const cover = await getCoverImage(resource.id); - console.log({cover}) - return - })) + await Promise.all( + resources.map(async (resource) => { + const cover = await getCoverImage(resource.id); + console.log({ cover }); + return ( + + ); + }), + ) }