refactor: convert Picture component to use AstroImageTools

This commit is contained in:
Stefan Imhoff
2023-05-18 16:06:38 +02:00
parent 5f66147900
commit 53fffc4f74
4 changed files with 9 additions and 10 deletions

View File

@@ -1,13 +1,12 @@
--- ---
import cx from 'classnames'; import cx from 'classnames';
import { Picture } from '@astrojs/image/components'; import { Picture } from 'astro-imagetools/components';
import type { PictureComponentLocalImageProps } from '@astrojs/image/components'; import type { PictureConfigOptions } from 'astro-imagetools';
interface Props extends PictureComponentLocalImageProps { interface Props extends PictureConfigOptions {
class?: string; class?: string;
noMargin?: boolean; noMargin?: boolean;
slot?: string;
} }
const { class: className, noMargin, ...props } = Astro.props; const { class: className, noMargin, ...props } = Astro.props;

View File

@@ -18,9 +18,9 @@ const { project } = Astro.props;
) : ( ) : (
<Picture <Picture
alt={project.data.title} alt={project.data.title}
aspectRatio={project.data.image.aspectRatio as number | `${number}:${number}`} aspect={project.data.image.aspectRatio}
formats={['webp', 'avif']} breakpoints={[300, 500, 700, 1000, 1200, 1500]}
widths={[300, 500, 700, 1000, 1200, 1500]} format={['webp', 'avif']}
src={project.data.image.src} src={project.data.image.src}
/> />
)) ))

View File

@@ -17,7 +17,7 @@ const projectCollection = defineCollection({
src: z.string(), src: z.string(),
height: z.number().optional(), height: z.number().optional(),
width: z.number().optional(), width: z.number().optional(),
aspectRatio: z.union([z.number(), z.string().regex(/^\d+:\d+$/)]), aspectRatio: z.number().optional(),
}) })
.optional(), .optional(),
sort: z.number().optional(), sort: z.number().optional(),

View File

@@ -16,10 +16,10 @@ const { frontmatter } = Astro.props;
> >
<Picture <Picture
alt="Stefan Imhoff" alt="Stefan Imhoff"
aspectRatio="1:1" aspect={1}
breakpoints={[300, 512]}
class="[&_img]:xl:-scale-x-100" class="[&_img]:xl:-scale-x-100"
src="/assets/images/ai-portrait-stefan-imhoff.png" src="/assets/images/ai-portrait-stefan-imhoff.png"
widths={[300, 512]}
/> />
</div> </div>
<slot /> <slot />