@@ -245,21 +245,26 @@ pub fn Navbar(
245245 }
246246 </div>
247247 for ( label, href, _) in nav_items {
248- <a class={ {
249- let color = if * label == active_nav_label { "var(--color-primary)" } else { "var(--color-text)" } ;
250- css!(
251- color: ${ color} ;
252- text-decoration: none;
253- padding: 0.5 rem 0.75 rem;
254- font-size: 0.875 rem;
255- font-weight: 500 ;
256- display: inline-flex;
257- align-items: center;
258- gap: 0.25 rem;
259- & : hover { color: var( --color-primary) ; text-decoration: none; }
260- @media ( max-width: 700 px) { display: none; }
261- )
262- } } href={ * href} onclick={ crate :: nav_onclick( & nav_ctx, href) } >{ label} </a>
248+ {
249+ {
250+ let url = compute_nav_href( href, lang. as_str( ) , doc_version. as_str( ) ) ;
251+ let color = if * label == active_nav_label { "var(--color-primary)" } else { "var(--color-text)" } ;
252+ html! {
253+ <a class={ css!(
254+ color: ${ color} ;
255+ text-decoration: none;
256+ padding: 0.5 rem 0.75 rem;
257+ font-size: 0.875 rem;
258+ font-weight: 500 ;
259+ display: inline-flex;
260+ align-items: center;
261+ gap: 0.25 rem;
262+ & : hover { color: var( --color-primary) ; text-decoration: none; }
263+ @media ( max-width: 700 px) { display: none; }
264+ ) } href={ url. clone( ) } onclick={ crate :: nav_onclick( & nav_ctx, & url) } >{ label} </a>
265+ }
266+ }
267+ }
263268 }
264269 <a class={ css!(
265270 color: var( --color-text) ;
@@ -416,16 +421,23 @@ pub fn Navbar(
416421 -webkit-overflow-scrolling: touch;
417422 ) } >
418423 for ( label, href, _) in nav_items {
419- <a class={ css!(
420- color: var( --color-text) ;
421- text-decoration: none;
422- padding: 0.75 rem 0 ;
423- font-size: 0.875 rem;
424- font-weight: 500 ;
425- display: inline-flex;
426- align-items: center;
427- & : hover { color: var( --color-primary) ; text-decoration: none; }
428- ) } href={ * href} onclick={ crate :: nav_onclick( & nav_ctx, href) } >{ label} </a>
424+ {
425+ {
426+ let url = compute_nav_href( href, lang. as_str( ) , doc_version. as_str( ) ) ;
427+ html! {
428+ <a class={ css!(
429+ color: var( --color-text) ;
430+ text-decoration: none;
431+ padding: 0.75 rem 0 ;
432+ font-size: 0.875 rem;
433+ font-weight: 500 ;
434+ display: inline-flex;
435+ align-items: center;
436+ & : hover { color: var( --color-primary) ; text-decoration: none; }
437+ ) } href={ url. clone( ) } onclick={ crate :: nav_onclick( & nav_ctx, & url) } >{ label} </a>
438+ }
439+ }
440+ }
429441 }
430442 <a class={ css!(
431443 color: var( --color-text) ;
@@ -561,6 +573,31 @@ fn DropdownItem(href: AttrValue, active: bool, children: Html) {
561573 }
562574}
563575
576+ fn compute_nav_href ( base_href : & str , lang : & str , doc_version : & str ) -> String {
577+ let prefix = crate :: lang_prefix ( lang) ;
578+ let version_slug = VERSION_SLUGS
579+ . iter ( )
580+ . find ( |( label, _) | * label == doc_version)
581+ . map ( |( _, slug) | * slug)
582+ . unwrap_or ( "" ) ;
583+
584+ if base_href. starts_with ( "/tutorial" ) {
585+ if version_slug. is_empty ( ) {
586+ return format ! ( "{prefix}/tutorial" ) ;
587+ }
588+ return format ! ( "{prefix}/{version_slug}/tutorial" ) ;
589+ }
590+
591+ if let Some ( doc_path) = base_href. strip_prefix ( "/docs/" ) {
592+ if version_slug. is_empty ( ) {
593+ return format ! ( "{prefix}/docs/{doc_path}" ) ;
594+ }
595+ return format ! ( "{prefix}/docs/{version_slug}/{doc_path}" ) ;
596+ }
597+
598+ format ! ( "{prefix}{base_href}" )
599+ }
600+
564601fn compute_version_url (
565602 current_path : & str ,
566603 current_lang : & str ,
0 commit comments