From a63d28cf878197ead3e61eaf4acd1932a6edd94c Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Wed, 8 Jan 2025 18:05:08 +0000 Subject: Lallans 105 --- src/content/news/en-GB/2025-01-08-lallans-105.mdx | 12 ++++++++++++ src/content/news/sco/2025-01-08-lallans-105.mdx | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/content/news/en-GB/2025-01-08-lallans-105.mdx create mode 100644 src/content/news/sco/2025-01-08-lallans-105.mdx (limited to 'src') diff --git a/src/content/news/en-GB/2025-01-08-lallans-105.mdx b/src/content/news/en-GB/2025-01-08-lallans-105.mdx new file mode 100644 index 0000000..eed3ca7 --- /dev/null +++ b/src/content/news/en-GB/2025-01-08-lallans-105.mdx @@ -0,0 +1,12 @@ +--- +title: Lallans 105 is out +summary: "Lallans 105 has been dispatched to all our members: let us know if you don't receive it." +--- + +Lallans 105 has now been dispatched to our members. It should have arrived in time for Christmas, +however, we've had some issues communicating with our printer and distributor, Alliance. If you're a +member of the Scots Language Society and haven't received Lallans 105 yet, please +get in touch and we'll work to rectify any mistakes. + +We're working on diagnosing what went wrong this time and we will shortly decide a plan of action to +make sure we don't have this problem next time. diff --git a/src/content/news/sco/2025-01-08-lallans-105.mdx b/src/content/news/sco/2025-01-08-lallans-105.mdx new file mode 100644 index 0000000..b3152b3 --- /dev/null +++ b/src/content/news/sco/2025-01-08-lallans-105.mdx @@ -0,0 +1,12 @@ +--- +title: Lallans 105 is out +summary: "Lallans 105 haes been dispatcht til aa our members: gie's a bell gin you dinnae receive it." +--- + +Lallans 105 haes nou been dispatcht til our members. It shuid hae arrived in time for Christmas, +houaniver, we've haed some issues communicatin wi our prenter an distreibutor, Alliance. Gin you're +a member o the Scots Leid Associe and haena received Lallans 105 yet, pleise +get in titch and we'll ettle tae mak ony errors guid. + +We're ettlin tae diagnose whit gaed agley this time, and we will shuin decide a plan o action for tae +mak siccar we dinnae hae this problem neist time. -- cgit v1.2.3 From 7e0219994b0f62b7d17310f5adebb549e129c952 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Wed, 8 Jan 2025 18:40:15 +0000 Subject: Fixes English news feed --- src/lib/correctLocaleCasing.ts | 13 +++++++++++++ src/lib/getLocaleFromPath.ts | 5 +++-- src/lib/newsUtils.ts | 6 ++++-- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/lib/correctLocaleCasing.ts (limited to 'src') diff --git a/src/lib/correctLocaleCasing.ts b/src/lib/correctLocaleCasing.ts new file mode 100644 index 0000000..4a0f669 --- /dev/null +++ b/src/lib/correctLocaleCasing.ts @@ -0,0 +1,13 @@ +import locales from '$i18n/locales'; + +export function correctLocaleCasing(str: string) { + const strLowercase = str.toLowerCase(); + + for (const locale of locales) { + if (strLowercase === locale.toLowerCase()) { + return locale; + } + } + + return str; +} diff --git a/src/lib/getLocaleFromPath.ts b/src/lib/getLocaleFromPath.ts index 2cfaf41..b1e815c 100644 --- a/src/lib/getLocaleFromPath.ts +++ b/src/lib/getLocaleFromPath.ts @@ -1,13 +1,14 @@ import locales, { defaultLocale } from '$i18n/locales'; import type Locale from '$types/Locale'; +import { correctLocaleCasing } from './correctLocaleCasing'; export function getLocaleFromPath(path: string): Locale | null { - const regex = new RegExp(`^/(${locales.join('|')})`); + const regex = new RegExp(`^/(${locales.join('|')})`, 'i'); const match = path.match(regex)?.[1]; if (!match) { return null; } - return match as Locale; + return correctLocaleCasing(match) as Locale; } export function getLocaleFromPathOrDefault(path: string): Locale { 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; } -- cgit v1.2.3