Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/.vuepress/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { defineClientConfig, resolvers } from 'vuepress/client';
import { watchEffect } from 'vue';
import {
defineClientConfig,
resolvers,
useSiteLocaleData,
} from 'vuepress/client';
import HomeLayout from './layouts/HomeLayout.vue';
import NotFound from './layouts/NotFound.vue';

Expand All @@ -12,9 +17,39 @@ resolvers.resolvePageHeadTitle = (page, siteLocale) => {
: resolvePageHeadTitle(page, siteLocale);
};

function textDirection(lang: string): 'ltr' | 'rtl' {
try {
const locale = new Intl.Locale(lang) as Intl.Locale & {
getTextInfo?: () => { direction: 'ltr' | 'rtl' };
textInfo?: { direction: 'ltr' | 'rtl' };
};
return (
locale.getTextInfo?.().direction ??
locale.textInfo?.direction ??
'ltr'
);
} catch {
return 'ltr';
}
}

export default defineClientConfig({
layouts: {
HomeLayout,
NotFound,
},

// Arabic and Urdu read right to left. The page's `lang` is set from the
// locale, but nothing sets `dir`, so do it here as the reader switches
// languages. It follows the locale of the address rather than the page,
// since the one 404 page is shown in every locale.
setup() {
if (__VUEPRESS_SSR__) {
return;
}
const siteLocale = useSiteLocaleData();
watchEffect(() => {
document.documentElement.dir = textDirection(siteLocale.value.lang);
});
},
});
Loading
Loading