diff --git a/src/components/misc/ImageWrapper.astro b/src/components/misc/ImageWrapper.astro index a058b5a..824ca85 100644 --- a/src/components/misc/ImageWrapper.astro +++ b/src/components/misc/ImageWrapper.astro @@ -1,19 +1,21 @@ --- -import path from "path"; interface Props { id?: string; - src: string; + src: ImageMetadata | string; class?: string; alt?: string; position?: string; basePath?: string; } -import { Image } from "astro:assets"; + +import path from "path"; import { url } from "../../utils/url-utils"; -const { id, src, alt, position = "center", basePath = "/" } = Astro.props; +const { id, src: img, alt, position = "center", basePath = "/" } = Astro.props; const className = Astro.props.class; +const src = typeof img === "string" ? img : img.src; + const isLocal = !( src.startsWith("/") || src.startsWith("http") || @@ -24,23 +26,23 @@ const isPublic = src.startsWith("/"); // TODO temporary workaround for images dynamic import // https://github.com/withastro/astro/issues/3373 -let img: ImageMetadata; -if (isLocal) { +let optimizedImg: ImageMetadata; +if (isLocal && typeof img === "string") { const files = import.meta.glob("../../**", { import: "default", }); const normalizedPath = path .normalize(path.join("../../", basePath, src)) .replace(/\\/g, "/"); - img = await files[normalizedPath](); + optimizedImg = await files[normalizedPath](); } const imageClass = "w-full h-full object-cover"; const imageStyle = `object-position: ${position}`; --- -
+
- {isLocal && {alt} + {isLocal && {alt} {!isLocal && {alt}
diff --git a/src/content/config.ts b/src/content/config.ts index b037fc9..ff87951 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,15 +1,16 @@ import { defineCollection, z } from "astro:content"; const postsCollection = defineCollection({ - schema: z.object({ - title: z.string(), - published: z.date(), - draft: z.boolean().optional(), - description: z.string().optional(), - image: z.string().optional(), - tags: z.array(z.string()).optional(), - category: z.string().optional(), - }), + schema: ({ image }) => + z.object({ + title: z.string(), + published: z.date(), + draft: z.boolean().optional(), + description: z.string().optional(), + image: image().optional(), + tags: z.array(z.string()).optional(), + category: z.string().optional(), + }), }); export const collections = { posts: postsCollection, diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 0eb6deb..e9993f9 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -22,9 +22,10 @@ interface Props { title: string; banner: string; description?: string; + cover?: string; } -let { title, banner, description } = Astro.props; +let { title, banner, description, cover } = Astro.props; const isHomePage = pathsEqual(Astro.url.pathname, "/"); @@ -56,11 +57,11 @@ const myFade = { // why doing this in Layout instead of GlobalStyles: https://github.com/withastro/astro/issues/6728#issuecomment-1502203757 const configHue = siteConfig.themeColor.hue; if (!banner || typeof banner !== "string" || banner.trim() === "") { - banner = siteConfig.banner.src; + banner = cover ?? siteConfig.banner.src; } // TODO don't use post cover as banner for now -banner = siteConfig.banner.src; +// banner = siteConfig.banner.src; const enableBanner = siteConfig.banner.enable; @@ -91,6 +92,7 @@ const siteLang = siteConfig.lang.replace("_", "-"); + diff --git a/src/layouts/MainGridLayout.astro b/src/layouts/MainGridLayout.astro index 8da230a..8848f4f 100644 --- a/src/layouts/MainGridLayout.astro +++ b/src/layouts/MainGridLayout.astro @@ -11,14 +11,15 @@ interface Props { title: string; banner?: string; description?: string; + cover?: string; } -const { title, banner, description } = Astro.props; +const { title, banner, description, cover } = Astro.props; const isHomePage = pathsEqual(Astro.url.pathname, "/"); const enableBanner = siteConfig.banner.enable; --- - +
img.src); +} + +console.log(coverImageUrl); --- - +
{entry.data.image && -