Skip to content

Commit

Permalink
fix: fix local search and optimize version display (GreptimeTeam#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aganivi authored Oct 12, 2023
1 parent 575e7ff commit 94abccf
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
4 changes: 0 additions & 4 deletions docs/.vitepress/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export const common = async () => {
lastUpdated: true,
ignoreDeadLinks: false,
head: [['script', { src: 'https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/icons_19361_134.ede7dfbb02f3e5cba425f4d574d089ba.js' }]],
locales: {
zh: { label: '简体中文', lang: 'zh-CN', link: 'https://docs.greptime.cn/' },
en: { label: 'English', lang: 'en-US', link: 'https://docs.greptime.com/' },
},
markdown: {
theme: { light: 'material-theme-darker', dark: 'material-theme-darker' },
},
Expand Down
56 changes: 26 additions & 30 deletions docs/.vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@
Layout
</template>
<script setup name="Layout" lang="ts">
import Layout from 'vitepress/dist/client/theme-default/Layout.vue'
import { useRouter } from 'vitepress'
import { getSidebarIcon, setVersionOnPage } from '@/utils.ts'
import Layout from 'vitepress/dist/client/theme-default/Layout.vue'
import { useRouter } from 'vitepress'
import { getSidebarIcon, setVersionOnPage } from '@/utils.ts'
// data
const { theme } = useData()
const { latestVersion, iconMap } = theme.value
// methods
// lifecycle
const router = useRouter()
const currentVersion = ref(latestVersion)
// data
const { theme } = useData()
const { latestVersion, iconMap, sidebar } = theme.value
// methods
// lifecycle
const router = useRouter()
router.onBeforePageLoad = to => {
const pre = to
let res = to.replace(`/v0.4`, '')
if (pre !== res) router.go(res)
setVersionOnPage(to, currentVersion)
router.onBeforePageLoad = to => {
setVersionOnPage(to, latestVersion, sidebar)
}
onBeforeMount(async () => {
const body = document.querySelector('body')
body.style.display = 'none'
const router = useRouter()
let path = router.route.path
if (path.includes(latestVersion)) {
const res = path.replace(`/${latestVersion}`, '')
await router.go(res)
}
onBeforeMount(async () => {
const body = document.querySelector('body')
body.style.display = 'none'
const router = useRouter()
let path = router.route.path
if (path.includes(latestVersion)) {
const res = path.replace(`/${latestVersion}`, '')
await router.go(path)
}
body.style.display = 'block'
})
onMounted(async () => {
setVersionOnPage(router.route.path, currentVersion)
getSidebarIcon(iconMap)
})
body.style.display = 'block'
})
onMounted(async () => {
setVersionOnPage(router.route.path, latestVersion, sidebar)
getSidebarIcon(iconMap)
})
</script>
3 changes: 3 additions & 0 deletions docs/.vitepress/theme/style/custom.styl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
color var(--color-dark-text)
.VPNavBarMenu .VPFlyout
.text
text-transform capitalize
font-size var(--font-size-m)
line-height var(--line-height-m)
color var(--color-dark-text)
&.active .text
&.active:hover .text
Expand Down
13 changes: 10 additions & 3 deletions docs/.vitepress/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ export function getSidebarIcon(iconMap) {
})
}

export function setVersionOnPage(path, currentVersion) {
currentVersion.value = path.includes('/v0.3/') ? 'V0.3' : 'V0.4'
export function setVersionOnPage(path, latestVersion, sidebar) {
const allVersions = getAllVersions(sidebar, latestVersion)
const version = allVersions.find(version => path.includes(version)) || latestVersion
const div = document.querySelector('.VPNavBarMenuGroup')
const targetElement = <HTMLInputElement>div.childNodes[0].childNodes[0].childNodes[1]
targetElement.innerText = currentVersion.value
targetElement.innerText = version
}

export const getAllVersions = (sidebar, latestVersion) =>
Object.keys(sidebar).map(v => {
if (v === '/') return latestVersion
return v.replace(new RegExp(/\//g), '')
})
6 changes: 3 additions & 3 deletions docs/en/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const enConfig = async () => ({
['meta', { name: 'msvalidate.01', content: 'BD813946F80D5B50E162932BF3FD0D49' }],
],
locales: {
root: { label: 'English' },
root: { label: 'English', lang: 'en-US', link: 'https://docs.greptime.com/' },
zh: { label: '简体中文', lang: 'zh-CN', link: 'https://docs.greptime.cn/' },
},
themeConfig: {
nav: [
Expand All @@ -36,8 +37,7 @@ export const enConfig = async () => ({
link: 'https://greptime.com/blogs',
},
{
// TODO change version
text: 'All Versions',
text: `${LATEST_VERSION}`,
items: [
{
text: `${LATEST_VERSION}(latest)`,
Expand Down
5 changes: 3 additions & 2 deletions docs/zh/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const zhConfig = async () => ({
['meta', { name: 'msvalidate.01', content: 'BD813946F80D5B50E162932BF3FD0D49' }],
],
locales: {
root: { label: '简体中文', lang: 'zh-CN' },
root: { label: '简体中文', lang: 'zh-CN', link: 'https://docs.greptime.cn/' },
en: { label: 'English', lang: 'en-US', link: 'https://docs.greptime.com/' },
},
themeConfig: {
search: {
Expand Down Expand Up @@ -59,7 +60,7 @@ export const zhConfig = async () => ({
link: 'https://greptime.com/blogs',
},
{
text: '历史版本',
text: `${LATEST_VERSION}`,
items: [
{
text: `${LATEST_VERSION}(最新)`,
Expand Down

0 comments on commit 94abccf

Please sign in to comment.