Skip to content

Commit 1aade13

Browse files
committed
[Layout] images optimization in desktop and lite
1 parent bceec95 commit 1aade13

32 files changed

+104
-39
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import type { ImageMetadata } from "astro";
3+
import { Image } from "astro:assets";
4+
import { trimStart } from "lodash-es";
5+
6+
interface Props {
7+
imageRelativePath: string;
8+
alt: string;
9+
opacity?: number;
10+
}
11+
const { opacity, imageRelativePath, alt } = Astro.props;
12+
13+
const imageAbsolutePath = `/src/images/${trimStart(imageRelativePath, "/")}`;
14+
15+
const images = import.meta.glob<{ default: ImageMetadata }>("/src/images/**/*.{jpeg,jpg,png,gif}");
16+
console.log(images[imageAbsolutePath]);
17+
if (!images[imageAbsolutePath])
18+
throw new Error(`"${imageAbsolutePath}" does not exist in glob: "src/images/*.{jpeg,jpg,png,gif}"`);
19+
---
20+
21+
<div class="feature-background" style={opacity ? { opacity } : undefined}>
22+
<Image src={images[imageAbsolutePath]()} alt={alt} layout="full-width" />
23+
</div>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)