From e9aabe498e6cf0e9b29438c2b5e456336ef03607 Mon Sep 17 00:00:00 2001 From: Oliver Bryan <04oliverbryan@gmail.com> Date: Fri, 26 Sep 2025 13:16:39 +0100 Subject: [PATCH] project system --- src/components/ProjectListItem.astro | 39 ++++++++++++++ src/components/ProjectPage.astro | 40 ++++++++++++++ src/pages/index.astro | 81 +++++++++++++++++++++++++++- 3 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/components/ProjectListItem.astro create mode 100644 src/components/ProjectPage.astro diff --git a/src/components/ProjectListItem.astro b/src/components/ProjectListItem.astro new file mode 100644 index 00000000..736e53d4 --- /dev/null +++ b/src/components/ProjectListItem.astro @@ -0,0 +1,39 @@ +--- +const { title, description, date, image, slug } = Astro.props; +--- + + + + +
+
+ {image ? ( + {`${title} + ) : ( +
+ )} +
+
+

+ {title} +

+

{description}

+

{date}

+
+
+
diff --git a/src/components/ProjectPage.astro b/src/components/ProjectPage.astro new file mode 100644 index 00000000..5f98af05 --- /dev/null +++ b/src/components/ProjectPage.astro @@ -0,0 +1,40 @@ +--- +import Layout from "../layouts/Layout.astro"; + +export interface Props { + metadata: { + title: string; + description: string; + date: string; + slug: string; + image?: string | null; + hidden: boolean; + }; +} + +const { metadata } = Astro.props; +--- + + +
+

+ {metadata.title} +

+ + { + metadata.image ? ( + {`${metadata.title} + ) : ( +
+ ) + } + + + +

{metadata.date}

+
+ diff --git a/src/pages/index.astro b/src/pages/index.astro index f974355b..205b59a9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,7 +1,84 @@ --- import Layout from "../layouts/Layout.astro"; +import ProjectListItem from "../components/ProjectListItem.astro"; + +interface ProjectMetadata { + title: string; + description: string; + date: string; + slug: string; + hidden: boolean; + image?: string; +} + +interface AstroModule { + metadata?: ProjectMetadata; +} + +function parseDate(dateStr: string): Date { + // formats like "February 2024", "January - June 2024", "Q1 2023", etc + const lower = dateStr.toLowerCase(); + + if (lower.includes("q1")) return new Date("2023-01-01"); + if (lower.includes("q2")) return new Date("2023-04-01"); + if (lower.includes("q3")) return new Date("2023-07-01"); + if (lower.includes("q4")) return new Date("2023-10-01"); + + const months: Record = { + january: 0, + february: 1, + march: 2, + april: 3, + may: 4, + june: 5, + july: 6, + august: 7, + september: 8, + october: 9, + november: 10, + december: 11, + }; + + // month and year + for (const [monthName, monthIndex] of Object.entries(months)) { + if (lower.includes(monthName)) { + const yearMatch = dateStr.match(/\b(20\d{2})\b/); + if (yearMatch) { + return new Date(parseInt(yearMatch[1]), monthIndex, 1); + } + } + } + + // fallback: try to extract any year + const yearMatch = dateStr.match(/\b(20\d{2})\b/); + if (yearMatch) { + return new Date(parseInt(yearMatch[1]), 0, 1); + } + + return new Date(0); +} + +const projects: ProjectMetadata[] = Object.values( + import.meta.glob("./projects/*.astro", { eager: true }) +) + .map((module) => module.metadata) + .filter((metadata): metadata is ProjectMetadata => metadata !== undefined) + .filter((project) => !project.hidden) + .sort((a, b) => parseDate(b.date).getTime() - parseDate(a.date).getTime()); --- -

home page

-
\ No newline at end of file +

projects

+ + { + projects.map((project) => ( + + )) + } +