From f4eb8b6fc931f7ded138dceb2b9df4c63ac7e353 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Sat, 26 Aug 2023 16:58:27 +0100 Subject: Differentiates getLocaleFromPath failure strategies --- src/pages/[locale]/news/index.astro | 4 ++-- src/pages/[locale]/rss.xml.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pages') diff --git a/src/pages/[locale]/news/index.astro b/src/pages/[locale]/news/index.astro index 6e95884..37e7dd6 100644 --- a/src/pages/[locale]/news/index.astro +++ b/src/pages/[locale]/news/index.astro @@ -2,14 +2,14 @@ import translate from '$i18n/translate'; import tPage from '$i18n/translations/pages/news'; import Page from '$layouts/Page.astro'; -import getLocaleFromPath from '$lib/getLocaleFromPath'; +import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath'; import localeStaticPaths from '$lib/localeStaticPaths'; import { getCollection } from 'astro:content'; import { isNewsItemInLocale } from '$lib/newsUtils'; import NewsIndex from '$components/NewsIndex/NewsIndex.astro'; const allNews = await getCollection('news'); -const locale = getLocaleFromPath(Astro.url.pathname); +const locale = getLocaleFromPathOrThrow(Astro.url.pathname); const allNewsInLocale = allNews.filter((item) => isNewsItemInLocale(item, locale)); const t = translate(locale); diff --git a/src/pages/[locale]/rss.xml.ts b/src/pages/[locale]/rss.xml.ts index b3cb22f..9d2e34b 100644 --- a/src/pages/[locale]/rss.xml.ts +++ b/src/pages/[locale]/rss.xml.ts @@ -2,7 +2,7 @@ import rss, { RSSFeedItem } from '@astrojs/rss'; import { CollectionEntry, getCollection } from 'astro:content'; import { getDate, getHref, isNewsItemInLocale } from '$lib/newsUtils'; import localeStaticPaths from '$lib/localeStaticPaths'; -import getLocaleFromPath from '$lib/getLocaleFromPath'; +import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath'; import type { APIContext } from 'astro'; import translate from '$i18n/translate'; import tFeed from '$i18n/translations/pages/rss.xml'; @@ -13,7 +13,7 @@ import type Scotsoun from '$types/Scotsoun'; import { getAllScotsoun } from '$data/scotsoun'; export async function get(context: APIContext) { - const locale = getLocaleFromPath(context.url.pathname); + const locale = getLocaleFromPathOrThrow(context.url.pathname); const t = translate(locale); const site = context.site; if (!site) { -- cgit v1.2.3