summaryrefslogtreecommitdiff
path: root/src/components/Navbar
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-18 21:28:17 +0100
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-18 21:38:16 +0100
commita56344ea9aced15fc4d2932d48cb2efd7f452e94 (patch)
tree12e58f6a0699291d4c5aea5c36d251db845f895b /src/components/Navbar
parent57b86c33a183e11652215f8588f728476f176fc5 (diff)
Pulls out nav module
Diffstat (limited to 'src/components/Navbar')
-rw-r--r--src/components/Navbar/Breadcrumbs.astro33
-rw-r--r--src/components/Navbar/Logo.astro14
-rw-r--r--src/components/Navbar/NavLinks.astro25
-rw-r--r--src/components/Navbar/Navbar.astro15
4 files changed, 87 insertions, 0 deletions
diff --git a/src/components/Navbar/Breadcrumbs.astro b/src/components/Navbar/Breadcrumbs.astro
new file mode 100644
index 0000000..1e82fd9
--- /dev/null
+++ b/src/components/Navbar/Breadcrumbs.astro
@@ -0,0 +1,33 @@
+---
+import findAllIndicesOf from '$lib/findAllIndicesOf';
+import translate from '$i18n/translate';
+import tBreadcrumbs from '$i18n/translations/components/breadcrumbs';
+import type Locale from '$types/Locale';
+import locales from '$i18n/locales';
+
+const path = Astro.url.pathname.replace(/(?<!\/)$/, '/');
+const localeInPath = new RegExp(`/(?<=^/)(${locales.join('|')})`);
+const locale = path.match(localeInPath)?.[1] as Locale;
+if (!locale) {
+ return;
+}
+const pathWithoutLocale = path.replace(new RegExp(`^/${locale}`), '');
+const slashIndices = findAllIndicesOf('/', pathWithoutLocale);
+const parentRoutes = slashIndices.map((n) => pathWithoutLocale.slice(0, n + 1)).slice(0, -1);
+
+const t = translate(locale);
+---
+
+<ol class="nav__breadcrumbs">
+ {
+ parentRoutes.map((route) => {
+ return (
+ <li>
+ <a class="link" href={`/${locale}${route}`}>
+ {t(tBreadcrumbs, { key: route })}
+ </a>
+ </li>
+ );
+ })
+ }
+</ol>
diff --git a/src/components/Navbar/Logo.astro b/src/components/Navbar/Logo.astro
new file mode 100644
index 0000000..58bf01d
--- /dev/null
+++ b/src/components/Navbar/Logo.astro
@@ -0,0 +1,14 @@
+---
+import translate from '$i18n/translate';
+import getLocaleFromPath from '$lib/getLocaleFromPath';
+import tSite from '$i18n/translations/site';
+
+const locale = getLocaleFromPath(Astro.url.pathname);
+const t = translate(locale);
+---
+
+<p class="title--small nav__logo">
+ <a href="/">
+ {t(tSite, { key: 'scots-leid-associe' })}
+ </a>
+</p>
diff --git a/src/components/Navbar/NavLinks.astro b/src/components/Navbar/NavLinks.astro
new file mode 100644
index 0000000..a34014e
--- /dev/null
+++ b/src/components/Navbar/NavLinks.astro
@@ -0,0 +1,25 @@
+---
+import getLocaleFromPath from '$lib/getLocaleFromPath';
+import translate from '$i18n/translate';
+import tNews from '$i18n/translations/pages/news';
+import tFurthsettins from '$i18n/translations/pages/furthsettins';
+import tHame from '$i18n/translations/pages/home';
+
+const locale = getLocaleFromPath(Astro.url.pathname);
+const t = translate(locale);
+---
+
+<ul class="nav__nav-links">
+ <li>
+ <a class="btn" href={`/${locale}/news`}>{t(tNews, { key: 'title' })}</a>
+ </li>
+ <li>
+ <a class="btn" href={`/${locale}/furthsettins`}>{t(tFurthsettins, { key: 'title' })}</a>
+ </li>
+ <li>
+ <a class="btn" href={`/${locale}/#jyne`}>{t(tHame, { key: 'jyne' })}</a>
+ </li>
+ <li>
+ <a class="btn" href={`/${locale}/#contact`}>{t(tHame, { key: 'contact' })}</a>
+ </li>
+</ul>
diff --git a/src/components/Navbar/Navbar.astro b/src/components/Navbar/Navbar.astro
new file mode 100644
index 0000000..aea8909
--- /dev/null
+++ b/src/components/Navbar/Navbar.astro
@@ -0,0 +1,15 @@
+---
+import Breadcrumbs from './Breadcrumbs.astro';
+import SwitchLanguageLink from '../SwitchLanguageLink.astro';
+import NavLinks from './NavLinks.astro';
+import Logo from './Logo.astro';
+---
+
+<nav>
+ <Logo />
+ <NavLinks />
+ <div class="nav__bottom-row">
+ <SwitchLanguageLink />
+ <Breadcrumbs />
+ </div>
+</nav>