Skip to content

Commit

Permalink
docs: Show React tab on first visit
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Jun 23, 2024
1 parent c2a833b commit 62c52b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/.vitepress/theme/frameworksTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const localStorageKey = 'vitepress:tabsSharedState'
const ls = typeof localStorage !== 'undefined' ? localStorage : null

const getLocalStorageValue = (): Record<string, string> => {
const rawValue = ls?.getItem(localStorageKey)
if (rawValue) {
try {
return JSON.parse(rawValue)
} catch {}
}
return {}
}

const setLocalStorageValue = (v: Record<string, string>) => {
if (!ls) return
ls.setItem(localStorageKey, JSON.stringify(v))
}

export const setupFrameworksTabs = () => {
const v = getLocalStorageValue()
if (!v.frameworks) {
setLocalStorageValue({"frameworks":"React"})
}
}
4 changes: 4 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { h } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
import { setupFrameworksTabs } from './frameworksTabs'
import './style.css'

export default {
Expand All @@ -14,5 +15,8 @@ export default {
},
enhanceApp({ app, router, siteData }) {
enhanceAppWithTabs(app)
},
setup() {
setupFrameworksTabs()
}
} satisfies Theme

0 comments on commit 62c52b9

Please sign in to comment.