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/i18n/translations/pages/news.ts | 19 +++++++++++++++ src/pages/[locale]/news/index.astro | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/i18n/translations/pages/news.ts create mode 100644 src/pages/[locale]/news/index.astro (limited to 'src') diff --git a/src/i18n/translations/pages/news.ts b/src/i18n/translations/pages/news.ts new file mode 100644 index 0000000..0cc411a --- /dev/null +++ b/src/i18n/translations/pages/news.ts @@ -0,0 +1,19 @@ +import type { TranslationsDictionary } from '$types/TranslationsDictionary'; + +const tPage = { + title: { + sco: () => 'News', + 'en-GB': () => 'News', + }, + 'read-article': { + sco: () => 'Read fu airticle', + 'en-GB': () => 'Read full article', + }, + 'no-news': { + sco: () => 'The ar nae news at the present time. Caw again later!', + 'en-GB': () => 'There is no news at the current time. Check in again later!', + }, +}; + +type Raw = typeof tPage; +export default tPage as TranslationsDictionary; 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