diff options
Diffstat (limited to 'src')
18 files changed, 48 insertions, 57 deletions
diff --git a/src/components/LallansIssue.astro b/src/components/LallansIssue.astro index a07d345..690e96c 100644 --- a/src/components/LallansIssue.astro +++ b/src/components/LallansIssue.astro @@ -1,19 +1,19 @@ --- import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; import relativePath from '$lib/relativePath'; import type LallansIssue from '$types/LallansIssue'; -import type Locale from '$types/Locale'; import LallansIssueContributions from './LallansIssueContributions.astro'; import LallansIssueContributors from './LallansIssueContributors.astro'; import PayPalButtons from './PayPalButtons.astro'; interface Props { issue: LallansIssue; - locale: Locale; } -const { issue, locale } = Astro.props; +const { issue } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -36,7 +36,7 @@ const t = translate(locale); <section> { 'contributions' in issue ? ( - <LallansIssueContributions contributions={issue.contributions} locale={locale} /> + <LallansIssueContributions contributions={issue.contributions} /> ) : ( 'contributors' in issue && <LallansIssueContributors contributors={issue.contributors} /> ) diff --git a/src/components/LallansIssueContributions.astro b/src/components/LallansIssueContributions.astro index 425f66a..9cf46da 100644 --- a/src/components/LallansIssueContributions.astro +++ b/src/components/LallansIssueContributions.astro @@ -1,15 +1,15 @@ --- import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; import type { Contribution } from '$types/LallansIssue'; -import type Locale from '$types/Locale'; interface Props { contributions: Contribution[]; - locale: Locale; } -const { contributions, locale } = Astro.props; +const { contributions } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- diff --git a/src/components/LallansIssuesGallery.astro b/src/components/LallansIssuesGallery.astro index c784156..f3db9b3 100644 --- a/src/components/LallansIssuesGallery.astro +++ b/src/components/LallansIssuesGallery.astro @@ -1,13 +1,8 @@ --- import { getAllLallansIssues } from '$data/lallans'; -import type Locale from '$types/Locale'; - -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +const locale = getLocaleFromPath(Astro.url.pathname); const issues = await getAllLallansIssues(); --- diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 45cf96b..c4e31b2 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -1,16 +1,11 @@ --- -import type Locale from '$types/Locale'; import Breadcrumbs from './Breadcrumbs.astro'; import SwitchLanguageLink from './SwitchLanguageLink.astro'; import tSite from '$i18n/translations/site'; import translate from '$i18n/translate'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; - +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -20,6 +15,6 @@ const t = translate(locale); {t(tSite, { key: 'scots-leid-associe' })} </a> </p> - <SwitchLanguageLink currentLocale={locale} /> + <SwitchLanguageLink /> <Breadcrumbs /> </nav> diff --git a/src/components/Scotsoun.astro b/src/components/Scotsoun.astro index 1491ebc..a0600d1 100644 --- a/src/components/Scotsoun.astro +++ b/src/components/Scotsoun.astro @@ -2,17 +2,17 @@ import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; import tComponent from '$i18n/translations/components/scotsoun'; -import type Locale from '$types/Locale'; import type Scotsoun from '$types/Scotsoun'; import PayPalButtons from './PayPalButtons.astro'; import relativePath from '$lib/relativePath'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; interface Props { - locale: Locale; scotsoun: Scotsoun; } -const { locale, scotsoun } = Astro.props; +const { scotsoun } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- diff --git a/src/components/ScotsounCdGallery.astro b/src/components/ScotsounCdGallery.astro index 6f6c794..0a8cd92 100644 --- a/src/components/ScotsounCdGallery.astro +++ b/src/components/ScotsounCdGallery.astro @@ -1,13 +1,8 @@ --- import { getAllScotsoun } from '$data/scotsoun'; -import type Locale from '$types/Locale'; - -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +const locale = getLocaleFromPath(Astro.url.pathname); const scotsoun = await getAllScotsoun(); --- diff --git a/src/components/SwitchLanguageLink.astro b/src/components/SwitchLanguageLink.astro index 96dd538..62de1ba 100644 --- a/src/components/SwitchLanguageLink.astro +++ b/src/components/SwitchLanguageLink.astro @@ -3,13 +3,10 @@ import tPage from '$i18n/translations/components/languageLinks'; import tSite from '$i18n/translations/site'; import translate from '$i18n/translate'; import type Locale from '$types/Locale'; - -interface Props { - currentLocale: Locale; -} +import getLocaleFromPath from '$lib/getLocaleFromPath'; // This logic assumes that there are exactly two locales. -const { currentLocale } = Astro.props; +const currentLocale = getLocaleFromPath(Astro.url.pathname); const otherLocale: Locale = currentLocale === 'sco' ? 'en-GB' : 'sco'; const currentPath = Astro.url.pathname; const currentLocaleInPath = new RegExp(`(?<=^/)(${currentLocale}/)?`); diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 9bca7e1..54b8c25 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -3,14 +3,14 @@ import Footer from '$components/Footer.astro'; import Navbar from '$components/Navbar.astro'; import translate from '$i18n/translate'; import site from '$i18n/translations/site'; -import type Locale from '$types/Locale'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; interface Props { - locale: Locale; title: string; } -const { locale, title } = Astro.props; +const { title } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -27,7 +27,7 @@ const t = translate(locale); <title>{title} | {t(site, { key: 'title' })}</title> </head> <body> - <Navbar locale={locale} /> + <Navbar /> <slot /> <Footer /> </body> diff --git a/src/layouts/Page.astro b/src/layouts/Page.astro index 8e8b5a9..bc7a095 100644 --- a/src/layouts/Page.astro +++ b/src/layouts/Page.astro @@ -1,16 +1,14 @@ --- -import type Locale from '$types/Locale'; import Layout from './Layout.astro'; interface Props { - locale: Locale; title: string; } -const { locale, title } = Astro.props; +const { title } = Astro.props; --- -<Layout locale={locale} title={title}> +<Layout title={title}> <main id="main"> <slot /> </main> diff --git a/src/lib/getLocaleFromPath.ts b/src/lib/getLocaleFromPath.ts new file mode 100644 index 0000000..f5dc697 --- /dev/null +++ b/src/lib/getLocaleFromPath.ts @@ -0,0 +1,11 @@ +import locales from '$i18n/locales'; +import type Locale from '$types/Locale'; + +export default function (path: string): Locale { + const regex = new RegExp(`^/(${locales.join('|')})`); + const match = path.match(regex)?.[1]; + if (!match) { + throw new Error(`Cannot find locale in path ${path}.`); + } + return match as Locale; +} diff --git a/src/pages/[locale]/furthsettins/index.astro b/src/pages/[locale]/furthsettins/index.astro index 43ff28e..eb4c92a 100644 --- a/src/pages/[locale]/furthsettins/index.astro +++ b/src/pages/[locale]/furthsettins/index.astro @@ -15,7 +15,7 @@ const locale = Astro.params.locale as Locale; const t = translate(locale); --- -<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}> +<Page title={t(tFurthsettins, { key: 'title' })}> <section> <h1>Furthsettins</h1> diff --git a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro index 25da7e6..48f1947 100644 --- a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro +++ b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro @@ -21,6 +21,6 @@ const issueNumber = new Number(Astro.params.issueNumber).valueOf() as LallansIss const issue = await getLallansIssue[issueNumber](); --- -<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}> - <LallansIssue issue={issue} locale={locale} /> +<Page title={t(tFurthsettins, { key: 'title' })}> + <LallansIssue issue={issue} /> </Page> diff --git a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/payment-success-confirmation.astro b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/payment-success-confirmation.astro index 4a26146..2f0a9d4 100644 --- a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/payment-success-confirmation.astro +++ b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/payment-success-confirmation.astro @@ -19,7 +19,7 @@ const t = translate(locale); const issueNumber = new Number(Astro.params.issueNumber).valueOf() as LallansIssueNumber; --- -<Page locale={locale} title={t(tPage, { key: 'title' })}> +<Page title={t(tPage, { key: 'title' })}> <section> <h1>{t(tPage, { key: 'title' })}</h1> <p>{t(tPage, { key: 'payment-confirmation-message', issueNumber: `${issueNumber}` })}</p> diff --git a/src/pages/[locale]/furthsettins/lallans/index.astro b/src/pages/[locale]/furthsettins/lallans/index.astro index 65f7b63..3e4fd46 100644 --- a/src/pages/[locale]/furthsettins/lallans/index.astro +++ b/src/pages/[locale]/furthsettins/lallans/index.astro @@ -14,9 +14,9 @@ const locale = Astro.params.locale as Locale; const t = translate(locale); --- -<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}> +<Page title={t(tFurthsettins, { key: 'title' })}> <section class="section--full-width"> <h1>Lallans</h1> - <LallansIssuesGallery locale={locale} /> + <LallansIssuesGallery /> </section> </Page> diff --git a/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/index.astro b/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/index.astro index 5b5dc82..a641561 100644 --- a/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/index.astro +++ b/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/index.astro @@ -22,6 +22,6 @@ const t = translate(locale); const scotsoun = await getScotsoun[scotsounId](); --- -<Page locale={locale} title={t(tPage, { key: 'title' })}> - <Scotsoun scotsoun={scotsoun} locale={locale} /> +<Page title={t(tPage, { key: 'title' })}> + <Scotsoun scotsoun={scotsoun} /> </Page> diff --git a/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/payment-success-confirmation.astro b/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/payment-success-confirmation.astro index 49f1bf7..16bbdd8 100644 --- a/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/payment-success-confirmation.astro +++ b/src/pages/[locale]/furthsettins/scotsoun/[scotsounId]/payment-success-confirmation.astro @@ -19,7 +19,7 @@ const scotsounId = Astro.params.scotsounId as ScotsounId; const t = translate(locale); --- -<Page locale={locale} title={t(tPage, { key: 'title' })}> +<Page title={t(tPage, { key: 'title' })}> <section> <h1>{t(tPage, { key: 'title' })}</h1> <p>{t(tPage, { key: 'payment-confirmation-message', scotsounId })}</p> diff --git a/src/pages/[locale]/furthsettins/scotsoun/index.astro b/src/pages/[locale]/furthsettins/scotsoun/index.astro index feb86a3..ed9490c 100644 --- a/src/pages/[locale]/furthsettins/scotsoun/index.astro +++ b/src/pages/[locale]/furthsettins/scotsoun/index.astro @@ -14,9 +14,9 @@ const locale = Astro.params.locale as Locale; const t = translate(locale); --- -<Page locale={locale} title={t(tPage, { key: 'title' })}> +<Page title={t(tPage, { key: 'title' })}> <section class="section--full-width"> <h1>Scotsoun</h1> - <ScotsounCdGallery locale={locale} /> + <ScotsounCdGallery /> </section> </Page> diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro index b065e50..c32ddf6 100644 --- a/src/pages/[locale]/index.astro +++ b/src/pages/[locale]/index.astro @@ -14,7 +14,7 @@ const locale = Astro.params.locale as Locale; const t = translate(locale); --- -<Page locale={locale} title={t(home, { key: 'title' })}> +<Page title={t(home, { key: 'title' })}> <section> <h1 class="title">{t(site, { key: 'title' })}</h1> <h1>Tap-level heidin</h1> |
