@@ -23,7 +23,7 @@ type Props = {
2323 versions: readonly LabeledVersion [];
2424};
2525
26- const { currentPage, langCode, version, versions } = Astro .props ;
26+ const { currentPage, langCode, version = " latest " , versions } = Astro .props as Props ;
2727
2828function getSlug() {
2929 let slug = resolveSlug (langCode , currentPage , version );
@@ -41,17 +41,12 @@ const currentPageMatch = currentPage.endsWith("/")
4141 ? currentPage .slice (1 , - 1 )
4242 : currentPage .slice (1 );
4343
44- let sidebar = SITE [langCode ].sidebar ;
45- if (sidebar && typeof version === " string" ) {
46- const versionedSidebar = sidebar [version ];
47- if (! Array .isArray (versionedSidebar )) {
48- sidebar = versionedSidebar ;
49- }
50- }
44+ const site = SITE [langCode ];
45+
46+ const navbar = site ?.navbar ? site .navbar [version ] : undefined ;
47+
48+ const sidebar = (site ?.sidebar ? site .sidebar [version ] : undefined ) ?? {};
5149
52- if (! sidebar ) {
53- sidebar = {};
54- }
5550
5651const sidebarSlug =
5752 Object .keys (sidebar ).find ((sectionSlug ) => slug .startsWith (sectionSlug )) ??
@@ -94,6 +89,25 @@ function findActiveSidebarItem({
9489
9590 return undefined ;
9691}
92+
93+ const langRootUrl = new URL (` /${langCode } ` , Astro .url .href );
94+ function resolveNavUrl(link : string ) {
95+ if (link .startsWith (" http" )) {
96+ return new URL (link );
97+ }
98+
99+ const versionSegment = version === " latest" ? " " : ` /${version } ` ;
100+
101+ if (link .startsWith (" /" )) {
102+ if (link .startsWith (` /${langRootUrl } ` )) {
103+ return new URL (link , langRootUrl );
104+ }
105+
106+ return new URL (` ${langRootUrl }${versionSegment }${link } ` );
107+ }
108+
109+ return new URL (link , ` ${langRootUrl }${versionSegment } ` );
110+ }
97111---
98112
99113<aside id =" sidebar" class =" sidebar" aria-label =" Site Navigation" >
@@ -115,6 +129,23 @@ function findActiveSidebarItem({
115129 )
116130 }
117131 </div >
132+ {
133+ Array .isArray (navbar ) && navbar .length > 0 && (
134+ <nav class = " site-sections" >
135+ <ul class = " horizontal hide-on-mobile" >
136+ { navbar .map ((item ) => {
137+ return (
138+ <li >
139+ <a href = { resolveNavUrl (item .link )} >
140+ { item .title }
141+ </a >
142+ </li >
143+ );
144+ })}
145+ </ul >
146+ </nav >
147+ )
148+ }
118149 </div >
119150 <nav aria-labelledby =" sidebar" >
120151 <ul class =" nav-groups" >
@@ -390,6 +421,42 @@ function findActiveSidebarItem({
390421 background-color: var(--theme-bg-hover);
391422 }
392423
424+ nav.site-sections {
425+ border-top: 1px solid var(--theme-divider);
426+ padding: 1em 0.5em;
427+ text-align: left;
428+ width: 100%;
429+ }
430+
431+ @media (min-width: 900px) {
432+ nav.site-sections {
433+ display: none;
434+ }
435+ }
436+
437+ nav.site-sections ul {
438+ display: flex;
439+ flex-direction: row;
440+ flex-wrap: wrap;
441+ }
442+
443+ nav.site-sections li {
444+ padding: 0.5em 0em;
445+ }
446+
447+ nav.site-sections a {
448+ color: var(--theme-text);
449+ font-size: 1.25em;
450+ font-weight: 500;
451+ text-decoration: none;
452+ }
453+
454+ nav.site-sections a:hover,
455+ nav.site-sections a:focus {
456+ color: var(--theme-text-accent);
457+ text-decoration: none;
458+ }
459+
393460 @media (max-width: 1280px) {
394461 .menu-toggle {
395462 display: initial;
@@ -411,6 +478,7 @@ function findActiveSidebarItem({
411478 right: 0;
412479 top: var(--header-height);
413480 width: 100vw;
481+ z-index: 1;
414482 }
415483</style >
416484
0 commit comments