Skip to content

Commit 983f433

Browse files
bjohansebasanonrig
andauthored
add items to menu nav (#108)
* add items to menu nav * fix code style * remove class * Update astro/components/SiteTitle.astro Co-authored-by: Yagiz Nizipli <[email protected]> * rename vars --------- Co-authored-by: Yagiz Nizipli <[email protected]>
1 parent 7299267 commit 983f433

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

astro.config.mts

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export default defineConfig({
6363
],
6464
},
6565
],
66+
components: {
67+
SiteTitle: './astro/components/SiteTitle.astro',
68+
},
6669
favicon: './public/favicon-32x32.png',
6770
logo: {
6871
light: './astro/assets/logo-light.svg',

astro/components/SiteTitle.astro

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
import AstrolightSiteTitle from '@astrojs/starlight/components/SiteTitle.astro'
3+
import type { Props } from '@astrojs/starlight/props'
4+
5+
const menuItems = [
6+
{ name: 'Docs', href: '/introduction' },
7+
{ name: 'Performance', href: '/performance' },
8+
{ name: 'Playground', href: '/playground' },
9+
]
10+
11+
function pathsMatch(lhs: string, rhs: string): boolean {
12+
return rhs.includes(lhs)
13+
}
14+
---
15+
16+
<div>
17+
<AstrolightSiteTitle {...Astro.props} />
18+
19+
<div class="separator"></div>
20+
21+
<div class="menu-items">
22+
{
23+
menuItems.map((menuItem) => (
24+
<a
25+
href={menuItem.href}
26+
aria-current={
27+
pathsMatch(encodeURI(menuItem.href), Astro.url.pathname) && "page"
28+
}
29+
>
30+
<span>{menuItem.name}</span>
31+
</a>
32+
))
33+
}
34+
</div>
35+
</div>
36+
37+
<style>
38+
div {
39+
display: flex;
40+
gap: var(--sl-content-pad-x);
41+
align-items: center;
42+
}
43+
44+
.separator {
45+
content: "";
46+
height: 1.5rem;
47+
border-inline-end: 1px solid var(--sl-color-gray-4);
48+
}
49+
50+
div a {
51+
text-decoration: none;
52+
color: var(--sl-color-white);
53+
font-size: var(--sl-text-base);
54+
font-weight: 500;
55+
}
56+
57+
div a:hover {
58+
text-decoration: underline;
59+
color: var(--sl-color-text-accent);
60+
}
61+
62+
[aria-current="page"],
63+
[aria-current="page"]:hover,
64+
[aria-current="page"]:focus {
65+
color: var(--sl-color-text-accent);
66+
}
67+
68+
@media (min-width: 50rem) {
69+
.menu-items {
70+
display: flex;
71+
}
72+
.separator {
73+
display: block;
74+
}
75+
}
76+
</style>

0 commit comments

Comments
 (0)