diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-14 21:10:08 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-14 21:14:19 +0100 |
| commit | 50ee98e20e0721375cf58b0e2de1c471a246abb0 (patch) | |
| tree | e43d804fb650d0c0dd38f0db0a82d5106ad0122f /src | |
| parent | e01eefe318ccb9916fa0e4561b5c995d932487fa (diff) | |
Adds news item page
Diffstat (limited to 'src')
| -rw-r--r-- | src/pages/[locale]/news/[...slug].astro | 44 |
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> |
