summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/[locale]/news/[...slug].astro23
-rw-r--r--src/pages/[locale]/news/index.astro6
2 files changed, 8 insertions, 21 deletions
diff --git a/src/pages/[locale]/news/[...slug].astro b/src/pages/[locale]/news/[...slug].astro
index e3b8b36..a24e65a 100644
--- a/src/pages/[locale]/news/[...slug].astro
+++ b/src/pages/[locale]/news/[...slug].astro
@@ -1,28 +1,13 @@
---
-import locales from '$i18n/locales';
import Article from '$layouts/Article.astro';
-import type Locale from '$types/Locale';
-import { CollectionEntry, getCollection } from 'astro:content';
+import { getCollection } from 'astro:content';
+import { getLocale, getSlug } from '$lib/newsUtils';
export async function getStaticPaths() {
- function localeFromSlug(slug: CollectionEntry<'news'>['slug']): Locale | undefined {
- const lowerCaseLocale = new RegExp(`^(${locales.map((l) => l.toLocaleLowerCase()).join('|')})`);
- const matchedLowerCaseLocale = slug.match(lowerCaseLocale)?.[1];
- switch (matchedLowerCaseLocale) {
- case 'sco':
- return 'sco';
- case 'en-gb':
- return 'en-GB';
- default:
- console.warn('Could not find locale in slug %s', slug);
- return undefined;
- }
- }
-
return (await getCollection('news')).map((entry) => ({
params: {
- slug: entry.slug.replace('/', '-'),
- locale: localeFromSlug(entry.slug),
+ slug: getSlug(entry),
+ locale: getLocale(entry),
},
props: { entry },
}));
diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro
index 37e7dd6..112f87b 100644
--- a/src/pages/[locale]/news/index.astro
+++ b/src/pages/[locale]/news/index.astro
@@ -5,12 +5,14 @@ import Page from '$layouts/Page.astro';
import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath';
import localeStaticPaths from '$lib/localeStaticPaths';
import { getCollection } from 'astro:content';
-import { isNewsItemInLocale } from '$lib/newsUtils';
+import { isBefore, isNewsItemInLocale } from '$lib/newsUtils';
import NewsIndex from '$components/NewsIndex/NewsIndex.astro';
const allNews = await getCollection('news');
const locale = getLocaleFromPathOrThrow(Astro.url.pathname);
-const allNewsInLocale = allNews.filter((item) => isNewsItemInLocale(item, locale));
+const allNewsInLocale = allNews
+ .filter((item) => isNewsItemInLocale(item, locale))
+ .sort((a, b) => (isBefore(a, b) ? 1 : isBefore(b, a) ? -1 : 0));
const t = translate(locale);
export async function getStaticPaths() {