Skip to content

Commit

Permalink
feat: $lang and $localePath globals (#166) (#167)
Browse files Browse the repository at this point in the history
close #166 

Co-authored-by: Kia King Ishii <[email protected]>
  • Loading branch information
patak-dev and kiaking committed Jan 22, 2021
1 parent 417caf3 commit 481c451
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/guide/global-computed.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<title>` label used for the current page.
Expand Down
19 changes: 19 additions & 0 deletions src/client/app/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 481c451

Please sign in to comment.