diff options
| author | Joe Carstairs <65492573+joeacarstairs@users.noreply.github.com> | 2025-01-08 19:06:59 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-08 19:06:59 +0000 |
| commit | 7c9e28c1f614cbab7f84344be840e9aec0bc194c (patch) | |
| tree | 205afc5e3b411bd2ee84b83287307b2deb4d4192 | |
| parent | 9fb9e47e92049b72cdc7cbaa3e9d43ed1aacd095 (diff) | |
| parent | 7e0219994b0f62b7d17310f5adebb549e129c952 (diff) | |
Merge pull request #110 from joeacarstairs/staging
Update
| -rw-r--r-- | src/content/news/en-GB/2025-01-08-lallans-105.mdx | 12 | ||||
| -rw-r--r-- | src/content/news/sco/2025-01-08-lallans-105.mdx | 12 | ||||
| -rw-r--r-- | src/lib/correctLocaleCasing.ts | 13 | ||||
| -rw-r--r-- | src/lib/getLocaleFromPath.ts | 5 | ||||
| -rw-r--r-- | src/lib/newsUtils.ts | 6 |
5 files changed, 44 insertions, 4 deletions
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 +<a href="/en-GB/contact">get in touch</a> 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 +<a href="/en-GB/contact">get in titch</a> 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. 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; } |
