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) const open = ref(false)
watch(open, (value) => { watch(open, (value) => {
if (value === false) { if (!value) {
el.value!.scrollTop = 0 el.value!.scrollTop = 0
} }
}) })

@ -47,7 +47,9 @@ export function initData(route: Route): VitePressData {
lang: computed(() => site.value.lang), lang: computed(() => site.value.lang),
localePath: computed(() => { localePath: computed(() => {
const { langs, lang } = site.value 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 || '/') return withBase(path || '/')
}), }),
title: computed(() => { title: computed(() => {

@ -32,7 +32,7 @@ const isCustomLayout = computed(() => !!frontmatter.value.customLayout)
const enableHome = computed(() => !!frontmatter.value.home) const enableHome = computed(() => !!frontmatter.value.home)
// automatic multilang check for AlgoliaSearchBox // 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 // navbar
const showNavbar = computed(() => { const showNavbar = computed(() => {

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

25
types/shared.d.ts vendored

@ -11,13 +11,36 @@ export interface LocaleConfig {
export interface SiteData<ThemeConfig = any> { export interface SiteData<ThemeConfig = any> {
base: string base: string
/**
* Language of the site as it should be set on the `html` element.
* @example `en-US`, `zh-CN`
*/
lang: string lang: string
title: string title: string
description: string description: string
head: HeadConfig[] head: HeadConfig[]
themeConfig: ThemeConfig themeConfig: ThemeConfig
locales: Record<string, LocaleConfig> 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 customData: any
} }

Loading…
Cancel
Save