From 83144491ded4bb483bf74125794294c58b193b7e Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Aug 2023 17:50:43 +0100 Subject: Pulls out NewsPreviewLink --- src/components/NewsPreviewLink.astro | 20 ++++++++++++++++++++ src/i18n/translations/components/newsPreviewLink.ts | 11 +++++++++++ src/i18n/translations/pages/news.ts | 4 ---- src/pages/[locale]/news/index.astro | 13 ++----------- 4 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 src/components/NewsPreviewLink.astro create mode 100644 src/i18n/translations/components/newsPreviewLink.ts (limited to 'src') diff --git a/src/components/NewsPreviewLink.astro b/src/components/NewsPreviewLink.astro new file mode 100644 index 0000000..99ecb60 --- /dev/null +++ b/src/components/NewsPreviewLink.astro @@ -0,0 +1,20 @@ +--- +import translate from '$i18n/translate'; +import tNewsPreviewLink from '$i18n/translations/components/newsPreviewLink'; +import type Locale from '$types/Locale'; +import type { CollectionEntry } from 'astro:content'; + +interface Props { + locale: Locale; + newsItem: CollectionEntry<'news'>; +} + +const { locale, newsItem } = Astro.props; +const t = translate(locale); +--- + + +

{newsItem.data.title}

+

{newsItem.data.summary}

+ +
diff --git a/src/i18n/translations/components/newsPreviewLink.ts b/src/i18n/translations/components/newsPreviewLink.ts new file mode 100644 index 0000000..98b2dd9 --- /dev/null +++ b/src/i18n/translations/components/newsPreviewLink.ts @@ -0,0 +1,11 @@ +import type { TranslationsDictionary } from '$types/TranslationsDictionary'; + +const tNewsPreviewLink = { + 'read-article': { + sco: () => 'Read fu airticle', + 'en-GB': () => 'Read full article', + }, +}; + +type Raw = typeof tNewsPreviewLink; +export default tNewsPreviewLink as TranslationsDictionary; diff --git a/src/i18n/translations/pages/news.ts b/src/i18n/translations/pages/news.ts index 0cc411a..22517d1 100644 --- a/src/i18n/translations/pages/news.ts +++ b/src/i18n/translations/pages/news.ts @@ -5,10 +5,6 @@ const tPage = { 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!', diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro index 3e1b994..42a17e2 100644 --- a/src/pages/[locale]/news/index.astro +++ b/src/pages/[locale]/news/index.astro @@ -5,7 +5,7 @@ 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'; +import NewsPreviewLink from '$components/NewsPreviewLink.astro'; const allNews = await getCollection('news'); const locale = getLocaleFromPath(Astro.url.pathname); @@ -29,16 +29,7 @@ export async function getStaticPaths() {
{ allNewsInLocale.length > 0 ? ( - allNewsInLocale.map((item) => ( - -

{item.data.title}

-

{item.data.summary}

- -
- )) + allNewsInLocale.map((item) => ) ) : (

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

) -- cgit v1.2.3