fix(client): add computed dir and lang to html root

instead of accessing raw siteData.lang/dir

fixes https://github.com/vuejs/vitepress/pull/3353#issuecomment-1874753809
pull/3404/head
Divyansh Singh 12 months ago
parent a6cd891d95
commit c2b4c66e79

@ -44,8 +44,8 @@ export interface VitePressData<T = any> {
title: Ref<string>
description: Ref<string>
lang: Ref<string>
isDark: Ref<boolean>
dir: Ref<string>
isDark: Ref<boolean>
localeIndex: Ref<string>
}

@ -38,13 +38,13 @@ const Theme = resolveThemeExtends(RawTheme)
const VitePressApp = defineComponent({
name: 'VitePressApp',
setup() {
const { site } = useData()
const { site, lang, dir } = useData()
// change the language on the HTML element based on the current lang
onMounted(() => {
watchEffect(() => {
document.documentElement.lang = site.value.lang
document.documentElement.dir = site.value.dir
document.documentElement.lang = lang.value
document.documentElement.dir = dir.value
})
})

@ -152,8 +152,10 @@ export async function renderPage(
}
}
const dir = pageData.frontmatter.dir || siteData.dir || 'ltr'
const html = `<!DOCTYPE html>
<html lang="${siteData.lang}" dir="${siteData.dir}">
<html lang="${siteData.lang}" dir="${dir}">
<head>
<meta charset="utf-8">
${

Loading…
Cancel
Save