summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-14 21:10:08 +0100
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-14 21:14:19 +0100
commit50ee98e20e0721375cf58b0e2de1c471a246abb0 (patch)
treee43d804fb650d0c0dd38f0db0a82d5106ad0122f /src
parente01eefe318ccb9916fa0e4561b5c995d932487fa (diff)
Adds news item page
Diffstat (limited to 'src')
-rw-r--r--src/pages/[locale]/news/[...slug].astro44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/pages/[locale]/news/[...slug].astro b/src/pages/[locale]/news/[...slug].astro
new file mode 100644
index 0000000..815387f
--- /dev/null
+++ b/src/pages/[locale]/news/[...slug].astro
@@ -0,0 +1,44 @@
+---
+import locales from '$i18n/locales';
+import Article from '$layouts/Article.astro';
+import type Locale from '$types/Locale';
+import { CollectionEntry, getCollection } from 'astro:content';
+
+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;
+ }
+ }
+
+ const paths = (await getCollection('news')).map((entry) => ({
+ params: {
+ slug: entry.slug.replace('/', '-'),
+ locale: localeFromSlug(entry.slug),
+ },
+ props: { entry },
+ }));
+
+ console.info('Paths: %s', JSON.stringify(paths));
+
+ return paths;
+}
+
+const { entry } = Astro.props;
+const { Content } = await entry.render();
+---
+
+<Article title={entry.data.title}>
+ <section>
+ <h1>{entry.data.title}</h1>
+ <Content />
+ </section>
+</Article>