From 481c4513d78450951add6177824b7996b89ae034 Mon Sep 17 00:00:00 2001 From: Matias Capeletto Date: Fri, 22 Jan 2021 15:47:08 +0100 Subject: [PATCH] feat: $lang and $localePath globals (#166) (#167) close #166 Co-authored-by: Kia King Ishii --- docs/guide/global-computed.md | 8 ++++++++ src/client/app/mixin.ts | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/docs/guide/global-computed.md b/docs/guide/global-computed.md index d1c0d3f119ad..384d0e3889e5 100644 --- a/docs/guide/global-computed.md +++ b/docs/guide/global-computed.md @@ -64,6 +64,14 @@ Reference of `$page.frontmatter`. } ``` +## $lang + +The language of the current page. Default: `en-US`. + +## $localePath + +The locale path prefix for the current page. Default: `/`. + ## $title Value of the `` label used for the current page. diff --git a/src/client/app/mixin.ts b/src/client/app/mixin.ts index 24841ce842e3..061c046a307f 100644 --- a/src/client/app/mixin.ts +++ b/src/client/app/mixin.ts @@ -42,6 +42,25 @@ export function mixinGlobalComputed( } }, + $lang: { + get() { + return siteByRoute.value.lang + } + }, + + $localePath: { + get() { + const { locales } = site.value + const { lang } = siteByRoute.value + + const path = Object.keys(locales).find( + (lp) => locales[lp].lang === lang + ) + + return (locales && path) || '/' + } + }, + $title: { get() { return page.value.title