feat: $lang and $localePath globals

pull/167/head
Matias Capeletto 5 years ago
parent 1b6981a915
commit e4fe64c5a6

@ -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 ## $title
Value of the `<title>` label used for the current page. Value of the `<title>` label used for the current page.
@ -77,5 +85,5 @@ The content value of the `<meta name= "description" content= "...">` for the cur
Helper method to generate correct path by prepending the `base` path configured in `.vitepress/config.js`. It's useful when you want to link to [public files with base path](./assets#public-files). Helper method to generate correct path by prepending the `base` path configured in `.vitepress/config.js`. It's useful when you want to link to [public files with base path](./assets#public-files).
```html ```html
<img :src="$withBase('/foo.png')" alt="foo"> <img :src="$withBase('/foo.png')" alt="foo" />
``` ```

@ -56,6 +56,24 @@ export function mixinGlobalComputed(
} }
}, },
$lang: {
get() {
return siteByRoute.value.lang
}
},
$localePath: {
get() {
const { locales } = site.value
const { lang } = siteByRoute.value
return (
(locales &&
Object.keys(locales).find((lp) => locales[lp].lang === lang)) ||
'/'
)
}
},
$withBase: { $withBase: {
value(path: string) { value(path: string) {
return joinPath(site.value.base, path) return joinPath(site.value.base, path)

Loading…
Cancel
Save