1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-28 16:48:00 +02:00

custom Picture component

This commit is contained in:
Matthias Kretschmann 2023-09-03 13:19:17 +01:00
parent d87ddd35d1
commit 3973834d61
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 20 additions and 34 deletions

View File

@ -1,6 +1,6 @@
---
import Image from '@components/core/Image.astro'
import type { CollectionEntry } from 'astro:content'
import Picture from './core/Picture.astro'
type Props = CollectionEntry<'photos'>
@ -29,7 +29,7 @@ const { title, image } = Astro.props.data
{
image ? (
<a href={slug}>
<Image
<Picture
width={316}
height={316}
image={image}

View File

@ -1,7 +1,7 @@
---
import Image from '@components/core/Image.astro'
import PostTitle from './layouts/Post/Title.astro'
import styles from './PostTeaser.module.css'
import Picture from './core/Picture.astro'
const { title, date, updated, hideDate, image, toggleSearch, slug } =
Astro.props
@ -10,7 +10,7 @@ const { title, date, updated, hideDate, image, toggleSearch, slug } =
<a class={styles.post} href={slug} onclick={toggleSearch && toggleSearch}>
{
image ? (
<Image image={image} alt={title} width={480} height={180} />
<Picture image={image} alt={title} width={480} height={180} />
) : (
<span class={styles.empty} />
)

View File

@ -29,7 +29,7 @@
}
.empty {
composes: frame from './core/Image.module.css';
composes: frame from './core/Picture.module.css';
display: block;
min-height: 95px;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACaADAAQAAAABAAAACQAAAAAvQpmhAAAAHElEQVQYGWNgoBL4T8gcggoIGcBA0ASCCmhsBQBhFwX7u70C8QAAAABJRU5ErkJggg==');

View File

@ -1,20 +0,0 @@
---
import { Image, type ImgAttributes } from 'astro:assets'
import styles from './Image.module.css'
type Props = {
image: ImgAttributes
alt: string
title?: string
class?: string
width?: number
height?: number
}
const { title, image, class: className, ...rest } = Astro.props
---
<figure class={`${styles.image} ${className ? className : ''}`}>
<Image src={image} {...rest} />
{title && <figcaption class={styles.imageTitle}>{title}</figcaption>}
</figure>

View File

@ -1,9 +1,10 @@
---
import { getImage, type ImgAttributes } from 'astro:assets'
import styles from './Image.module.css'
import { getImage } from 'astro:assets'
import type { ImageMetadata } from 'astro'
import styles from './Picture.module.css'
type Props = {
image: ImgAttributes
image: ImageMetadata
alt: string
title?: string
class?: string
@ -12,10 +13,11 @@ type Props = {
}
const { title, alt, image, class: className } = Astro.props
const { src } = image
const src = image
const sizes = [260, 520, 1040, 2080]
// TODO: make less repetitive
const image260_webp = await getImage({ src, width: 260, format: 'webp' })
const image520_webp = await getImage({ src, width: 520, format: 'webp' })
const image1040_webp = await getImage({ src, width: 1040, format: 'webp' })

View File

@ -2,7 +2,7 @@
import Time from '@components/core/Time.astro'
type Props = {
date: Date
date: Date | undefined
updated?: Date
}

View File

@ -1,11 +1,11 @@
---
import type { CollectionEntry } from 'astro:content'
import LayoutBase from '@layouts/Base/index.astro'
import Image from '@components/core/Image.astro'
import Title from './Title.astro'
import Actions from './Actions.astro'
import styles from './index.module.css'
import Meta from './Meta.astro'
import Picture from '@components/core/Picture.astro'
type Props = CollectionEntry<'articles' | 'links' | 'photos'> & {
lead?: string // comes in through remark plugin as html
@ -25,9 +25,13 @@ const { title, date, updated, image, linkurl } = data
{
image && (
<div class={styles.image}>
<Image width={1040} height={460} image={image} alt={title} />
</div>
<Picture
class={styles.image}
width={1040}
height={460}
image={image}
alt={title}
/>
)
}