Skip to content

Commit 8904925

Browse files
committed
feat: image loading optimization
1 parent ae1f16d commit 8904925

5 files changed

Lines changed: 32 additions & 40 deletions

File tree

src/components/Logo.astro

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
---
2-
import { SITE } from 'astrowind:config';
3-
import logoDark from '~/assets/images/logo-dark.svg'; // Logo negro para modo claro
4-
import logoLight from '~/assets/images/logo-light.png'; // Logo blanco para modo oscuro
5-
import Image from '~/components/common/Image.astro';
2+
import { Image } from 'astro:assets';
3+
import logoLight from '~/assets/images/logo-light.png';
4+
import logoDark from '~/assets/images/logo-dark.svg';
65
---
76

87
<span
9-
class="self-center ml-2 rtl:ml-0 rtl:mr-2 text-2xl md:text-xl font-bold text-gray-900 whitespace-nowrap dark:text-white"
8+
class="self-center ml-2 rtl:ml-0 rtl:mr-2 text-2xl md:text-xl font-bold text-gray-900 whitespace-nowrap dark:text-white flex items-center"
109
>
11-
<!-- Logo para modo claro (se oculta en modo oscuro) -->
12-
<Image
13-
src={logoDark}
14-
alt="Hackiit"
15-
width={80}
16-
class="mx-auto rounded-md w-full block dark:hidden"
17-
inferSize={true}
10+
<Image
11+
src={logoDark}
12+
alt="Hackiit Logo"
13+
class="h-8 md:h-10 w-auto block dark:hidden"
14+
loading="eager"
15+
fetchpriority="high"
1816
/>
1917

20-
<!-- Logo para modo oscuro (se oculta en modo claro) -->
21-
<Image
22-
src={logoLight}
23-
alt="Hackiit"
24-
width={80}
25-
class="mx-auto rounded-md w-full hidden dark:block"
26-
inferSize={true}
18+
<Image
19+
src={logoLight}
20+
alt="Hackiit Logo"
21+
class="h-8 md:h-10 w-auto hidden dark:block"
22+
loading="eager"
23+
fetchpriority="high"
2724
/>
2825
</span>

src/components/blog/GridItem.astro

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { APP_BLOG } from 'astrowind:config';
33
import type { Post } from '~/types';
44
5-
import Image from '~/components/common/Image.astro';
6-
5+
import { Image } from 'astro:assets';
76
import { findImage } from '~/utils/images';
87
import { getPermalink } from '~/utils/permalinks';
98
@@ -30,10 +29,9 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
3029
class="w-full md:h-full rounded shadow-lg bg-gray-400 dark:bg-slate-700"
3130
widths={[400, 900]}
3231
width={400}
32+
height={225}
3333
sizes="(max-width: 900px) 400px, 900px"
3434
alt={post.title}
35-
aspectRatio="16:9"
36-
layout="cover"
3735
loading="lazy"
3836
decoding="async"
3937
/>
@@ -44,10 +42,9 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
4442
class="w-full md:h-full rounded shadow-lg bg-gray-400 dark:bg-slate-700"
4543
widths={[400, 900]}
4644
width={400}
45+
height={225}
4746
sizes="(max-width: 900px) 400px, 900px"
4847
alt={post.title}
49-
aspectRatio="16:9"
50-
layout="cover"
5148
loading="lazy"
5249
decoding="async"
5350
/>
@@ -68,4 +65,4 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
6865
</h3>
6966

7067
<p class="text-muted dark:text-slate-400 text-lg">{post.excerpt}</p>
71-
</article>
68+
</article>

src/components/blog/ListItem.astro

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
---
22
import type { ImageMetadata } from 'astro';
33
import { Icon } from 'astro-icon/components';
4-
import Image from '~/components/common/Image.astro';
4+
import { Image } from 'astro:assets';
55
import PostTags from '~/components/blog/Tags.astro';
66
77
import { APP_BLOG } from 'astrowind:config';
88
import type { Post } from '~/types';
9-
109
import { getPermalink } from '~/utils/permalinks';
1110
import { findImage } from '~/utils/images';
1211
import { getFormattedDate } from '~/utils/utils';
13-
1412
export interface Props {
1513
post: Post;
1614
}
@@ -35,9 +33,9 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
3533
class="absolute inset-0 object-cover w-full h-full mb-6 rounded shadow-lg bg-gray-400 dark:bg-slate-700"
3634
widths={[400, 900]}
3735
width={900}
36+
height={506}
3837
sizes="(max-width: 900px) 400px, 900px"
3938
alt={post.title}
40-
aspectRatio="16:9"
4139
loading="lazy"
4240
decoding="async"
4341
/>
@@ -52,9 +50,9 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
5250
class="absolute inset-0 object-cover w-full h-full mb-6 rounded shadow-lg bg-gray-400 dark:bg-slate-700"
5351
widths={[400, 900]}
5452
width={900}
53+
height={506}
5554
sizes="(max-width: 900px) 400px, 900px"
5655
alt={post.title}
57-
aspectRatio="16:9"
5856
loading="lazy"
5957
decoding="async"
6058
/>
@@ -117,4 +115,4 @@ const link = APP_BLOG?.post?.isEnabled ? getPermalink(post.permalink, 'post') :
117115
)
118116
}
119117
</div>
120-
</article>
118+
</article>

src/components/blog/SinglePost.astro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
import { Icon } from 'astro-icon/components';
33
4-
import Image from '~/components/common/Image.astro';
4+
import { Image } from 'astro:assets';
5+
import { findImage } from '~/utils/images';
56
import PostTags from '~/components/blog/Tags.astro';
67
import SocialShare from '~/components/common/SocialShare.astro';
7-
88
import { getPermalink } from '~/utils/permalinks';
99
import { getFormattedDate } from '~/utils/utils';
1010
1111
import type { Post } from '~/types';
12-
1312
export interface Props {
1413
post: Post;
1514
url: string | URL;
1615
}
1716
1817
const { post, url } = Astro.props;
18+
const image = await findImage(post.image);
1919
---
2020

2121
<section class="py-8 sm:py-16 lg:py-20 mx-auto">
@@ -71,13 +71,13 @@ const { post, url } = Astro.props;
7171
</p>
7272

7373
{
74-
post.image ? (
74+
image ? (
7575
<Image
76-
src={post.image}
76+
src={image}
7777
class="max-w-full lg:max-w-[900px] mx-auto mb-6 sm:rounded-md bg-gray-400 dark:bg-slate-700"
7878
widths={[400, 900]}
7979
sizes="(max-width: 900px) 400px, 900px"
80-
alt={post?.excerpt || ''}
80+
alt={post?.title || ''}
8181
width={900}
8282
height={506}
8383
loading="eager"
@@ -100,4 +100,4 @@ const { post, url } = Astro.props;
100100
<SocialShare url={url} text={post.title} class="mt-5 sm:mt-1 align-middle text-gray-500 dark:text-slate-600" />
101101
</div>
102102
</article>
103-
</section>
103+
</section>

src/layouts/Layout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const { language, textDirection } = I18N;
4040
<ViewTransitions fallback="swap" />
4141
</head>
4242

43-
<body class="antialiased text-default bg-page tracking-tight">
43+
<body class="antialiased text-default bg-page tracking-tight">
4444
<slot />
4545

4646
<BasicScripts />

0 commit comments

Comments
 (0)