refactor: better names and docs

pull/353/head
Eduardo San Martin Morote 4 years ago
parent db70f073e8
commit bc685d1d77

@ -7,7 +7,7 @@ const el = ref<HTMLElement | null>(null)
const open = ref(false)
watch(open, (value) => {
if (value === false) {
if (!value) {
el.value!.scrollTop = 0
}
})

@ -47,7 +47,9 @@ export function initData(route: Route): VitePressData {
lang: computed(() => site.value.lang),
localePath: computed(() => {
const { langs, lang } = site.value
const path = Object.keys(langs).find((lp) => langs[lp].lang === lang)
const path = Object.keys(langs).find(
(langPath) => langs[langPath].lang === lang
)
return withBase(path || '/')
}),
title: computed(() => {

@ -32,7 +32,7 @@ const isCustomLayout = computed(() => !!frontmatter.value.customLayout)
const enableHome = computed(() => !!frontmatter.value.home)
// automatic multilang check for AlgoliaSearchBox
const isMultiLang = computed(() => Object.keys(site.value.langs).length > 0)
const isMultiLang = computed(() => Object.keys(site.value.langs).length > 1)
// navbar
const showNavbar = computed(() => {

@ -9,6 +9,7 @@ export function useLanguageLinks() {
const langs = site.value.langs
const localePaths = Object.keys(langs)
// one language
if (localePaths.length < 2) {
return null
}
@ -18,9 +19,9 @@ export function useLanguageLinks() {
// intentionally remove the leading slash because each locale has one
const currentPath = route.path.replace(localePath.value, '')
const candidates = localePaths.map((v) => ({
text: langs[v].label,
link: `${v}${currentPath}`
const candidates = localePaths.map((localePath) => ({
text: langs[localePath].label,
link: `${localePath}${currentPath}`
}))
const selectText = theme.value.selectText || 'Languages'

25
types/shared.d.ts vendored

@ -11,13 +11,36 @@ export interface LocaleConfig {
export interface SiteData<ThemeConfig = any> {
base: string
/**
* Language of the site as it should be set on the `html` element.
* @example `en-US`, `zh-CN`
*/
lang: string
title: string
description: string
head: HeadConfig[]
themeConfig: ThemeConfig
locales: Record<string, LocaleConfig>
langs: Record<string, { lang: string; label: string }>
/**
* Available locales for the site when it has defined `locales` in its
* `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
* `/zh/`.
*/
langs: Record<
string,
{
/**
* Lang attribute as set on the `<html>` element.
* @example `en-US`, `zh-CN`
*/
lang: string
/**
* Label to display in the language menu.
* @example `English', ``
*/
label: string
}
>
customData: any
}

Loading…
Cancel
Save