Skip to content

Commit

Permalink
add items to menu nav (#108)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bjohansebas and anonrig authored Aug 20, 2024
1 parent 7299267 commit 983f433
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default defineConfig({
],
},
],
components: {
SiteTitle: './astro/components/SiteTitle.astro',
},
favicon: './public/favicon-32x32.png',
logo: {
light: './astro/assets/logo-light.svg',
Expand Down
76 changes: 76 additions & 0 deletions astro/components/SiteTitle.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
import AstrolightSiteTitle from '@astrojs/starlight/components/SiteTitle.astro'
import type { Props } from '@astrojs/starlight/props'
const menuItems = [
{ name: 'Docs', href: '/introduction' },
{ name: 'Performance', href: '/performance' },
{ name: 'Playground', href: '/playground' },
]
function pathsMatch(lhs: string, rhs: string): boolean {
return rhs.includes(lhs)
}
---

<div>
<AstrolightSiteTitle {...Astro.props} />

<div class="separator"></div>

<div class="menu-items">
{
menuItems.map((menuItem) => (
<a
href={menuItem.href}
aria-current={
pathsMatch(encodeURI(menuItem.href), Astro.url.pathname) && "page"
}
>
<span>{menuItem.name}</span>
</a>
))
}
</div>
</div>

<style>
div {
display: flex;
gap: var(--sl-content-pad-x);
align-items: center;
}

.separator {
content: "";
height: 1.5rem;
border-inline-end: 1px solid var(--sl-color-gray-4);
}

div a {
text-decoration: none;
color: var(--sl-color-white);
font-size: var(--sl-text-base);
font-weight: 500;
}

div a:hover {
text-decoration: underline;
color: var(--sl-color-text-accent);
}

[aria-current="page"],
[aria-current="page"]:hover,
[aria-current="page"]:focus {
color: var(--sl-color-text-accent);
}

@media (min-width: 50rem) {
.menu-items {
display: flex;
}
.separator {
display: block;
}
}
</style>

0 comments on commit 983f433

Please sign in to comment.