Skip to content

Commit

Permalink
fix: switch language error
Browse files Browse the repository at this point in the history
  • Loading branch information
zuofenghua committed Oct 23, 2020
1 parent 392947f commit c55d125
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vlib-docsify",
"version": "0.2.0",
"version": "0.3.0",
"description": "",
"main": "dist/node/index.js",
"typings": "types/index.d.ts",
Expand Down
18 changes: 14 additions & 4 deletions src/client/theme-default/components/NavBarLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSiteData, useSiteDataByRoute, useRoute } from 'vitepress'
import NavBarLink from './NavBarLink.vue'
import NavDropdownLink from './NavDropdownLink.vue'
import { DefaultTheme } from '../config'
import { inBrowser } from '/@app/utils'

const platforms = ['GitHub', 'GitLab', 'Bitbucket'].map(
(platform) => [platform, new RegExp(platform, 'i')] as const
Expand Down Expand Up @@ -52,21 +53,30 @@ export default {
return null
}

// index.html
const base = siteData.value.base.endsWith('/')
? siteData.value.base.slice(0, -1)
: siteData.value.base

// inBrowser router
const routerPath = inBrowser ? route.path.slice(base.length) : route.path

const currentLangBase = localeKeys.find((v) => {
if (v === '/') {
return false
}
return route.path.startsWith(v)
return routerPath.startsWith(v)
})
const currentContentPath = currentLangBase
? route.path.substring(currentLangBase.length - 1)
: route.path
? routerPath.substring(currentLangBase.length - 1)
: routerPath
const candidates = localeKeys.map((v) => {
return {
text: locales[v].label || locales[v].lang,
link: `${v}${currentContentPath}`
link: `${v.slice(0, -1)}${currentContentPath}`
}
})
console.log(candidates)

const currentLangKey = currentLangBase ? currentLangBase : '/'
const selectText = locales[currentLangKey].selectText
Expand Down
2 changes: 2 additions & 0 deletions src/node/build/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export async function renderPage(
const virtualPage = localeFile(langToPrefix, resolveAlias(page, userAlias))
const routePath = `/${virtualPage.replace(/\.md$/, '')}`
const siteData = resolveSiteDataByRoute(config.site, routePath)
// const base = config.site.base.slice(0, -1)
console.log('go -> ' + routePath)
router.go(routePath)
// lazy require server-renderer for production build
const content = await require('@vue/server-renderer').renderToString(app)
Expand Down

0 comments on commit c55d125

Please sign in to comment.