|
| 1 | +--- |
| 2 | +import { getCollection, getEntries } from 'astro:content'; |
| 3 | +import BaseLayout from '@/layouts/BaseLayout.astro'; |
| 4 | +import { TOPICS, formatDate, formatMonth, sortPostsByDate } from '@/lib/data'; |
| 5 | +import { SITE } from '@/lib/site'; |
| 6 | +
|
| 7 | +export async function getStaticPaths() { |
| 8 | + return TOPICS.map((t) => ({ params: { id: t.id }, props: { topic: t } })); |
| 9 | +} |
| 10 | +
|
| 11 | +interface Props { |
| 12 | + topic: (typeof TOPICS)[number]; |
| 13 | +} |
| 14 | +const { topic } = Astro.props; |
| 15 | +
|
| 16 | +const allRaw = (await getCollection('posts', ({ data }) => !data.draft)) |
| 17 | + .filter((p) => p.data.topicId === topic.id) |
| 18 | + .sort(sortPostsByDate); |
| 19 | +
|
| 20 | +const posts = await Promise.all( |
| 21 | + allRaw.map(async (p) => ({ ...p, authors: await getEntries(p.data.authors) })), |
| 22 | +); |
| 23 | +
|
| 24 | +const grouped: Record<string, typeof posts> = {}; |
| 25 | +posts.forEach((a) => { |
| 26 | + const m = formatMonth(a.data.date.toISOString()); |
| 27 | + if (!grouped[m]) grouped[m] = []; |
| 28 | + grouped[m].push(a); |
| 29 | +}); |
| 30 | +
|
| 31 | +const canonical = `${SITE.url}/topics/${topic.id}/`; |
| 32 | +
|
| 33 | +const jsonLd = { |
| 34 | + '@context': 'https://schema.org', |
| 35 | + '@type': 'CollectionPage', |
| 36 | + name: `${topic.name} — ${SITE.name}`, |
| 37 | + description: topic.desc, |
| 38 | + url: canonical, |
| 39 | + isPartOf: { '@type': 'WebSite', name: SITE.name, url: SITE.url }, |
| 40 | + mainEntity: { |
| 41 | + '@type': 'ItemList', |
| 42 | + itemListElement: posts.map((p, i) => ({ |
| 43 | + '@type': 'ListItem', |
| 44 | + position: i + 1, |
| 45 | + url: `${SITE.url}/blog/${p.id}/`, |
| 46 | + name: p.data.title, |
| 47 | + })), |
| 48 | + }, |
| 49 | +}; |
| 50 | +--- |
| 51 | + |
| 52 | +<BaseLayout |
| 53 | + title={`${topic.name} — articles on ${topic.name.toLowerCase()}`} |
| 54 | + description={`${topic.desc} — articles, primers, and case studies on ${topic.name.toLowerCase()} from the ML Systems community.`} |
| 55 | + image="/og/page/topics.png" |
| 56 | + jsonLd={jsonLd} |
| 57 | +> |
| 58 | + <div class="container blog-shell"> |
| 59 | + <div class="blog-head"> |
| 60 | + <div> |
| 61 | + <div class="eyebrow page-eyebrow">Topic</div> |
| 62 | + <h1 class="blog-h1">{topic.name}.</h1> |
| 63 | + <p class="page-lede" style="max-width: 680px;">{topic.desc}</p> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + |
| 67 | + { |
| 68 | + posts.length === 0 ? ( |
| 69 | + <div style="padding: 80px 0; text-align: center; color: var(--ink-3);"> |
| 70 | + No articles in this topic yet. Be the first to{' '} |
| 71 | + <a href="/contribute" style="color: var(--accent);"> |
| 72 | + write one |
| 73 | + </a> |
| 74 | + . |
| 75 | + </div> |
| 76 | + ) : ( |
| 77 | + Object.entries(grouped).map(([month, items]) => ( |
| 78 | + <div class="blog-month-group" style="margin-bottom: 40px;"> |
| 79 | + <div class="eyebrow" style="margin-bottom: 4px; color: var(--ink-3);"> |
| 80 | + {month} |
| 81 | + </div> |
| 82 | + <div class="blog-list"> |
| 83 | + {items.map((a) => ( |
| 84 | + <a href={`/blog/${a.id}`} class="blog-row" data-topic={a.data.topicId}> |
| 85 | + <div class="blog-row-body"> |
| 86 | + <div class="blog-row-title-line"> |
| 87 | + <h3 class="blog-row-title">{a.data.title}</h3> |
| 88 | + {a.data.tags?.slice(0, 2).map((t) => ( |
| 89 | + <span class="blog-row-tag">#{t}</span> |
| 90 | + ))} |
| 91 | + </div> |
| 92 | + <p class="blog-row-summary">{a.data.summary}</p> |
| 93 | + </div> |
| 94 | + <div class="blog-row-meta"> |
| 95 | + <strong>{a.authors.map((au) => au.data.name).join(' · ')}</strong> |
| 96 | + <span>{formatDate(a.data.date.toISOString())}</span> |
| 97 | + </div> |
| 98 | + </a> |
| 99 | + ))} |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + )) |
| 103 | + ) |
| 104 | + } |
| 105 | + </div> |
| 106 | +</BaseLayout> |
0 commit comments