Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Refactor header component and add LanguagePicker component
Browse files Browse the repository at this point in the history
  • Loading branch information
osamajandali committed Mar 11, 2024
1 parent 7f2c2d9 commit 277e56b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 57 deletions.
94 changes: 49 additions & 45 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getLangFromUrl } from '../i18n/utils';
const lang = getLangFromUrl(Astro.url);
import { Icon } from "astro-icon";
import LanguagePicker from './LanguagePicker.astro';
const { isHomepage } = Astro.props;
const links = [
{
Expand All @@ -28,49 +29,52 @@ const links = [
];
---

<nav
class="text-xs lg:text-sm text-center font-bold max-w-5xl mx-auto px-4 flex items-center justify-between flex-wrap my-4 relative"
>
<a href="/" aria-label="SoGS Logo">
<Icon name="logo-alt" className="w-32 lg:w-40" />
</a>
<button
class="lg:hidden block focus:outline-none"
onclick="document.querySelector('ul').classList.toggle('hidden')"
>
<Icon name="menu" className="w-6 h-6" />
</button>
<ul
class="hidden lg:flex gap-4 items-center absolute lg:static bg-white lg:bg-transparent shadow-md lg:shadow-none z-50 top-10 left-0 w-full lg:w-auto py-3 lg:py-0"
<div class=" max-w-5xl mx-auto px-4 my-4">
<LanguagePicker />
<nav
class="text-xs lg:text-sm text-center font-bold flex items-center justify-between flex-wrap relative"
>
{
links.map(({ label, url }) => (
<li class="py-3 lg:py-0">
<a
href={url}
target={url.startsWith("http") ? "_blank" : "_self"}
rel={url.startsWith("http") ? "noopener noreferrer" : ""}
class={`${Astro.url.pathname === url ? "text-secondary" : ""}`}
>
{label}
</a>
</li>
))
}
{
!isHomepage && (
<li class="py-3 lg:py-0">
<a
class="bg-primary inline-block hover:bg-primary-light font-bold py-2 px-4 rounded
transition duration-200 ease-in-out
"
href=`/${lang}`
>
More Insights
</a>
</li>
)
}
</ul>
</nav>
<a href="/" aria-label="SoGS Logo">
<Icon name="logo-alt" className="w-32 lg:w-40" />
</a>
<button
class="lg:hidden block focus:outline-none"
onclick="document.querySelector('ul').classList.toggle('hidden')"
>
<Icon name="menu" className="w-6 h-6" />
</button>
<ul
class="hidden lg:flex gap-4 items-center absolute lg:static bg-white lg:bg-transparent shadow-md lg:shadow-none z-50 top-10 left-0 w-full lg:w-auto py-3 lg:py-0"
>
{
links.map(({ label, url }) => (
<li class="py-3 lg:py-0">
<a
href={url}
target={url.startsWith("http") ? "_blank" : "_self"}
rel={url.startsWith("http") ? "noopener noreferrer" : ""}
class={`${Astro.url.pathname === url ? "text-secondary" : ""}`}
>
{label}
</a>
</li>
))
}
{
!isHomepage && (
<li class="py-3 lg:py-0">
<a
class="bg-primary inline-block hover:bg-primary-light font-bold py-2 px-4 rounded
transition duration-200 ease-in-out
"
href=`/${lang}`
>
More Insights
</a>
</li>
)
}
</ul>
</nav>

</div>
17 changes: 10 additions & 7 deletions src/components/LanguagePicker.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
import { languages } from '../i18n/ui';
import { languages } from "../i18n/ui";
---
<ul>
{Object.entries(languages).map(([lang, label]) => (
<li>
<a href=`/${lang}/`>{label}</a>
</li>
))}

<ul class="text-xs flex justify-end mb-2 gap-2">
{
Object.entries(languages).map(([lang, label]) => (
<li>
<a href={`/${lang}/`}>{label}</a>
</li>
))
}
</ul>
4 changes: 0 additions & 4 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
import "../styles/base.css";
import LanguagePicker from '../components/LanguagePicker.astro';
import { getLangFromUrl } from '../i18n/utils';
const lang = getLangFromUrl(Astro.url);
Expand Down Expand Up @@ -117,8 +116,5 @@ const { title, description, image } = metaData
>
<!-- End Google Tag Manager (noscript) -->

<footer>
<LanguagePicker />
</footer>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
shortDescription: "Software legislation is on the rise"
layout: ../../layouts/InsightLayout.astro
layout: ../../../layouts/InsightLayout.astro
insightNo: 6
title: ソフトウェアの法整備は、この10年で4倍になった
image: software-legislation-has-quadrupled-in-the-last-decade.png
Expand Down

0 comments on commit 277e56b

Please sign in to comment.