2 Commits

Author SHA1 Message Date
itsfinniii
82c0905c0e Add IDs to all components of the website 2026-03-26 22:08:04 +01:00
itsfinniii
1fd51a6a3f Create Last Blogs component with responsive design 2026-03-26 22:03:03 +01:00
9 changed files with 198 additions and 7 deletions

View File

@@ -9,7 +9,10 @@ interface Props {
const equipment = Astro.props.equipment;
---
<div class="flex lg:flex-row flex-col lg:justify-center justify-center py-12 px-12 lg:container mx-auto gap-y-8 lg:gap-x-28 gap-x-18 lg:text-left text-center">
<div
id={`equipment-${equipment.id}`}
class="flex lg:flex-row flex-col lg:justify-center justify-center py-12 px-12 lg:container mx-auto gap-y-8 lg:gap-x-28 gap-x-18 lg:text-left text-center"
>
<div class="flex flex-col gap-1.5">
<h2 class="text-5xl font-bold">{equipment.title}</h2>
{ equipment.text !== null && (

View File

@@ -9,7 +9,10 @@ interface Props {
const faq = Astro.props.faq;
---
<div class="flex lg:flex-row flex-col justify-between py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full">
<div
id={`faq-${faq.id}`}
class="flex lg:flex-row flex-col justify-between py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full"
>
<div class="flex flex-col gap-2.5 lg:w-[50%] w-full">
<h2 class="text-5xl font-bold">{faq.title}</h2>
{ faq.text !== null && (

View File

@@ -0,0 +1,63 @@
---
import { getLastBlogs } from '@/content/blogs/blogs';
import { getSettings } from '@/content/settings/settings';
import CalendarIcon from '@/icons/CalendarIcon.astro';
import { getImageUrl } from '@/lib/images';
import { getBlogRoute } from '@/lib/routing';
import type { ACTION_ERROR_CODES } from 'astro:actions';
import { Image } from 'astro:assets';
interface Props {
blogs: LastBlogsComponent;
}
function calculateSizeClasses(amount: number, length: number) {
if (amount === 2 || length <= 2) {
return "lg:w-[45%] w-full";
}
else {
return "lg:w-[31%] w-full";
}
}
const blogs = Astro.props.blogs;
const settings = await getSettings();
const lastBlogs = await getLastBlogs(blogs.amount);
const size = calculateSizeClasses(blogs.amount, lastBlogs.length);
---
<div
id={`lastblogs-${blogs.id}`}
class="flex lg:flex-col flex-col py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full"
>
<div class="flex flex-row justify-between items-center w-full">
<h2 class="text-4xl font-bold">{blogs.title}</h2>
<div>
<a
href={settings.blog.indexRouteTemplate}
class="text-(--ptt) bg-(--ptc) hover:text-(--stt) hover:bg-(--stc) duration-200 py-3 px-4 rounded-full"
>
{blogs.readMoreButtonText}
</a>
</div>
</div>
<div class="flex flex-col lg:flex-row lg:justify-between gap-y-6">
{ lastBlogs.map((blog) => (
<a href={getBlogRoute(settings.blog, blog)} class={`${size} flex flex-col gap-2`}>
<Image
src={getImageUrl(blog.searchEngine.thumbnail.url)}
alt={blog.title}
class="flex rounded-2xl shadow-md"
width={600}
height={315}
/>
<h4 class="font-semibold text-[28px]">{blog.title}</h4>
<div class="flex flex-row items-center gap-1.5 text-neutral-900 text-sm">
<CalendarIcon width={20} height={20} />
<div>{blog.date}</div>
</div>
</a>
)) }
</div>
</div>

View File

@@ -19,7 +19,10 @@ const averageStars = Math.round((totalStars / totalReviews) * 10) / 10;
const reviewsToShow = reviews.reviews.slice(0, 5);
---
<div class="flex lg:flex-row flex-col py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full">
<div
id={`reviews-${reviews.id}`}
class="flex lg:flex-row flex-col py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full"
>
<div class="flex flex-col lg:gap-5 gap-2.25 lg:min-w-[32.5%]">
<div class="flex flex-col">
<h2 class="text-3xl font-bold">{reviews.title}</h2>

View File

@@ -11,8 +11,11 @@ interface Props {
const upcomingEvents = Astro.props.upcomingEvents;
---
<div id={`upcomingevents-${upcomingEvents.id}`} class="flex flex-col justify-between items-center py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18">
<h1 class="text-5xl font-bold">Upcoming Events</h1>
<div
id={`upcomingevents-${upcomingEvents.id}`}
class="flex flex-col justify-between items-center py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18"
>
<h1 class="text-5xl font-bold">{upcomingEvents.title}</h1>
<div class="flex flex-col items-start gap-7 w-full">
{ upcomingEvents.events.map((event) => (

View File

@@ -8,7 +8,10 @@ interface Props {
const wallOfText = Astro.props.wallOfText;
---
<div id={`walloftext-${wallOfText.id}`} class="flex flex-col py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full">
<div
id={`walloftext-${wallOfText.id}`}
class="flex flex-col py-12 px-12 lg:container mx-auto gap-y-8 gap-x-18 w-full"
>
<h2 class="text-5xl font-bold">{wallOfText.title}</h2>
<div set:html={markdownToHtml(wallOfText.text)}></div>
</div>

View File

@@ -6,6 +6,7 @@ import UpcomingEvents from '../web/UpcomingEvents.astro';
import WallOfText from '../web/WallOfText.astro';
import EquipmentTable from '../web/EquipmentTable.astro';
import Reviews from '../web/Reviews.astro';
import LastBlogs from '../web/LastBlogs.astro';
interface Props {
webpage: WebpageComponent[];
@@ -26,6 +27,7 @@ console.log(Astro.props.webpage);
{ component.component === "FrequentlyAskedQuestions" && <FrequentlyAskedQuestions faq={component} /> }
{ component.component === "EquipmentTable" && <EquipmentTable equipment={component} /> }
{ component.component === "Reviews" && <Reviews reviews={component} /> }
{ component.component === "LastBlogs" && <LastBlogs blogs={component} /> }
</Fragment>
)) }
</div>

View File

@@ -2,6 +2,7 @@ import { createDirectusConnection } from "@/lib/directus";
import { print } from 'graphql';
import getBlogs from '@/graphql/blogs/getBlogs.graphql';
import getBlogPost from '@/graphql/blogs/getBlog.graphql';
import getLastBlogPosts from '@/graphql/blogs/getLastBlogPosts.graphql';
import { formatDate } from "@/lib/dates";
export async function getAllBlogs(settings: GlobalSettings): Promise<BlogPost[]> {
@@ -24,6 +25,7 @@ export async function getAllBlogs(settings: GlobalSettings): Promise<BlogPost[]>
];
const blog: BlogPost = {
exists: true,
type: "BlogPost",
id: blogRecord["id"],
lastModified: new Date(),
@@ -93,8 +95,8 @@ export async function getBlog(settings: GlobalSettings, route: string): Promise<
];
const blog: BlogPost = {
type: "BlogPost",
exists: true,
type: "BlogPost",
id: blogRecord["id"],
lastModified: new Date(),
title: blogRecord["title"],
@@ -140,3 +142,73 @@ export async function getBlog(settings: GlobalSettings, route: string): Promise<
return blog;
}
export async function getLastBlogs(amount: number): Promise<BlogPost[]> {
const client = await createDirectusConnection();
const result = await client.query(print(getLastBlogPosts), {
date: formatDate(new Date(), "%Y-%M-%D"),
amount: amount
});
let blogs: BlogPost[] = [];
result["Blogs"].forEach((blogRecord: any) => {
let dates: string[] = [
blogRecord["date_created"],
blogRecord["date_updated"],
blogRecord["search_engine"][0]["date_created"],
blogRecord["search_engine"][0]["date_updated"],
blogRecord["search_engine"][0]["thumbnail"]["created_on"]
];
const blog: BlogPost = {
exists: true,
type: "BlogPost",
id: blogRecord["id"],
lastModified: new Date(),
title: blogRecord["title"],
content: blogRecord["content"],
date: blogRecord["date"],
url: blogRecord["url"],
searchEngine: {
title: blogRecord["search_engine"][0]["title"],
description: blogRecord["search_engine"][0]["description"],
allowCrawlers: blogRecord["search_engine"][0]["allow_crawler"],
canonical: blogRecord["search_engine"][0]["canonical"],
priority: blogRecord["search_engine"][0]["priority"],
thumbnail: {
url: blogRecord["search_engine"][0]["thumbnail"]["filename_disk"],
height: blogRecord["search_engine"][0]["thumbnail"]["height"],
width: blogRecord["search_engine"][0]["thumbnail"]["width"]
}
},
tags: []
};
blogRecord["tags"].forEach((tagRecord: any) => {
blog["tags"].push({
text: tagRecord["Tags_id"]["text"],
code: tagRecord["Tags_id"]["code"],
color: tagRecord["Tags_id"]["color"]
});
dates.push(tagRecord["Tags_id"]["date_created"]);
dates.push(tagRecord["Tags_id"]["date_updated"]);
});
if (dates.filter(e => e !== null).length === 0) {
blog.lastModified = new Date();
}
else {
const sortedDates: string[] = dates.sort((a: string, b: string) => {
return new Date(b).getTime() - new Date(a).getTime();
});
blog.lastModified = new Date(sortedDates[0]);
}
blogs.push(blog);
});
return blogs;
}

View File

@@ -0,0 +1,39 @@
query getLastBlogPosts($date: String!, $amount: Int!) {
Blogs(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, date: { _lte: $date } }, limit: $amount) {
id,
date_created,
date_updated,
status,
title,
url,
date,
content,
tags {
Tags_id {
id,
date_created,
date_updated,
text,
code,
color
}
},
search_engine {
id,
date_created,
date_updated,
title,
description,
thumbnail {
id,
created_on,
filename_disk,
width,
height
},
canonical,
allow_crawler,
priority
}
}
}