-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0b07a3
commit ec9a3a1
Showing
3 changed files
with
102 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
import type { Page } from 'src/nav'; | ||
interface Props { | ||
title: string | ||
pages: Page[] | ||
} | ||
function isSelected(href: string, currentPathname: string): boolean { | ||
if (removeLeadingSlash(href) === removeLeadingSlash(currentPathname)) { | ||
return true; | ||
} | ||
return currentPathname.startsWith(removeLeadingSlash(href) + "/"); | ||
} | ||
function removeLeadingSlash(s: string): string { | ||
if (s.endsWith("/")) { | ||
return s.split("/").slice(0, -1).join("/"); | ||
} | ||
return s; | ||
} | ||
--- | ||
|
||
<section class="text-sm"> | ||
<h2 class="mb-1 font-medium">{Astro.props.title}</h2> | ||
<ul> | ||
{Astro.props.pages.map((page) => { | ||
return ( | ||
<li class="my-1"> | ||
<a | ||
class:list={[ | ||
"hover:underline", | ||
{ | ||
"text-zinc-600": !isSelected(page[1], Astro.url.pathname), | ||
"text-main": isSelected(page[1], Astro.url.pathname) | ||
} | ||
]} | ||
href={page[1]} | ||
> | ||
{page[2] === "code" ? <code>{page[0]}</code> : page[0]} | ||
</a> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters