Skip to content

Commit 02dea7d

Browse files
committed
fix glob, images are loading
1 parent a84bf8f commit 02dea7d

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

docs/working-notes/todo3.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,5 +484,14 @@ For image resizing I would use a CDN - depending on usage you might be able to u
484484
For Gallery - https://benhowell.github.io/react-grid-gallery - which is client side React. For onscroll I used react-intersection-observer - https://www.builder.io/blog/react-intersection-observer
485485

486486
I hope this helps, sorry I can't share my code.
487+
----
488+
glob za slike
489+
poenta, ne sme da ima {} za jednu opciju
490+
ovo puca
491+
'/src/assets/images/all-images/*.{jpg}',
492+
ovo radi
493+
'/src/assets/images/all-images/*.jpg',
494+
495+
487496
------------
488497
```

src/components/Gallery.astro

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,41 @@
22
import { Image } from 'astro:assets';
33
44
import { IMAGE_SIZES } from '@/constants/image';
5+
import { cn } from '@/utils/styles';
56
67
import type { ImageMetadata } from 'astro';
78
9+
export interface Props extends astroHTML.JSX.HTMLAttributes {}
10+
11+
// filenames
12+
const EXCLUDE_IMAGES = ['avatar1.jpg'];
13+
814
const getAllImagesMetadata = (): ImageMetadata[] => {
9-
//
10-
// src/assets/images/all-images/river9.jpg
1115
const imageModules = import.meta.glob<{ default: ImageMetadata }>(
12-
'/src/assets/images/all-images/*.{jpg}',
16+
// cant be even variable
17+
'/src/assets/images/all-images/*.jpg',
1318
{ eager: true }
1419
);
1520
16-
console.log('imageModules', imageModules);
17-
18-
const imagesMetadata = Object.keys(imageModules).map((path) => imageModules[path].default);
21+
// convert map to array
22+
const imagesMetadata = Object.keys(imageModules)
23+
// filter excluded filenames
24+
.filter((path) => !EXCLUDE_IMAGES.some((excludedFileName) => path.endsWith(excludedFileName)))
25+
// return metadata array
26+
.map((path) => imageModules[path].default);
1927
return imagesMetadata;
2028
};
2129
2230
const imagesMetadata = getAllImagesMetadata();
31+
32+
const { class: className } = Astro.props;
2333
---
2434

25-
<ul>
35+
<ul class={cn('grid gap-4 grid-cols-1 sm:grid-cols-2 md:grid-cols-3', className)}>
2636
{
2737
imagesMetadata.map((image) => (
2838
<li>
29-
<Image {...IMAGE_SIZES.FIXED.MDX_XS_16_9} src={image} alt="my image" />
39+
<Image {...IMAGE_SIZES.FIXED.MDX_XXS_16_9} src={image} alt="my image" />
3040
</li>
3141
))
3242
}

src/components/react/ScrollToTop.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const ScrollToTop: React.FC<Props> = ({ children }) => {
5757
};
5858

5959
// bellow 100 or it will break again on fast scroll
60+
// todo: set threshold and remove debounce
6061
const debouncedCallback = debounce(callback, 20);
6162
const intersect = new IntersectionObserver(debouncedCallback);
6263

src/pages/gallery.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ description: 'Image gallery'
66

77
import Gallery from '../components/Gallery.astro';
88

9-
<Gallery />
9+
<Gallery class="not-prose" />

0 commit comments

Comments
 (0)