--- import { decodeSlug, getEmDashCollection, getEmDashEntry, getSeoMeta, } from "emdash"; import { Image, PortableText } from "emdash/ui"; import Base from "../../layouts/Base.astro"; import { absoluteImageUrl } from "../../utils/media"; const slug = decodeSlug(Astro.params.slug); if (!slug) { return Astro.rewrite("/404"); } const { entry: project, error, cacheHint: projectCacheHint, } = await getEmDashEntry("projects", slug); if (error) return new Response("Could not load the project", { status: 500 }); if (!project) { return Astro.rewrite("/404"); } // The next project is the next older one, so the links walk the whole // archive. The range includes this project and any that share its publish // date, so the next one is whichever entry follows this project in the same // order; the oldest project gets none. Without a date (a draft in preview) // the next is the newest project. const publishedAt = project.data.publishedAt; const olderResult = await getEmDashCollection("projects", { orderBy: { published_at: "desc" }, limit: 4, ...(publishedAt ? { where: { published_at: { lte: publishedAt.toISOString() } } } : {}), }); if (olderResult.error) { return new Response("Could not load related projects", { status: 500 }); } const { entries: olderProjects, cacheHint: olderCacheHint } = olderResult; const currentIndex = olderProjects.findIndex((p) => p.id === project.id); const nextProject = currentIndex >= 0 ? olderProjects[currentIndex + 1] : olderProjects.find((p) => p.id !== project.id); if (Astro.cache?.enabled) { Astro.cache.set(projectCacheHint); Astro.cache.set(olderCacheHint); } function safeExternalUrl(value: string | undefined): string | undefined { if (!value) return undefined; try { const url = new URL(value); return url.protocol === "https:" || url.protocol === "http:" ? url.href : undefined; } catch { return undefined; } } const projectUrl = safeExternalUrl(project.data.url); const seo = getSeoMeta(project, { siteUrl: Astro.url.origin, path: `/work/${slug}`, defaultDescription: project.data.summary, defaultOgImage: project.data.featured_image ? absoluteImageUrl(project.data.featured_image, Astro.url.origin) : undefined, }); const { client, year, summary } = project.data; const disciplines = project.data.terms?.tag ?? []; const websiteLabel = projectUrl ? new URL(projectUrl).host.replace(/^www\./, "") : undefined; const hasMeta = Boolean( client || year || disciplines.length > 0 || projectUrl, ); const figures = (project.data.gallery ?? []).filter((item) => item.image); // Figures run full, half, half. A half with no partner goes full width. function isHalf(index: number): boolean { const position = index % 3; return position === 2 || (position === 1 && index < figures.length - 1); } function pad(n: number): string { return String(n).padStart(2, "0"); } const fullSizes = "(min-width: 1680px) 1600px, (min-width: 768px) 96vw, 150vw"; const halfSizes = "(min-width: 1680px) 1200px, (min-width: 768px) 72vw, 150vw"; ---
Index

{project.data.title || "Untitled"}

{ (summary || hasMeta) && (
{summary && (

{summary}

)} {hasMeta && (
{client && (
Client
{client}
)} {year && (
Year
{year}
)} {disciplines.length > 0 && (
{disciplines.length === 1 ? "Discipline" : "Disciplines"}
)} {projectUrl && ( )}
)}
) } { project.data.featured_image && (
) }
{ figures.length > 0 && ( ) }
{ nextProject && (

Next project

{nextProject.data.title || "Untitled"} {nextProject.data.featured_image && ( )}
) }