feat: convert hero section to use randomly selected images stored in directus
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
---
|
||||
import { Image } from 'astro:assets';
|
||||
import { readItems } from '@directus/sdk';
|
||||
|
||||
import type { HeaderImage } from '@lib/directusTypes';
|
||||
|
||||
import GoLinkPrimaryButton from '@components/buttons/GoLinkPrimaryButton.astro';
|
||||
import GoLinkSecondaryButton from '@components/buttons/GoLinkSecondaryButton.astro';
|
||||
import directus from '@lib/directus';
|
||||
import { getDirectusImageURL } from '@/support/url';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
@@ -11,14 +16,20 @@ interface Props {
|
||||
primaryBtnURL?: string;
|
||||
secondaryBtn?: string;
|
||||
secondaryBtnURL?: string;
|
||||
src?: any;
|
||||
alt?: string;
|
||||
rounded?: boolean;
|
||||
}
|
||||
|
||||
const { title, subTitle, primaryBtn, primaryBtnURL, secondaryBtn, secondaryBtnURL, src, alt } = Astro.props;
|
||||
const { title, subTitle, primaryBtn, primaryBtnURL, secondaryBtn, secondaryBtnURL } = Astro.props;
|
||||
|
||||
const roundedClasses = Astro.props.rounded ? "rounded-2xl" : null;
|
||||
const imagesData = ((await directus.request(
|
||||
readItems('header_images', {
|
||||
fields: ['*'],
|
||||
})
|
||||
)) as unknown) as HeaderImage[];
|
||||
|
||||
const images = await Promise.all(imagesData.map(async (img) => ({
|
||||
...img,
|
||||
src: await getDirectusImageURL(img.image)
|
||||
})));
|
||||
---
|
||||
|
||||
<section class="mx-auto grid max-w-340 gap-4 px-4 py-14 sm:px-6 md:grid-cols-2 md:items-center md:gap-8 lg:px-8 2xl:max-w-full">
|
||||
@@ -38,20 +49,53 @@ const roundedClasses = Astro.props.rounded ? "rounded-2xl" : null;
|
||||
</div>
|
||||
|
||||
<div class="smooth-reveal-fade md:block w-full hidden">
|
||||
<div class="flex justify-center w-full top-12 md:ml-4 overflow-hidden">
|
||||
{src && alt && (
|
||||
<Image
|
||||
src={src}
|
||||
alt={alt}
|
||||
class={`h-full w-105 scale-100 object-cover object-center ${roundedClasses}`}
|
||||
draggable="false"
|
||||
loading="eager"
|
||||
format="webp"
|
||||
quality="low"
|
||||
widths={[840]}
|
||||
inferSize={true}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
class="flex justify-center w-full top-12 md:ml-4 overflow-hidden no-js-fallback"
|
||||
id="hero-image-container"
|
||||
>
|
||||
{images.map((img, index) => (
|
||||
<div
|
||||
class="hero-image hidden justify-center w-full h-full"
|
||||
data-index={index}
|
||||
>
|
||||
<Image
|
||||
class="h-full w-105 scale-100 object-cover object-center"
|
||||
src={img.src}
|
||||
alt={img.image_alt}
|
||||
draggable="false"
|
||||
loading="eager"
|
||||
format="webp"
|
||||
widths={[840]}
|
||||
inferSize={true}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<style>
|
||||
.no-js-fallback .hero-image:first-child {
|
||||
display: flex !important;
|
||||
}
|
||||
</style>
|
||||
<script is:inline>
|
||||
document.getElementById('hero-image-container')?.classList.remove('no-js-fallback');
|
||||
</script>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
document.addEventListener('astro:page-load', () => {
|
||||
const container = document.getElementById('hero-image-container');
|
||||
if (container) {
|
||||
const images = container.querySelectorAll('.hero-image');
|
||||
images.forEach(img => {
|
||||
img.classList.remove('flex');
|
||||
img.classList.add('hidden');
|
||||
});
|
||||
if (images.length > 0) {
|
||||
const randomIndex = Math.floor(Math.random() * images.length);
|
||||
images[randomIndex].classList.remove('hidden');
|
||||
images[randomIndex].classList.add('flex');
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.8 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.5 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB |
@@ -5,6 +5,7 @@ import type {
|
||||
Weather,
|
||||
Post,
|
||||
Category,
|
||||
HeaderImage,
|
||||
Application,
|
||||
Experience,
|
||||
Education,
|
||||
@@ -20,6 +21,7 @@ type Schema = {
|
||||
site_weather: Weather;
|
||||
posts: Post[];
|
||||
categories: Category[];
|
||||
header_images: HeaderImage[];
|
||||
site_applications: Application;
|
||||
site_experience: Experience;
|
||||
site_education: Education;
|
||||
|
||||
@@ -61,6 +61,12 @@ export type Category = {
|
||||
logoDark: string;
|
||||
};
|
||||
|
||||
export type HeaderImage = {
|
||||
id: string;
|
||||
image: string;
|
||||
image_alt: string;
|
||||
};
|
||||
|
||||
export type Application = {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
@@ -9,8 +9,6 @@ import SkillsSliderSection from '@components/sections/SkillsSliderSection.astro'
|
||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||
import directus from '@lib/directus';
|
||||
|
||||
import portraitImg from '@images/portrait.avif';
|
||||
|
||||
const global = await directus.request(readSingleton('site_global'));
|
||||
---
|
||||
|
||||
@@ -37,9 +35,6 @@ const global = await directus.request(readSingleton('site_global'));
|
||||
<HeroSection
|
||||
title="About Me"
|
||||
subTitle={global.about}
|
||||
src={portraitImg}
|
||||
alt={global.portrait_alt}
|
||||
rounded={true}
|
||||
/>
|
||||
|
||||
<section class="max-w-7xl px-4 sm:px-6 lg:px-8 py-10 lg:py-14 mx-auto">
|
||||
|
||||
@@ -6,8 +6,6 @@ import ApplicationSection from '@components/sections/ApplicationSection.astro';
|
||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||
import directus from '@lib/directus';
|
||||
|
||||
import applicationImg from '@images/cedar_tree.png';
|
||||
|
||||
const global = await directus.request(readSingleton('site_global'));
|
||||
---
|
||||
|
||||
@@ -34,8 +32,6 @@ const global = await directus.request(readSingleton('site_global'));
|
||||
<HeroSection
|
||||
title="Applications"
|
||||
subTitle={global.about_applications}
|
||||
src={applicationImg}
|
||||
alt={global.applications_image_alt}
|
||||
/>
|
||||
|
||||
<ApplicationSection className="smooth-reveal-2" />
|
||||
|
||||
@@ -10,8 +10,6 @@ import AllPostsSection from '@components/sections/AllPostsSection.astro';
|
||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||
import directus from '@lib/directus';
|
||||
|
||||
import blogImg from '@images/autumn_tree.png';
|
||||
|
||||
const global = await directus.request(readSingleton('site_global'));
|
||||
const posts = await directus.request(
|
||||
readItems('posts', {
|
||||
@@ -50,8 +48,6 @@ const recentPosts: Post[] = posts.filter(
|
||||
<HeroSection
|
||||
title="Blog"
|
||||
subTitle={global.about_blog}
|
||||
src={blogImg}
|
||||
alt={global.blog_image_alt}
|
||||
/>
|
||||
|
||||
<SelectedPostsSection posts={selectedPosts} />
|
||||
|
||||
@@ -7,8 +7,6 @@ import AllCategoriesSection from '@components/sections/AllCategoriesSection.astr
|
||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||
import directus from '@lib/directus';
|
||||
|
||||
import categoryImg from '@images/autumn_bench.png';
|
||||
|
||||
const global = await directus.request(readSingleton('site_global'));
|
||||
---
|
||||
|
||||
@@ -35,8 +33,6 @@ const global = await directus.request(readSingleton('site_global'));
|
||||
<HeroSection
|
||||
title="Categories"
|
||||
subTitle={global.about_categories}
|
||||
src={categoryImg}
|
||||
alt={global.categories_image_alt}
|
||||
/>
|
||||
|
||||
<CategorySection />
|
||||
|
||||
@@ -12,8 +12,6 @@ import GiteaSection from '@components/sections/GiteaSection.astro';
|
||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||
import directus from '@lib/directus';
|
||||
|
||||
import homeImg from '@images/autumn_mountain.png';
|
||||
|
||||
const global = await directus.request(readSingleton('site_global'));
|
||||
const weather = await directus.request(readSingleton('site_weather'));
|
||||
const posts = await directus.request(
|
||||
@@ -54,8 +52,6 @@ const recentPosts = posts
|
||||
subTitle={global.about_description}
|
||||
primaryBtn="About Me"
|
||||
primaryBtnURL="/about"
|
||||
src={homeImg}
|
||||
alt={global.home_image_alt}
|
||||
/>
|
||||
|
||||
<FeatureSection />
|
||||
|
||||
Reference in New Issue
Block a user