From a25b3c13b1ac5c40e48cdf42baf4081dd33dcf9f Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:13:21 +0100 Subject: Adds news index page --- src/pages/[locale]/news/index.astro | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/pages/[locale]/news/index.astro (limited to 'src/pages') diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro new file mode 100644 index 0000000..3e1b994 --- /dev/null +++ b/src/pages/[locale]/news/index.astro @@ -0,0 +1,48 @@ +--- +import translate from '$i18n/translate'; +import tPage from '$i18n/translations/pages/news'; +import Page from '$layouts/Page.astro'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +import localeStaticPaths from '$lib/localeStaticPaths'; +import { getCollection } from 'astro:content'; +import relativePath from '$lib/relativePath'; + +const allNews = await getCollection('news'); +const locale = getLocaleFromPath(Astro.url.pathname); +const allNewsInLocale = allNews.filter(isInLocale); +const t = translate(locale); + +function isInLocale(newsItem: (typeof allNews)[number]) { + const srcPath = newsItem.id; + const newsItemLocale = srcPath.slice(0, srcPath.indexOf('/')); + return newsItemLocale === locale; +} + +export async function getStaticPaths() { + return localeStaticPaths; +} +--- + + +
+

{t(tPage, { key: 'title' })}

+
+ { + allNewsInLocale.length > 0 ? ( + allNewsInLocale.map((item) => ( + +

{item.data.title}

+

{item.data.summary}

+ +
+ )) + ) : ( +

{t(tPage, { key: 'no-news' })}

+ ) + } +
+
+
-- cgit v1.2.3