From 869976b711d862581d1d99bf884dd166b1ecdf3b Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Sun, 20 Aug 2023 07:57:21 +0100 Subject: Pulls out NewsIndex Astro component --- src/components/NewsIndex/NewsIndex.astro | 25 +++++++++++++++++++++++++ src/components/NewsIndex/NewsPreviewLink.astro | 25 +++++++++++++++++++++++++ src/components/NewsPreviewLink.astro | 25 ------------------------- 3 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 src/components/NewsIndex/NewsIndex.astro create mode 100644 src/components/NewsIndex/NewsPreviewLink.astro delete mode 100644 src/components/NewsPreviewLink.astro (limited to 'src/components') diff --git a/src/components/NewsIndex/NewsIndex.astro b/src/components/NewsIndex/NewsIndex.astro new file mode 100644 index 0000000..6738071 --- /dev/null +++ b/src/components/NewsIndex/NewsIndex.astro @@ -0,0 +1,25 @@ +--- +import type { CollectionEntry } from 'astro:content'; +import NewsPreviewLink from './NewsPreviewLink.astro'; +import getLocaleFromPath 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 = getLocaleFromPath(Astro.url.pathname); +const t = translate(locale); +--- + +
+ { + newsItems.length > 0 ? ( + newsItems.map((item) => ) + ) : ( +

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

+ ) + } +
diff --git a/src/components/NewsIndex/NewsPreviewLink.astro b/src/components/NewsIndex/NewsPreviewLink.astro new file mode 100644 index 0000000..aa8a371 --- /dev/null +++ b/src/components/NewsIndex/NewsPreviewLink.astro @@ -0,0 +1,25 @@ +--- +import translate from '$i18n/translate'; +import tComponent from '$i18n/translations/components/newsIndex'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +import type { CollectionEntry } from 'astro:content'; + +interface Props { + headingLevel: 'h1' | 'h2' | 'h3' | 'h4'; + newsItem: CollectionEntry<'news'>; +} + +const { headingLevel, newsItem } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); +const t = translate(locale); +--- + + + ${newsItem.data.title} + `} + /> +

{newsItem.data.summary}

+ +
diff --git a/src/components/NewsPreviewLink.astro b/src/components/NewsPreviewLink.astro deleted file mode 100644 index 90cce61..0000000 --- a/src/components/NewsPreviewLink.astro +++ /dev/null @@ -1,25 +0,0 @@ ---- -import translate from '$i18n/translate'; -import tNewsPreviewLink from '$i18n/translations/components/newsPreviewLink'; -import getLocaleFromPath from '$lib/getLocaleFromPath'; -import type { CollectionEntry } from 'astro:content'; - -interface Props { - headingLevel: 'h1' | 'h2' | 'h3' | 'h4'; - newsItem: CollectionEntry<'news'>; -} - -const { headingLevel, newsItem } = Astro.props; -const locale = getLocaleFromPath(Astro.url.pathname); -const t = translate(locale); ---- - - - ${newsItem.data.title} - `} - /> -

{newsItem.data.summary}

- -
-- cgit v1.2.3