summaryrefslogtreecommitdiff
path: root/src/components/NewsIndex/NewsIndex.astro
blob: ae4c226398537c3f6980676f3d746f8b3376fd17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
import type { CollectionEntry } from 'astro:content';
import NewsPreviewLink from './NewsPreviewLink.astro';
import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath';
import translate from '$i18n/translate';
import tComponent from '$i18n/translations/components/newsIndex';
interface Props {
  headingLevel: 'h2' | 'h3' | 'h4';
  newsItems: CollectionEntry<'news'>[];
}

const { headingLevel, newsItems } = Astro.props;
const locale = getLocaleFromPathOrThrow(Astro.url.pathname);
const t = translate(locale);
---

<div class="news-index">
  {
    newsItems.length > 0 ? (
      newsItems.map((item) => <NewsPreviewLink headingLevel={headingLevel} newsItem={item} />)
    ) : (
      <p>{t(tComponent, { key: 'no-news' })}</p>
    )
  }
</div>