diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts index 95b327d..ebbdd82 100644 --- a/src/pages/api/revalidate.ts +++ b/src/pages/api/revalidate.ts @@ -25,13 +25,18 @@ async function getURLs( const urls = ["/technology"]; // Get all projects with the technology - const all_projects = await directus.request(readItems("project")); - if (all_projects != null) { - for (const project of all_projects) { - if (project.technologies?.some((t) => t.id === key)) - urls.push(`/projects/${project.id}`); - } - } + const all_projects = await directus.request(readItems("project", { + fields: ["id", { + technologies: ["id"], + }], + })); + + // if (all_projects != null) { + // for (const project of all_projects) { + // if (project.technologies?.some((t) => t.id === key)) + // urls.push(`/projects/${project.id}`); + // } + // } return urls; } diff --git a/src/pages/projects.tsx b/src/pages/projects.tsx index ef4974d..f756f7e 100644 --- a/src/pages/projects.tsx +++ b/src/pages/projects.tsx @@ -1,19 +1,26 @@ import AppWrapper from "@/components/AppWrapper"; -import directus, { Project } from "@/utils/directus"; +import directus from "@/utils/directus"; import { cn } from "@/utils/helpers"; import { readItems } from "@directus/sdk"; import { GetStaticPropsResult, type NextPage } from "next"; import Link from "next/link"; type Props = { - projects: Project[]; + projects: Awaited>; }; -export async function getStaticProps(): Promise> { - const projects = await directus.request(readItems("project")); +async function getProjects() { + return await directus.request(readItems("project", { + fields: ["name", "shortDescription", "icon", {links: ["url"]}], + })); +} + +export async function getStaticProps(): Promise> {; return { - props: {projects} + props: { + projects: await getProjects(), + } } } @@ -21,27 +28,29 @@ const ProjectsPage: NextPage = ({projects}) => { return (
- {projects.map(({ name, shortDescription: description, links, icon }) => ( - - -
- -
-
-
{name}
-
- {description} + {projects.map(({ name, shortDescription: description, links, icon }) => { + return ( + + +
+
-
- - ))} +
+
{name}
+
+ {description} +
+
+ + ); + })}
); diff --git a/src/utils/directus.ts b/src/utils/directus.ts index 241f3c9..bdba41e 100644 --- a/src/utils/directus.ts +++ b/src/utils/directus.ts @@ -4,6 +4,9 @@ export interface Schema { metadata: Metadata; project: Project[]; technology: Technology[]; + link: Link[]; + project_technology: ProjectTechnology[]; + project_link: ProjectLink[]; } export interface Technology { @@ -12,19 +15,42 @@ export interface Technology { url: string | null; } +export interface ProjectTechnology { + id: string; + project_id: string; + technology_id: string; +} + export interface Project { id: string; + + // One2Many + links: number[] | ProjectLink[]; + // Many2Many + technologies: number[] | ProjectTechnology[]; + icon: string | null; name: string; description: string; shortDescription: string; - links: Link[]; + + featured: boolean; wakatimeOffset: number | null; - technologies: Technology[] | null; bannerImage: string; } export interface Link { + id: string; + project_id: string; + icon: string; + url: string; + description: string | null; +} + +export interface ProjectLink { + id: string; + project_id: string; + sort: number; icon: string; url: string; description: string | null;