diff options
| author | Joe Carstairs <me@joeac.net> | 2025-04-15 07:52:17 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2025-04-15 07:52:17 +0100 |
| commit | fd5998240f65e3bc3a94e4045f8f5c286a755b1c (patch) | |
| tree | 7e8ee0d2a42d110ca5a8e1618668186075842b47 /src/pages | |
| parent | c39ad295afa6fbe51bab00870f06465bc62b71b0 (diff) | |
displays date on news items
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/[locale]/index.astro | 27 | ||||
| -rw-r--r-- | src/pages/[locale]/news/[...slug].astro | 13 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro index 7846fd8..15b4005 100644 --- a/src/pages/[locale]/index.astro +++ b/src/pages/[locale]/index.astro @@ -1,10 +1,14 @@ --- -import Page from '$layouts/Page.astro'; -import localeStaticPaths from '$lib/localeStaticPaths'; +import Button from '$components/Button.astro'; +import CommitteeList from '$components/CommitteeList/CommitteeList.astro'; +import NewsIndex from '$components/NewsIndex/NewsIndex.astro'; import translate from '$i18n/translate'; import tPage from '$i18n/translations/pages/home'; +import Page from '$layouts/Page.astro'; +import localeStaticPaths from '$lib/localeStaticPaths'; +import { isBefore, isNewsItemInLocale } from '$lib/newsUtils'; import type Locale from '$types/Locale'; -import CommitteeList from '$components/CommitteeList/CommitteeList.astro'; +import { getCollection } from 'astro:content'; export async function getStaticPaths() { return localeStaticPaths; @@ -12,9 +16,26 @@ export async function getStaticPaths() { const locale = Astro.params.locale as Locale; const t = translate(locale); + +const allNewsItemsInLocale = await getCollection('news', (item) => + isNewsItemInLocale(item, locale) +); +const firstNewsItem = allNewsItemsInLocale.find( + (item) => !allNewsItemsInLocale.some((otherItem) => isBefore(item, otherItem)) +); +if (!firstNewsItem) { + throw new Error('No first news item.'); +} --- <Page title={t(tPage, { key: 'title' })}> + <section id="news"> + <h2 set:html={t(tPage, { key: 'news' })} /> + <NewsIndex headingLevel="h3" newsItems={[firstNewsItem]} /> + <Button classNames="grid-span-3 grid-prose-end" href={`/${locale}/news`}> + {t(tPage, { key: 'aw-news' })} ▶ + </Button> + </section> <section id="about"> <h2 set:html={t(tPage, { key: 'about-us' })} /> <p set:html={t(tPage, { key: 'about-us-para-1' })} /> diff --git a/src/pages/[locale]/news/[...slug].astro b/src/pages/[locale]/news/[...slug].astro index 4585cf2..580f4a3 100644 --- a/src/pages/[locale]/news/[...slug].astro +++ b/src/pages/[locale]/news/[...slug].astro @@ -1,7 +1,7 @@ --- import Article from '$layouts/Article.astro'; import { getCollection, render } from 'astro:content'; -import { getLocale, getSlug } from '$lib/newsUtils'; +import { getDate, getLocale, getSlug } from '$lib/newsUtils'; export async function getStaticPaths() { return (await getCollection('news')).map((entry) => ({ @@ -15,11 +15,22 @@ export async function getStaticPaths() { const { entry } = Astro.props; const { Content } = await render(entry); + +const publicationDate = getDate(entry); --- <Article title={entry.data.title}> <section> <h1>{entry.data.title}</h1> + <time datetime={publicationDate?.toISOString()}> + { + publicationDate?.toLocaleDateString('en-GB', { + day: 'numeric', + month: 'short', + year: 'numeric', + }) + } + </time> <Content /> </section> </Article> |
