Add last projects component and fixing some small bugs
This commit is contained in:
64
astro/src/components/web/LastProjects.astro
Normal file
64
astro/src/components/web/LastProjects.astro
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
---
|
||||||
|
import { getLastProjects } from '@/content/projects/projects';
|
||||||
|
import { getSettings } from '@/content/settings/settings';
|
||||||
|
import CalendarIcon from '@/icons/CalendarIcon.astro';
|
||||||
|
import { getImageUrl } from '@/lib/images';
|
||||||
|
import { getProjectRoute } from '@/lib/routing';
|
||||||
|
import { Image } from 'astro:assets';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
projects: LastProjectsComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 projects = Astro.props.projects;
|
||||||
|
const settings = await getSettings();
|
||||||
|
const lastProjects = await getLastProjects(projects.amount);
|
||||||
|
const size = calculateSizeClasses(projects.amount, lastProjects.length);
|
||||||
|
|
||||||
|
console.log(lastProjects[0].searchEngine);
|
||||||
|
---
|
||||||
|
|
||||||
|
<div
|
||||||
|
id={`lastprojects-${projects.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">{projects.title}</h2>
|
||||||
|
<div>
|
||||||
|
<a
|
||||||
|
href={settings.project.indexRouteTemplate}
|
||||||
|
class="text-(--ptt) bg-(--ptc) hover:text-(--stt) hover:bg-(--stc) duration-200 py-3 px-4 rounded-full"
|
||||||
|
>
|
||||||
|
{projects.readMoreButtonText}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col lg:flex-row lg:justify-between gap-y-6">
|
||||||
|
{ lastProjects.map((project) => (
|
||||||
|
<a href={getProjectRoute(settings.project, project)} class={`${size} flex flex-col gap-2`}>
|
||||||
|
<Image
|
||||||
|
src={getImageUrl(project.searchEngine.thumbnail.url)}
|
||||||
|
alt={project.title}
|
||||||
|
class="flex rounded-2xl shadow-md"
|
||||||
|
width={600}
|
||||||
|
height={315}
|
||||||
|
/>
|
||||||
|
<h4 class="font-semibold text-[28px]">{project.title}</h4>
|
||||||
|
<div class="flex flex-row items-center gap-1.5 text-neutral-900 text-sm">
|
||||||
|
<CalendarIcon width={20} height={20} />
|
||||||
|
<div>{project.date}</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
)) }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -7,6 +7,7 @@ import WallOfText from '../web/WallOfText.astro';
|
|||||||
import EquipmentTable from '../web/EquipmentTable.astro';
|
import EquipmentTable from '../web/EquipmentTable.astro';
|
||||||
import Reviews from '../web/Reviews.astro';
|
import Reviews from '../web/Reviews.astro';
|
||||||
import LastBlogs from '../web/LastBlogs.astro';
|
import LastBlogs from '../web/LastBlogs.astro';
|
||||||
|
import LastProjects from '../web/LastProjects.astro';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
webpage: WebpageComponent[];
|
webpage: WebpageComponent[];
|
||||||
@@ -28,6 +29,7 @@ console.log(Astro.props.webpage);
|
|||||||
{ component.component === "EquipmentTable" && <EquipmentTable equipment={component} /> }
|
{ component.component === "EquipmentTable" && <EquipmentTable equipment={component} /> }
|
||||||
{ component.component === "Reviews" && <Reviews reviews={component} /> }
|
{ component.component === "Reviews" && <Reviews reviews={component} /> }
|
||||||
{ component.component === "LastBlogs" && <LastBlogs blogs={component} /> }
|
{ component.component === "LastBlogs" && <LastBlogs blogs={component} /> }
|
||||||
|
{ component.component === "LastProjects" && <LastProjects projects={component} /> }
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)) }
|
)) }
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createDirectusConnection } from "@/lib/directus";
|
|||||||
import { print } from "graphql";
|
import { print } from "graphql";
|
||||||
import getProjects from '@/graphql/projects/getProjects.graphql';
|
import getProjects from '@/graphql/projects/getProjects.graphql';
|
||||||
import getProjectPost from '@/graphql/projects/getProject.graphql';
|
import getProjectPost from '@/graphql/projects/getProject.graphql';
|
||||||
|
import getLastProjectsQuery from '@/graphql/projects/getLastProjects.graphql';
|
||||||
|
|
||||||
export async function getAllProjects(settings: GlobalSettings): Promise<ProjectPost[]> {
|
export async function getAllProjects(settings: GlobalSettings): Promise<ProjectPost[]> {
|
||||||
const client = await createDirectusConnection();
|
const client = await createDirectusConnection();
|
||||||
@@ -24,9 +25,8 @@ export async function getAllProjects(settings: GlobalSettings): Promise<ProjectP
|
|||||||
];
|
];
|
||||||
|
|
||||||
const project: ProjectPost = {
|
const project: ProjectPost = {
|
||||||
type: "ProjectPost",
|
|
||||||
exists: true,
|
exists: true,
|
||||||
|
type: "ProjectPost",
|
||||||
lastModified: new Date(),
|
lastModified: new Date(),
|
||||||
title: projectRecord["title"],
|
title: projectRecord["title"],
|
||||||
content: projectRecord["content"],
|
content: projectRecord["content"],
|
||||||
@@ -141,3 +141,72 @@ export async function getProject(settings: GlobalSettings, route: string): Promi
|
|||||||
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getLastProjects(amount: number): Promise<ProjectPost[]> {
|
||||||
|
const client = await createDirectusConnection();
|
||||||
|
const result = await client.query(print(getLastProjectsQuery), {
|
||||||
|
date: formatDate(new Date(), "%Y-%M-%D"),
|
||||||
|
amount: amount
|
||||||
|
});
|
||||||
|
|
||||||
|
let projects: ProjectPost[] = [];
|
||||||
|
|
||||||
|
result["Projects"].forEach((projectRecord: any) => {
|
||||||
|
let dates: string[] = [
|
||||||
|
projectRecord["date_created"],
|
||||||
|
projectRecord["date_updated"],
|
||||||
|
projectRecord["search_engine"][0]["date_created"],
|
||||||
|
projectRecord["search_engine"][0]["date_updated"],
|
||||||
|
projectRecord["search_engine"][0]["thumbnail"]["created_on"]
|
||||||
|
];
|
||||||
|
|
||||||
|
const project: ProjectPost = {
|
||||||
|
exists: true,
|
||||||
|
type: "ProjectPost",
|
||||||
|
lastModified: new Date(),
|
||||||
|
title: projectRecord["title"],
|
||||||
|
content: projectRecord["content"],
|
||||||
|
date: projectRecord["date"],
|
||||||
|
url: projectRecord["url"],
|
||||||
|
searchEngine: {
|
||||||
|
title: projectRecord["search_engine"][0]["title"],
|
||||||
|
description: projectRecord["search_engine"][0]["description"],
|
||||||
|
allowCrawlers: projectRecord["search_engine"][0]["allow_crawler"],
|
||||||
|
canonical: projectRecord["search_engine"][0]["canonical"],
|
||||||
|
priority: projectRecord["search_engine"][0]["priority"],
|
||||||
|
thumbnail: {
|
||||||
|
url: projectRecord["search_engine"][0]["thumbnail"]["filename_disk"],
|
||||||
|
height: projectRecord["search_engine"][0]["thumbnail"]["height"],
|
||||||
|
width: projectRecord["search_engine"][0]["thumbnail"]["width"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tags: []
|
||||||
|
};
|
||||||
|
|
||||||
|
projectRecord["tags"].forEach((tagRecord: any) => {
|
||||||
|
project["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) {
|
||||||
|
project.lastModified = new Date();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const sortedDates: string[] = dates.sort((a: string, b: string) => {
|
||||||
|
return new Date(b).getTime() - new Date(a).getTime();
|
||||||
|
});
|
||||||
|
|
||||||
|
project.lastModified = new Date(sortedDates[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
projects.push(project);
|
||||||
|
});
|
||||||
|
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
|
|||||||
39
astro/src/graphql/projects/getLastProjects.graphql
Normal file
39
astro/src/graphql/projects/getLastProjects.graphql
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
query getLastProjects($date: String!, $amount: Int!) {
|
||||||
|
Projects(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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ query getAllProjects($date: String!) {
|
|||||||
thumbnail {
|
thumbnail {
|
||||||
id,
|
id,
|
||||||
created_on,
|
created_on,
|
||||||
filename_download,
|
filename_disk,
|
||||||
width,
|
width,
|
||||||
height
|
height
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user