Skip to content

Commit 55111e5

Browse files
committed
fix: share header link
1 parent f1ba70c commit 55111e5

3 files changed

Lines changed: 22 additions & 44 deletions

File tree

src/components/Header.astro

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
import { getRelativeLocaleUrl } from 'astro:i18n';
3+
import HeaderLink from '@/components/HeaderLink.astro';
34
import Logo from '@/components/Logo.astro';
45
import MobileMenu from '@/components/MobileMenu.astro';
5-
import { getLangFromUrl, isActive, useTranslations } from '@/i18n/utils';
6+
import { getLangFromUrl, useTranslations } from '@/i18n/utils';
67
78
const lang = getLangFromUrl(Astro.url);
89
const t = useTranslations(lang);
9-
const pathname = Astro.url.pathname.replace(/\/$/, '') || '/';
1010
1111
const navigationLinks = [
1212
{ href: getRelativeLocaleUrl(lang, '/'), label: t('nav.home') },
@@ -30,7 +30,7 @@ const ctaLinks = {
3030
<!-- Mobile: Logo + Hamburger in a flex row -->
3131
<div class="flex w-full items-center justify-between lg:hidden">
3232
<div class="flex items-center gap-2">
33-
<MobileMenu {navigationLinks} {ctaLinks} {pathname} />
33+
<MobileMenu {navigationLinks} {ctaLinks} />
3434
</div>
3535

3636
<div class="flex items-center gap-2">
@@ -50,22 +50,11 @@ const ctaLinks = {
5050
<Logo size="nav" showTitle />
5151
<ul class="menu menu-horizontal flex flex-1 flex-wrap gap-0 px-0 lg:gap-1">
5252
{
53-
navigationLinks.map((link) => {
54-
const isActiveLink = isActive(link.href, pathname);
55-
return (
56-
<li>
57-
<a
58-
class:list={[
59-
'btn btn-xs btn-ghost',
60-
isActiveLink && 'btn-outline btn-primary',
61-
]}
62-
href={link.href}
63-
>
64-
{link.label}
65-
</a>
66-
</li>
67-
);
68-
})
53+
navigationLinks.map((link) => (
54+
<li>
55+
<HeaderLink href={link.href} class="btn-xs">{link.label}</HeaderLink>
56+
</li>
57+
))
6958
}
7059
</ul>
7160
</div>

src/components/HeaderLink.astro

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ const isActiveLink = isActive(hrefStr, pathname);
1313
<a
1414
href={href}
1515
class:list={[
16-
'inline-block border-b-4 px-2 py-4 text-sm font-medium no-underline transition-colors',
17-
isActiveLink
18-
? 'border-primary text-primary'
19-
: 'border-transparent text-base-content hover:text-primary',
16+
'btn btn-ghost',
17+
isActiveLink && 'btn-outline btn-primary',
2018
className,
2119
]}
2220
{...props}

src/components/MobileMenu.astro

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
import { Icon } from 'astro-icon/components';
3+
import HeaderLink from '@/components/HeaderLink.astro';
34
import Logo from '@/components/Logo.astro';
4-
import { getLangFromUrl, isActive, useTranslations } from '@/i18n/utils';
5+
import { getLangFromUrl, useTranslations } from '@/i18n/utils';
56
67
interface Props {
78
navigationLinks: Array<{ href: string; label: string }>;
89
ctaLinks: {
910
secondary: { href: string; label: string };
1011
primary: { href: string; label: string };
1112
};
12-
pathname: string;
1313
}
1414
15-
const { navigationLinks, ctaLinks, pathname } = Astro.props;
15+
const { navigationLinks, ctaLinks } = Astro.props;
1616
const lang = getLangFromUrl(Astro.url);
1717
const t = useTranslations(lang);
1818
---
@@ -44,24 +44,15 @@ const t = useTranslations(lang);
4444
<div class="flex items-center gap-2">
4545
<Logo size="nav" showTitle />
4646
</div>
47-
<ul class="menu w-full gap-1 p-0">
48-
{
49-
navigationLinks.map((link) => {
50-
const isActiveLink = isActive(link.href, pathname);
51-
return (
52-
<li>
53-
<a
54-
class:list={[
55-
'btn btn-ghost btn-sm w-full justify-start',
56-
isActiveLink && 'btn-outline btn-primary',
57-
]}
58-
href={link.href}
59-
>
60-
{link.label}
61-
</a>
62-
</li>
63-
);
64-
})
47+
<ul class="menu w-full gap-1 p-0">
48+
{
49+
navigationLinks.map((link) => (
50+
<li>
51+
<HeaderLink href={link.href} class="btn-sm w-full justify-start">
52+
{link.label}
53+
</HeaderLink>
54+
</li>
55+
))
6556
}
6657
</ul>
6758
</div>

0 commit comments

Comments
 (0)