Commit 720a0ff01a

720a0ff01a5e37a5201df626e96de457943924b0

parent: c1d05f4b1b

Unsigned

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

feat: add sidebar menu toggle on homepage desktop

Adds a hamburger icon in the navbar (desktop only) that opens a
slideout sidebar with full site navigation on the homepage.

Layout: unified · split

docs/.vitepress/theme/Layout.vue +53 −1
@@ -15,7 +15,9 @@ import { usePreferredReducedMotion } from '@vueuse/core'
15import { useData, useRoute } from 'vitepress' 15import { useData, useRoute } from 'vitepress'
16import type { DefaultTheme as Theme } from 'vitepress' 16import type { DefaultTheme as Theme } from 'vitepress'
17import DefaultTheme from 'vitepress/theme' 17import DefaultTheme from 'vitepress/theme'
18import { computed, onMounted, onUnmounted, ref } from 'vue' 18import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue'
19import { getSidebarGroups } from 'vitepress/dist/client/theme-default/support/sidebar'
20import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
19import { sidebar } from '../configs/constants' 21import { sidebar } from '../configs/constants'
20import AnnouncementPill from './components/AnnouncementPill.vue' 22import AnnouncementPill from './components/AnnouncementPill.vue'
21import NotFoundComponent from './components/NotFound.vue' 23import NotFoundComponent from './components/NotFound.vue'
@@ -28,8 +30,21 @@ import { TakodachiStorageKey } from './constants'
28import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math' 30import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math'
29 31
30const route = useRoute() 32const route = useRoute()
33const { frontmatter, site, theme } = useData()
31const { Layout } = DefaultTheme 34const { Layout } = DefaultTheme
32 35
36// Home sidebar menu
37const isHome = computed(() => frontmatter.value.layout === 'home')
38const homeSidebarOpen = ref(false)
39const homeSidebarGroups = getSidebarGroups(sidebar as any)
40const logoSrc = computed(() =>
41 typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src
42)
43
44watch(() => route.path, () => {
45 homeSidebarOpen.value = false
46})
47
33interface BreadcrumbItem { 48interface BreadcrumbItem {
34 text: string 49 text: string
35 link?: string 50 link?: string
@@ -185,6 +200,30 @@ onUnmounted(() => {
185 top: `${position.y}px` 200 top: `${position.y}px`
186 }" 201 }"
187 /> 202 />
203 <!-- Home sidebar menu (desktop only) -->
204 <template v-if="isHome">
205 <Transition name="home-fade">
206 <div
207 v-if="homeSidebarOpen"
208 class="home-sidebar-backdrop"
209 @click="homeSidebarOpen = false"
210 />
211 </Transition>
212 <Transition name="home-slide">
213 <aside v-if="homeSidebarOpen" class="home-sidebar" @click.stop>
214 <div class="home-sidebar-header">
215 <a href="/" class="home-sidebar-logo">
216 <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" />
217 <span>{{ theme.siteTitle ?? site.title }}</span>
218 </a>
219 </div>
220 <nav id="VPSidebarNav" class="home-sidebar-nav">
221 <VPSidebarGroup :items="homeSidebarGroups" />
222 </nav>
223 <SidebarCard />
224 </aside>
225 </Transition>
226 </template>
188 </template> 227 </template>
189 <template #doc-before> 228 <template #doc-before>
190 <!-- Breadcrumb Navigation --> 229 <!-- Breadcrumb Navigation -->
@@ -237,5 +276,18 @@ onUnmounted(() => {
237 <template #nav-screen-content-after> 276 <template #nav-screen-content-after>
238 <NolebaseEnhancedReadabilitiesScreenMenu /> 277 <NolebaseEnhancedReadabilitiesScreenMenu />
239 </template> 278 </template>
279 <template #nav-bar-title-before>
280 <span
281 v-if="isHome"
282 class="home-menu-btn"
283 role="button"
284 tabindex="0"
285 aria-label="Menu"
286 @click.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
287 @keydown.enter.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
288 >
289 <span class="vpi-align-left home-menu-icon" />
290 </span>
291 </template>
240 </Layout> 292 </Layout>
241</template> 293</template>
docs/.vitepress/theme/styles/style.scss +105
@@ -1224,3 +1224,108 @@ table tr:nth-child(odd) {
1224.VPNavBarSearch.search { 1224.VPNavBarSearch.search {
1225 @apply ml-2 pl-0!; 1225 @apply ml-2 pl-0!;
1226} 1226}
1227
1228/* Home sidebar menu button in navbar */
1229.home-menu-btn {
1230 display: none;
1231 align-items: center;
1232 justify-content: center;
1233 margin-right: 16px;
1234 color: var(--vp-c-text-2);
1235 cursor: pointer;
1236 transition: color 0.25s;
1237
1238 &:hover {
1239 color: var(--vp-c-text-1);
1240 }
1241
1242 @media (min-width: 960px) {
1243 display: inline-flex;
1244 }
1245}
1246
1247.home-menu-icon {
1248 font-size: 20px;
1249}
1250
1251.home-sidebar-backdrop {
1252 position: fixed;
1253 inset: 0;
1254 z-index: var(--vp-z-index-backdrop, 100);
1255 background-color: rgba(0, 0, 0, 0.6);
1256}
1257
1258.home-sidebar {
1259 position: fixed;
1260 top: 0;
1261 bottom: 0;
1262 left: 0;
1263 z-index: calc(var(--vp-z-index-backdrop, 100) + 1);
1264 padding: 0 32px 96px;
1265 width: var(--vp-sidebar-width);
1266 max-width: calc(100vw - 64px);
1267 background-color: var(--vp-sidebar-bg-color);
1268 box-shadow: var(--vp-c-shadow-3);
1269 overflow-x: hidden;
1270 overflow-y: auto;
1271 overscroll-behavior: contain;
1272
1273 .dark & {
1274 box-shadow: var(--vp-shadow-1);
1275 }
1276}
1277
1278.home-sidebar-header {
1279 position: sticky;
1280 top: 0;
1281 z-index: 1;
1282 padding: 0;
1283 height: var(--vp-nav-height);
1284 display: flex;
1285 align-items: center;
1286 background-color: var(--vp-sidebar-bg-color);
1287 border-bottom: 1px solid var(--vp-c-divider);
1288}
1289
1290.home-sidebar-logo {
1291 display: flex;
1292 align-items: center;
1293 height: var(--vp-nav-height);
1294 font-size: 16px;
1295 font-weight: 600;
1296 color: var(--vp-c-text-1);
1297 text-decoration: none;
1298}
1299
1300.home-sidebar-logo-img {
1301 margin-right: 8px;
1302 height: var(--vp-nav-logo-height);
1303}
1304
1305.home-sidebar-nav {
1306 padding-top: 10px;
1307}
1308
1309.home-fade-enter-active,
1310.home-fade-leave-active {
1311 transition: opacity 0.25s;
1312}
1313
1314.home-fade-enter-from,
1315.home-fade-leave-to {
1316 opacity: 0;
1317}
1318
1319.home-slide-enter-active {
1320 transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s;
1321}
1322
1323.home-slide-leave-active {
1324 transition: transform 0.25s ease, opacity 0.5s;
1325}
1326
1327.home-slide-enter-from,
1328.home-slide-leave-to {
1329 transform: translateX(-100%);
1330 opacity: 0;
1331}