Files
site-profile/src/pages/categories/[...slug].astro

131 lines
3.4 KiB
Plaintext

---
import { readItems, readSingleton } from '@directus/sdk';
import type { Post } from '@lib/directusTypes';
import HeaderSection from '@components/sections/HeaderSection.astro';
import BlogCard from '@components/cards/BlogCard.astro';
import BaseLayout from '@layouts/BaseLayout.astro';
import directus from '@lib/directus';
const category = Astro.props;
export async function getStaticPaths() {
const categories = await directus.request(readItems('categories'));
return categories.map((category) => ({
params: { slug: category.slug },
props: category,
}));
}
const global = await directus.request(readSingleton('site_global'));
const posts = await directus.request(
readItems('posts', {
filter: { published: { _eq: true } },
fields: ['*', { category: ['*'] }],
sort: ['-published_date'],
})
);
const categoriesPosts = posts
.sort((a: Post, b: Post) => b.published_date.valueOf() - a.published_date.valueOf())
.filter((b) => {
return b.category?.slug === category.slug;
});
---
<BaseLayout
title={category.title}
description={category.description}
structuredData={{
'@context': 'https://schema.org',
'@type': 'WebPage',
inLanguage: 'en-US',
'@id': Astro.url.href,
url: Astro.url.href,
name: `${category.title} | ${global.name}`,
description: category.description,
isPartOf: {
url: `${global.site_url}/categories`,
name: global.name,
description: global.about,
},
}}
>
<HeaderSection
title=`${category.title}`
subTitle={category.description}
logoExists
logoLight={category.logoLight}
logoDark={category.logoDark}
btnExists
btnTitle="Back to Categories"
btnURL="/categories"
/>
<section class="max-w-340 2xl:max-w-full mb-10 px-4 sm:px-6 lg:px-8 py-8 mx-auto mt-10">
<div class="columns-1 sm:columns-2 lg:columns-3 gap-6">
{categoriesPosts.map((b) =>
<div class="break-inside-avoid mb-6">
<BlogCard post={b} />
</div>
)}
</div>
</section>
</BaseLayout>
<script>
// Add smooth reveal animations for content after loading
document.addEventListener('astro:page-load', () => {
const animateContent = () => {
// Animate group 1
const smoothReveal = document.querySelectorAll('.smooth-reveal');
smoothReveal.forEach((el, index) => {
setTimeout(
() => {
el.classList.add('animate-reveal');
},
50 + index * 100
);
});
// Animate group 2
const smoothReveal2 = document.querySelectorAll('.smooth-reveal-2');
smoothReveal2.forEach((el, index) => {
setTimeout(
() => {
el.classList.add('animate-reveal');
},
200 + index * 150
);
});
// Animate topic cards with staggered delay
const smoothRevealCards = document.querySelectorAll('.smooth-reveal-cards');
smoothRevealCards.forEach((el, index) => {
setTimeout(
() => {
el.classList.add('animate-reveal');
},
500 + index * 100
);
});
// Animate with just fade in with staggered delay
const smoothRevealFade = document.querySelectorAll('.smooth-reveal-fade');
smoothRevealFade.forEach((el, index) => {
setTimeout(
() => {
el.classList.add('animate-reveal-fade');
},
100 + index * 250
);
});
};
animateContent();
});
</script>