Commit 487f79188b

487f79188b6f815682dc3b5cec8c96faced33f69

parent: 720a0ff01a

Unsigned

TubaApollo <86665265+TubaApollo@users.noreply.github.com> · 2026-04-09 21:12 UTC

feat: add sidebar navigation on homepage (desktop + mobile)

Desktop: hamburger icon in navbar opens left slideout sidebar with
full site navigation, logo header, and arrow key scrolling.

Mobile: VitePress NavScreen restyled as floating panel with rounded
corners, blur, and slide-from-left animation. Sidebar categories
added via slot. Outside click closes the panel.

Layout: unified · split

docs/.vitepress/theme/Layout.vue +46 −4
@@ -36,6 +36,7 @@ const { Layout } = DefaultTheme
3636// Home sidebar menu
3737const isHome = computed(() => frontmatter.value.layout === 'home')
3838const homeSidebarOpen = ref(false)
39const sidebarRef = ref<HTMLElement | null>(null)
3940const homeSidebarGroups = getSidebarGroups(sidebar as any)
4041const logoSrc = computed(() =>
4142 typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src
@@ -45,6 +46,10 @@ watch(() => route.path, () => {
4546 homeSidebarOpen.value = false
4647})
4748
49function onSidebarEnter() {
50 sidebarRef.value?.focus()
51}
52
4853interface BreadcrumbItem {
4954 text: string
5055 link?: string
@@ -168,6 +173,32 @@ const reloadTakodachi = () => {
168173onMounted(() => {
169174 if (import.meta.env.SSR) return
170175
176 // Arrow key scrolling + Escape close for desktop sidebar
177 useEventListener(document, 'keydown', (e: KeyboardEvent) => {
178 if (!homeSidebarOpen.value || !sidebarRef.value) return
179 if (e.key === 'Escape') {
180 homeSidebarOpen.value = false
181 return
182 }
183 if (e.key === 'ArrowDown') {
184 e.preventDefault()
185 sidebarRef.value.scrollBy({ top: 60, behavior: 'smooth' })
186 } else if (e.key === 'ArrowUp') {
187 e.preventDefault()
188 sidebarRef.value.scrollBy({ top: -60, behavior: 'smooth' })
189 }
190 })
191
192 // Close home NavScreen on outside click
193 useEventListener(document, 'click', (e: Event) => {
194 if (!isHome.value) return
195 const screen = document.getElementById('VPNavScreen')
196 if (!screen) return
197 const hamburger = document.querySelector('.VPNavBarHamburger')
198 if (screen.contains(e.target as Node) || hamburger?.contains(e.target as Node)) return
199 requestAnimationFrame(() => (hamburger as HTMLElement)?.click())
200 })
201
171202 // Storage changed in other documents.
172203 useEventListener(window, 'storage', () => {
173204 reloadTakodachi()
@@ -200,7 +231,7 @@ onUnmounted(() => {
200231 top: `${position.y}px`
201232 }"
202233 />
203 <!-- Home sidebar menu (desktop only) -->
234 <!-- Home sidebar menu -->
204235 <template v-if="isHome">
205236 <Transition name="home-fade">
206237 <div
@@ -209,8 +240,14 @@ onUnmounted(() => {
209240 @click="homeSidebarOpen = false"
210241 />
211242 </Transition>
212 <Transition name="home-slide">
213 <aside v-if="homeSidebarOpen" class="home-sidebar" @click.stop>
243 <Transition name="home-slide" @after-enter="onSidebarEnter">
244 <aside
245 v-if="homeSidebarOpen"
246 ref="sidebarRef"
247 class="home-sidebar"
248 tabindex="-1"
249 @click.stop
250 >
214251 <div class="home-sidebar-header">
215252 <a href="/" class="home-sidebar-logo">
216253 <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" />
@@ -273,8 +310,13 @@ onUnmounted(() => {
273310 <template #nav-bar-content-after>
274311 <NolebaseEnhancedReadabilitiesMenu />
275312 </template>
313 <template #nav-screen-content-before>
314 <nav v-if="isHome" id="VPSidebarNavMobile" class="home-screen-nav">
315 <VPSidebarGroup :items="homeSidebarGroups" />
316 </nav>
317 </template>
276318 <template #nav-screen-content-after>
277 <NolebaseEnhancedReadabilitiesScreenMenu />
319 <NolebaseEnhancedReadabilitiesScreenMenu v-if="!isHome" />
278320 </template>
279321 <template #nav-bar-title-before>
280322 <span
docs/.vitepress/theme/styles/style.scss +79 −2
@@ -612,7 +612,8 @@ table tr:nth-child(odd) {
612612 }
613613}
614614
615#VPSidebarNav > .group {
615#VPSidebarNav > .group,
616#VPSidebarNavMobile > .group {
616617 @apply border-t-0 min-h-11 pt-2.25;
617618
618619 & > .VPSidebarItem {
@@ -1225,6 +1226,20 @@ table tr:nth-child(odd) {
12251226 @apply ml-2 pl-0!;
12261227}
12271228
1229%thin-scrollbar {
1230 scrollbar-width: thin;
1231 &::-webkit-scrollbar { width: 8px; }
1232 &::-webkit-scrollbar-track { background: transparent; }
1233 &::-webkit-scrollbar-thumb { border-radius: 4px; }
1234}
1235
1236%thin-scrollbar-narrow {
1237 scrollbar-width: thin;
1238 &::-webkit-scrollbar { width: 6px; }
1239 &::-webkit-scrollbar-track { background: transparent; }
1240 &::-webkit-scrollbar-thumb { border-radius: 3px; background-color: var(--vp-c-divider); }
1241}
1242
12281243/* Home sidebar menu button in navbar */
12291244.home-menu-btn {
12301245 display: none;
@@ -1255,6 +1270,7 @@ table tr:nth-child(odd) {
12551270 background-color: rgba(0, 0, 0, 0.6);
12561271}
12571272
1273/* Home desktop sidebar (left slideout) */
12581274.home-sidebar {
12591275 position: fixed;
12601276 top: 0;
@@ -1269,6 +1285,7 @@ table tr:nth-child(odd) {
12691285 overflow-x: hidden;
12701286 overflow-y: auto;
12711287 overscroll-behavior: contain;
1288 @extend %thin-scrollbar;
12721289
12731290 .dark & {
12741291 box-shadow: var(--vp-shadow-1);
@@ -1279,7 +1296,6 @@ table tr:nth-child(odd) {
12791296 position: sticky;
12801297 top: 0;
12811298 z-index: 1;
1282 padding: 0;
12831299 height: var(--vp-nav-height);
12841300 display: flex;
12851301 align-items: center;
@@ -1306,6 +1322,7 @@ table tr:nth-child(odd) {
13061322 padding-top: 10px;
13071323}
13081324
1325/* Desktop sidebar transitions */
13091326.home-fade-enter-active,
13101327.home-fade-leave-active {
13111328 transition: opacity 0.25s;
@@ -1329,3 +1346,63 @@ table tr:nth-child(odd) {
13291346 transform: translateX(-100%);
13301347 opacity: 0;
13311348}
1349
1350/* Hide navbar border when home NavScreen is open */
1351.VPNavBar.home.screen-open {
1352 border-bottom: none !important;
1353}
1354
1355/* Home NavScreen: restyle as left-aligned floating panel matching VPSidebar */
1356.VPNavScreen:has(.home-screen-nav) {
1357 @apply bg-white/85 dark:bg-neutral-800/85
1358 border dark:border-neutral-700 border-neutral-200
1359 rounded-3xl backdrop-blur shadow-lg;
1360 padding: 0 !important;
1361 left: 0.5rem !important;
1362 right: auto !important;
1363 top: 0.5rem !important;
1364 bottom: 0.5rem !important;
1365 width: calc(100vw - 64px) !important;
1366 max-width: 320px !important;
1367 overflow-x: hidden !important;
1368 @extend %thin-scrollbar-narrow;
1369
1370 & > * {
1371 max-width: 100% !important;
1372 padding: 16px 16px 0 !important;
1373 display: flex !important;
1374 flex-direction: column !important;
1375 min-height: 100%;
1376 }
1377
1378 .VPNavScreenAppearance {
1379 margin-top: 24px !important;
1380 }
1381
1382 .VPNavScreenSocialLinks {
1383 margin-top: auto !important;
1384 padding: 16px 0 !important;
1385 display: flex;
1386 justify-content: center;
1387 }
1388}
1389
1390.home-screen-nav {
1391 padding-top: 8px;
1392}
1393
1394/* Override NavScreen fade transition to slide-from-left on home */
1395.VPNavScreen:has(.home-screen-nav) {
1396 &.fade-enter-active,
1397 &.fade-leave-active {
1398 transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s !important;
1399
1400 .container { transform: none !important; }
1401 }
1402
1403 &.fade-enter-from,
1404 &.fade-leave-to {
1405 transform: translateX(-100%) !important;
1406 opacity: 0 !important;
1407 }
1408}