summaryrefslogtreecommitdiff
path: root/src/lib/newsUtils.ts
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+joeacarstairs@users.noreply.github.com>2025-01-08 19:06:59 +0000
committerGitHub <noreply@github.com>2025-01-08 19:06:59 +0000
commit7c9e28c1f614cbab7f84344be840e9aec0bc194c (patch)
tree205afc5e3b411bd2ee84b83287307b2deb4d4192 /src/lib/newsUtils.ts
parent9fb9e47e92049b72cdc7cbaa3e9d43ed1aacd095 (diff)
parent7e0219994b0f62b7d17310f5adebb549e129c952 (diff)
Merge pull request #110 from joeacarstairs/staging
Update
Diffstat (limited to 'src/lib/newsUtils.ts')
-rw-r--r--src/lib/newsUtils.ts6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib/newsUtils.ts b/src/lib/newsUtils.ts
index 233fdcf..4333534 100644
--- a/src/lib/newsUtils.ts
+++ b/src/lib/newsUtils.ts
@@ -1,6 +1,7 @@
import locales from '$i18n/locales';
import type Locale from '$types/Locale';
import { getCollection, type CollectionEntry } from 'astro:content';
+import { correctLocaleCasing } from './correctLocaleCasing';
export async function getMostRecentNewsItem(locale: Locale) {
const allNews = await getCollection('news');
@@ -14,7 +15,8 @@ export async function getMostRecentNewsItem(locale: Locale) {
export function getLocale(newsItem: CollectionEntry<'news'>) {
const srcPath = newsItem.id;
- return srcPath.slice(0, srcPath.indexOf('/'));
+ const localeInUnknownCase = srcPath.slice(0, srcPath.indexOf('/'));
+ return correctLocaleCasing(localeInUnknownCase);
}
export function getHref(newsItem: CollectionEntry<'news'>) {
@@ -46,7 +48,7 @@ export function isBefore(item1: CollectionEntry<'news'>, item2: CollectionEntry<
}
export function getDate(newsItem: CollectionEntry<'news'>) {
- const matchDate = new RegExp(`(${locales.join('|')})/(\\d\\d\\d\\d-\\d\\d-\\d\\d)`);
+ const matchDate = new RegExp(`(${locales.join('|')})/(\\d\\d\\d\\d-\\d\\d-\\d\\d)`, 'i');
const date = newsItem.id.match(matchDate)?.[2];
return date ? new Date(date) : null;
}