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 { Image } from 'astro:assets';
|
||||||
|
import { readItems } from '@directus/sdk';
|
||||||
|
|
||||||
|
import type { HeaderImage } from '@lib/directusTypes';
|
||||||
|
|
||||||
import GoLinkPrimaryButton from '@components/buttons/GoLinkPrimaryButton.astro';
|
import GoLinkPrimaryButton from '@components/buttons/GoLinkPrimaryButton.astro';
|
||||||
import GoLinkSecondaryButton from '@components/buttons/GoLinkSecondaryButton.astro';
|
import GoLinkSecondaryButton from '@components/buttons/GoLinkSecondaryButton.astro';
|
||||||
|
import directus from '@lib/directus';
|
||||||
|
import { getDirectusImageURL } from '@/support/url';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -11,14 +16,20 @@ interface Props {
|
|||||||
primaryBtnURL?: string;
|
primaryBtnURL?: string;
|
||||||
secondaryBtn?: string;
|
secondaryBtn?: string;
|
||||||
secondaryBtnURL?: 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">
|
<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>
|
||||||
|
|
||||||
<div class="smooth-reveal-fade md:block w-full hidden">
|
<div class="smooth-reveal-fade md:block w-full hidden">
|
||||||
<div class="flex justify-center w-full top-12 md:ml-4 overflow-hidden">
|
<div
|
||||||
{src && alt && (
|
class="flex justify-center w-full top-12 md:ml-4 overflow-hidden no-js-fallback"
|
||||||
<Image
|
id="hero-image-container"
|
||||||
src={src}
|
>
|
||||||
alt={alt}
|
{images.map((img, index) => (
|
||||||
class={`h-full w-105 scale-100 object-cover object-center ${roundedClasses}`}
|
<div
|
||||||
draggable="false"
|
class="hero-image hidden justify-center w-full h-full"
|
||||||
loading="eager"
|
data-index={index}
|
||||||
format="webp"
|
>
|
||||||
quality="low"
|
<Image
|
||||||
widths={[840]}
|
class="h-full w-105 scale-100 object-cover object-center"
|
||||||
inferSize={true}
|
src={img.src}
|
||||||
/>
|
alt={img.image_alt}
|
||||||
)}
|
draggable="false"
|
||||||
|
loading="eager"
|
||||||
|
format="webp"
|
||||||
|
widths={[840]}
|
||||||
|
inferSize={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</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>
|
</div>
|
||||||
</section>
|
</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,
|
Weather,
|
||||||
Post,
|
Post,
|
||||||
Category,
|
Category,
|
||||||
|
HeaderImage,
|
||||||
Application,
|
Application,
|
||||||
Experience,
|
Experience,
|
||||||
Education,
|
Education,
|
||||||
@@ -20,6 +21,7 @@ type Schema = {
|
|||||||
site_weather: Weather;
|
site_weather: Weather;
|
||||||
posts: Post[];
|
posts: Post[];
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
header_images: HeaderImage[];
|
||||||
site_applications: Application;
|
site_applications: Application;
|
||||||
site_experience: Experience;
|
site_experience: Experience;
|
||||||
site_education: Education;
|
site_education: Education;
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ export type Category = {
|
|||||||
logoDark: string;
|
logoDark: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type HeaderImage = {
|
||||||
|
id: string;
|
||||||
|
image: string;
|
||||||
|
image_alt: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type Application = {
|
export type Application = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import SkillsSliderSection from '@components/sections/SkillsSliderSection.astro'
|
|||||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||||
import directus from '@lib/directus';
|
import directus from '@lib/directus';
|
||||||
|
|
||||||
import portraitImg from '@images/portrait.avif';
|
|
||||||
|
|
||||||
const global = await directus.request(readSingleton('site_global'));
|
const global = await directus.request(readSingleton('site_global'));
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -37,9 +35,6 @@ const global = await directus.request(readSingleton('site_global'));
|
|||||||
<HeroSection
|
<HeroSection
|
||||||
title="About Me"
|
title="About Me"
|
||||||
subTitle={global.about}
|
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">
|
<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 BaseLayout from '@layouts/BaseLayout.astro';
|
||||||
import directus from '@lib/directus';
|
import directus from '@lib/directus';
|
||||||
|
|
||||||
import applicationImg from '@images/cedar_tree.png';
|
|
||||||
|
|
||||||
const global = await directus.request(readSingleton('site_global'));
|
const global = await directus.request(readSingleton('site_global'));
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -34,8 +32,6 @@ const global = await directus.request(readSingleton('site_global'));
|
|||||||
<HeroSection
|
<HeroSection
|
||||||
title="Applications"
|
title="Applications"
|
||||||
subTitle={global.about_applications}
|
subTitle={global.about_applications}
|
||||||
src={applicationImg}
|
|
||||||
alt={global.applications_image_alt}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ApplicationSection className="smooth-reveal-2" />
|
<ApplicationSection className="smooth-reveal-2" />
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import AllPostsSection from '@components/sections/AllPostsSection.astro';
|
|||||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||||
import directus from '@lib/directus';
|
import directus from '@lib/directus';
|
||||||
|
|
||||||
import blogImg from '@images/autumn_tree.png';
|
|
||||||
|
|
||||||
const global = await directus.request(readSingleton('site_global'));
|
const global = await directus.request(readSingleton('site_global'));
|
||||||
const posts = await directus.request(
|
const posts = await directus.request(
|
||||||
readItems('posts', {
|
readItems('posts', {
|
||||||
@@ -50,8 +48,6 @@ const recentPosts: Post[] = posts.filter(
|
|||||||
<HeroSection
|
<HeroSection
|
||||||
title="Blog"
|
title="Blog"
|
||||||
subTitle={global.about_blog}
|
subTitle={global.about_blog}
|
||||||
src={blogImg}
|
|
||||||
alt={global.blog_image_alt}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectedPostsSection posts={selectedPosts} />
|
<SelectedPostsSection posts={selectedPosts} />
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import AllCategoriesSection from '@components/sections/AllCategoriesSection.astr
|
|||||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||||
import directus from '@lib/directus';
|
import directus from '@lib/directus';
|
||||||
|
|
||||||
import categoryImg from '@images/autumn_bench.png';
|
|
||||||
|
|
||||||
const global = await directus.request(readSingleton('site_global'));
|
const global = await directus.request(readSingleton('site_global'));
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -35,8 +33,6 @@ const global = await directus.request(readSingleton('site_global'));
|
|||||||
<HeroSection
|
<HeroSection
|
||||||
title="Categories"
|
title="Categories"
|
||||||
subTitle={global.about_categories}
|
subTitle={global.about_categories}
|
||||||
src={categoryImg}
|
|
||||||
alt={global.categories_image_alt}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CategorySection />
|
<CategorySection />
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import GiteaSection from '@components/sections/GiteaSection.astro';
|
|||||||
import BaseLayout from '@layouts/BaseLayout.astro';
|
import BaseLayout from '@layouts/BaseLayout.astro';
|
||||||
import directus from '@lib/directus';
|
import directus from '@lib/directus';
|
||||||
|
|
||||||
import homeImg from '@images/autumn_mountain.png';
|
|
||||||
|
|
||||||
const global = await directus.request(readSingleton('site_global'));
|
const global = await directus.request(readSingleton('site_global'));
|
||||||
const weather = await directus.request(readSingleton('site_weather'));
|
const weather = await directus.request(readSingleton('site_weather'));
|
||||||
const posts = await directus.request(
|
const posts = await directus.request(
|
||||||
@@ -54,8 +52,6 @@ const recentPosts = posts
|
|||||||
subTitle={global.about_description}
|
subTitle={global.about_description}
|
||||||
primaryBtn="About Me"
|
primaryBtn="About Me"
|
||||||
primaryBtnURL="/about"
|
primaryBtnURL="/about"
|
||||||
src={homeImg}
|
|
||||||
alt={global.home_image_alt}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FeatureSection />
|
<FeatureSection />
|
||||||
|
|||||||
Reference in New Issue
Block a user