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 ----------------------
src/i18n/translations/components/newsIndex.ts | 19 ++++++++++++++++
.../translations/components/newsPreviewLink.ts | 11 ----------
src/i18n/translations/pages/news.ts | 4 ----
src/pages/[locale]/index.astro | 18 ++++++++++------
src/pages/[locale]/news/index.astro | 12 ++---------
8 files changed, 82 insertions(+), 57 deletions(-)
create mode 100644 src/components/NewsIndex/NewsIndex.astro
create mode 100644 src/components/NewsIndex/NewsPreviewLink.astro
delete mode 100644 src/components/NewsPreviewLink.astro
create mode 100644 src/i18n/translations/components/newsIndex.ts
delete mode 100644 src/i18n/translations/components/newsPreviewLink.ts
(limited to 'src')
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}${headingLevel}>
+ `}
+ />
+ {newsItem.data.summary}
+ {t(tComponent, { key: 'read-article' })}
+
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}${headingLevel}>
- `}
- />
- {newsItem.data.summary}
- {t(tNewsPreviewLink, { key: 'read-article' })}
-
diff --git a/src/i18n/translations/components/newsIndex.ts b/src/i18n/translations/components/newsIndex.ts
new file mode 100644
index 0000000..0511b88
--- /dev/null
+++ b/src/i18n/translations/components/newsIndex.ts
@@ -0,0 +1,19 @@
+import type { TranslationsDictionary } from '$types/TranslationsDictionary';
+
+const tComponent = {
+ title: {
+ sco: () => 'News',
+ 'en-GB': () => 'News',
+ },
+ '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!',
+ },
+ 'read-article': {
+ sco: () => 'Read fu airticle',
+ 'en-GB': () => 'Read full article',
+ },
+};
+
+type Raw = typeof tComponent;
+export default tComponent as TranslationsDictionary;
diff --git a/src/i18n/translations/components/newsPreviewLink.ts b/src/i18n/translations/components/newsPreviewLink.ts
deleted file mode 100644
index 98b2dd9..0000000
--- a/src/i18n/translations/components/newsPreviewLink.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-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 22517d1..a794c6f 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',
},
- '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;
diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro
index 11188a0..e5e6040 100644
--- a/src/pages/[locale]/index.astro
+++ b/src/pages/[locale]/index.astro
@@ -5,8 +5,8 @@ import translate from '$i18n/translate';
import tPage from '$i18n/translations/pages/home';
import type Locale from '$types/Locale';
import { getMostRecentNewsItem } from '$lib/newsUtils';
-import NewsPreviewLink from '$components/NewsPreviewLink.astro';
import contactDetails from '$data/contactDetails';
+import NewsIndex from '$components/NewsIndex/NewsIndex.astro';
export async function getStaticPaths() {
return localeStaticPaths;
@@ -20,12 +20,16 @@ const mostRecentNewsItem = await getMostRecentNewsItem(locale);
- {mostRecentNewsItem && }
-
+
+ {
+ mostRecentNewsItem && (
+
+ )
+ }
diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro
index 8a6e322..6e95884 100644
--- a/src/pages/[locale]/news/index.astro
+++ b/src/pages/[locale]/news/index.astro
@@ -5,8 +5,8 @@ import Page from '$layouts/Page.astro';
import getLocaleFromPath from '$lib/getLocaleFromPath';
import localeStaticPaths from '$lib/localeStaticPaths';
import { getCollection } from 'astro:content';
-import NewsPreviewLink from '$components/NewsPreviewLink.astro';
import { isNewsItemInLocale } from '$lib/newsUtils';
+import NewsIndex from '$components/NewsIndex/NewsIndex.astro';
const allNews = await getCollection('news');
const locale = getLocaleFromPath(Astro.url.pathname);
@@ -21,14 +21,6 @@ export async function getStaticPaths() {
{t(tPage, { key: 'title' })}
-
- {
- allNewsInLocale.length > 0 ? (
- allNewsInLocale.map((item) =>
)
- ) : (
-
{t(tPage, { key: 'no-news' })}
- )
- }
-
+
--
cgit v1.2.3