Skip to content

Commit

Permalink
leverage new heading sidebar config in the vuepress default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nruffing committed Mar 9, 2024
1 parent ae7a80a commit 5278d38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
36 changes: 4 additions & 32 deletions vuepress/.vuepress/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import LandingFeature from './components/LandingFeature.vue'
import DEMO from '../demo-data/DEMO_DATA'
import constants from './constants'
import Layout from './layouts/Layout.vue'
import { useThemeLocaleData } from '../node_modules/@vuepress/theme-default/lib/client'
import { useRouter } from 'vue-router'
import { ApplicationInsights } from '@microsoft/applicationinsights-web'

let sideBarCache: any = false

const appInsights = new ApplicationInsights({
config: {
connectionString:
Expand All @@ -24,6 +20,10 @@ appInsights.addTelemetryInitializer(envelope => {
envelope.data['userAgent'] = navigator.userAgent
envelope.data['language'] = navigator.language
envelope.data['referrer'] = document.referrer
envelope.data['screenHeight'] = window?.screen?.height
envelope.data['screenWidth'] = window?.screen?.width
envelope.data['windowInnerHeight'] = window?.innerHeight
envelope.data['windowInnerWidth'] = window?.innerWidth
})

export default defineClientConfig({
Expand Down Expand Up @@ -56,34 +56,6 @@ export default defineClientConfig({
return savedPosition || { top: 0 }
}
},
setup() {
const themeLocale = useThemeLocaleData()
const router = useRouter()

function isAutoSidebar(route): boolean {
return route.fullPath?.startsWith('/generated/') || route.fullPath?.startsWith('/dotnet-generated/')
}

function flipToAutoSidebar() {
sideBarCache = themeLocale.value.sidebar
themeLocale.value.sidebar = 'auto'
}

if (isAutoSidebar(router.currentRoute.value)) {
flipToAutoSidebar()
}

router.beforeEach((to, from) => {
const toIsAuto = isAutoSidebar(to)
const fromIsAuto = isAutoSidebar(from)
if (toIsAuto && !fromIsAuto) {
flipToAutoSidebar()
} else if (!toIsAuto && fromIsAuto) {
themeLocale.value.sidebar = sideBarCache
sideBarCache = false
}
})
},
layouts: {
Layout,
},
Expand Down
12 changes: 2 additions & 10 deletions vuepress/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,8 @@ export default defineUserConfig({
],
},
],
'/generated/': [
{
text: 'API',
},
],
'/dotnet-generated/': [
{
text: '.NET',
},
],
'/generated/': 'heading',
'/dotnet-generated/': 'heading',
},
sidebarDepth: 2,
}),
Expand Down

0 comments on commit 5278d38

Please sign in to comment.