11import "../styles/components/Navigation.scss" ;
22
33import { useEffect , useState , type ReactElement } from "react" ;
4-
54import { useTranslations } from "../i18n/utils" ;
65import { defaultLang } from "../i18n/ui" ;
6+
77import ToggleThemeButton from "./ToggleThemeButton" ;
88import LanguageSelector from "./LanguageSelector" ;
9- import { AstroJSX } from "astro/jsx-runtime" ;
9+
1010
1111interface Props {
1212 lang ?: string ;
@@ -63,6 +63,7 @@ export default function(props: Props): ReactElement {
6363 window . addEventListener ( "scroll" , handleScroll ) ;
6464 } ) ;
6565
66+
6667 return < div className = "navigation-bar" >
6768 < nav className = { `navigation ${ scrolled ? "scrolled" : "" } ` } id = "navbar"
6869 aria-label = "Navigation Bar" onScroll = { ( ) => {
@@ -75,25 +76,34 @@ export default function(props: Props): ReactElement {
7576 } } >
7677
7778 < div className = "left-side" > {
78- showProfilePic ?
79- < a rel = "author" href = "https://github.com/retrozinndev" >
80- < img className = "profile-pic"
81- src = "https://1.gravatar.com/avatar/093b64d2016ab8acce8a2fe73cb719f527790d4ecec7f5837db8d46519b38bf8?size=80"
82- width = { 32 } height = { 32 } alt = { tr ( "nav.home" ) } loading = "lazy" />
83- </ a >
84- : null
79+ showProfilePic ? < a rel = "author" href = "https://github.com/retrozinndev" >
80+ < img className = "profile-pic"
81+ src = "https://1.gravatar.com/avatar/093b64d2016ab8acce8a2fe73cb719f527790d4ecec7f5837db8d46519b38bf8?size=80"
82+ width = { 32 } height = { 32 } alt = { tr ( "nav.home" ) } loading = "lazy"
83+ />
84+ </ a > : null
8585 } </ div >
8686
8787 < div className = "items" > {
88- pages . map ( ( page , i ) => (
89- < div className = "item" key = { i } >
90- < a href = { `${ page . hasI18n ? `/${ lang } ` : "" } ${ page . href } ` }
91- target = "_self" title = { tr ( `nav.${ page . name } _tooltip` ) } > {
92-
88+ pages . map ( ( page , i ) =>
89+ < div className = { `item` } key = { i } onLoadStart = { e => {
90+ const currentPage = ( page . hasI18n ?
91+ window . location . pathname . replace ( / ^ \/ .* ( \/ ) / , "/" )
92+ : window . location . pathname ) . trimEnd ( ) . replace ( / \/ $ / , "" ) . concat (
93+ window . location . hash . startsWith ( '#' ) ?
94+ window . location . hash
95+ : window . location . hash . replace ( / ^ ./ , "\#&" )
96+ ) . trim ( ) ;
97+
98+ if ( currentPage === page . href . toString ( ) )
99+ ( e . target as HTMLDivElement ) . classList . add ( "current" ) ;
100+ } } >
101+ < a href = { `${ page . hasI18n ? `/${ lang } ` : "" } ${ page . href } ` } target = "_self"
102+ title = { tr ( `nav.${ page . name } _tooltip` ) } > {
93103 tr ( `nav.${ page . name } ` )
94104 } </ a >
95105 </ div >
96- ) )
106+ )
97107 }
98108
99109 < div className = "item" key = { pages . length } >
0 commit comments