https://github.com/polo2ro/hexo-helper-page-languages
Get available languages for one page
https://github.com/polo2ro/hexo-helper-page-languages
Last synced: 6 months ago
JSON representation
Get available languages for one page
- Host: GitHub
- URL: https://github.com/polo2ro/hexo-helper-page-languages
- Owner: polo2ro
- License: mit
- Created: 2016-10-29T13:22:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-01T14:39:04.000Z (over 9 years ago)
- Last Synced: 2025-10-20T08:02:57.334Z (9 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-helper-page-languages
Get available languages as links on one page
## Install
Install using [npm](https://www.npmjs.com/).
```bash
$ npm install hexo-helper-page-languages --save
```
## Usage
### In your front-matter.
The default language, in /en/docs/hello.md:
```yaml
title: Hello World
lang: en
contentId: hello-word
```
A translated version file, if /fr/docs/bonjour.md:
```yaml
title: Bonjour le monde
lang: fr
contentId: hello-word
```
If contentId is not provided, the full path except language will be used as value. The contentId variable is really usefull only if your file names are translated.
This can come handy if you care about SEO.
This other example can work because of the same file names.
The default language, in /en/docs/intro.md:
```yaml
title: Introduction
lang: en
```
A translated version file, if /fr/docs/intro.md:
```yaml
title: Bonjour le monde
lang: fr
```
### in your ejs templates
List all pages for the same contentId.
```html
- <%= __('docs.otherlang') %>
- <%= versions[i].label %>
<% var versions = getPageLanguages();
for (var i=0; i
<% } %>
```
getPageLanguages return an array of objects, with:
* url: full path url, example `/fr/docs/bonjour.html`
* label: two letter code for the language, like `fr`