--- import type { CollectionEntry } from 'astro:content'; import { getEntry } from 'astro:content'; import EntryThumbnail from './EntryThumbnail.astro'; import ProjectLinks from './ProjectLinks.astro'; import { PROJECT_THUMBNAIL, articlePath, entrySlug } from '../lib/site'; interface Props { projects: CollectionEntry<'projects'>[]; // Opt-in: eagerly load the first thumbnail. Only set when the list is // reliably above the fold. The home and projects-index lists sit below // other sections, so leave this off there. eagerFirstThumbnail?: boolean; } const { projects, eagerFirstThumbnail = false } = Astro.props; // The `essay` field is a `reference('posts')`, so when present it's always a // `{ collection, id }` shape that `getEntry` resolves to a CollectionEntry. const essayHrefs = new Map(); for (const project of projects) { const essay = project.data.essay; if (!essay) continue; const resolved = await getEntry(essay); if (resolved) essayHrefs.set(project.id, articlePath(resolved)); } ---
    { projects.map((project, index) => { const anchor = entrySlug(project); const titleId = `${anchor}-title`; const essayHref = essayHrefs.get(project.id); const primaryHref = essayHref ?? project.data.links[0]?.url; return (
  1. {primaryHref ? ( {project.data.title} ) : ( project.data.title )} {essayHref && Article}

    {project.data.description}

    {project.data.period} ยท {project.data.technologies.join(', ')}

    {project.data.links.length > 0 && }
  2. ); }) }