Skip to content

Commit d801031

Browse files
committed
README
1 parent 2d05ca1 commit d801031

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ infrastructure for [mdbook](https://github.com/rust-lang/mdBook/):
1010

1111
- [mdbook-i18n-helpers](./i18n-helpers/README.md): Gettext translation support
1212
for [mdbook](https://github.com/rust-lang/mdBook/)
13+
- [mdbook-tera-backend](./mdbook-tera-backend/README.md): Tera templates extension
14+
for [mdbook](https://github.com/rust-lang/mdBook/)'s HTML renderer.
1315

1416
## Showcases
1517

@@ -39,9 +41,13 @@ $ cargo install mdbook-i18n-helpers
3941
Please see [USAGE](./i18n-helpers/USAGE.md) for how to translate your
4042
[mdbook](https://github.com/rust-lang/mdBook/) project.
4143

42-
## Changelog
44+
### `mdbook-tera-backend`
4345

44-
Please see [CHANGELOG](CHANGELOG.md) for details on the changes in each release.
46+
Run
47+
48+
```shell
49+
$ cargo install mdbook-tera-backend
50+
```
4551

4652
## Contact
4753

mdbook-tera-backend/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [Tera](https://github.com/Keats/tera) backend extension for `mdbook`'s HTML backend
2+
3+
[![Visit crates.io](https://img.shields.io/crates/v/mdbook-i18n-helpers?style=flat-square)](https://crates.io/crates/mdbook-tera-backend)
4+
[![Build workflow](https://img.shields.io/github/actions/workflow/status/google/mdbook-i18n-helpers/test.yml?style=flat-square)](https://github.com/google/mdbook-i18n-helpers/actions/workflows/test.yml?query=branch%3Amain)
5+
[![GitHub contributors](https://img.shields.io/github/contributors/google/mdbook-i18n-helpers?style=flat-square)](https://github.com/google/mdbook-i18n-helpers/graphs/contributors)
6+
[![GitHub stars](https://img.shields.io/github/stars/google/mdbook-i18n-helpers?style=flat-square)](https://github.com/google/mdbook-i18n-helpers/stargazers)
7+
8+
This `mdbook` backend makes it possible to use [tera](https://github.com/Keats/tera)
9+
templates and expand the capabilities of your books. It works on top of the default HTML
10+
backend.
11+
12+
## Installation
13+
14+
Run
15+
16+
```shell
17+
$ cargo install mdbook-tera-backend
18+
```
19+
20+
## Usage
21+
22+
### Configuring the backend
23+
24+
To enable the backend, simply add `[output.tera-backend]` to your `book.toml`,
25+
and configure the place where youre templates will live.
26+
For instance `theme/templates`:
27+
28+
```toml
29+
...
30+
31+
[output.tera-backend]
32+
templates_dir = "theme/templates"
33+
34+
...
35+
```
36+
37+
### Creating templates
38+
39+
Create your template files in the same directory as your book.
40+
41+
```html
42+
<!-- ./theme/templates/language_list.html -->
43+
<ul>
44+
{% for identifier, language_name in get_context(key="output.i18n.languages") %}
45+
<li>{{ identifier }}: {{ language_name }}</li>
46+
{% endfor %}
47+
</ul>
48+
```
49+
50+
### Using templates in `index.hbs`
51+
52+
Since the HTML renderer will first render Handlebars templates, we need to tell it to
53+
ignore tera templates using `{{{{raw}}}}` blocks:
54+
55+
```html
56+
{{{{raw}}}}
57+
{% set current_language = ctx | get(key="config") | get(key="book") | get(key="language", default="en") %}
58+
<p>CURRENT LANGUAGE: {{ current_language }}</p>
59+
<p>All languages: {% include "language_list.html" %}</p>
60+
{{{{/raw}}}}
61+
```
62+
63+
Includes names are based on the file name and not the whole file path.
64+
65+
### Tera documentation
66+
67+
Find out all you can do with Tera templates [here](https://keats.github.io/tera/docs/).
68+
69+
## Changelog
70+
71+
Please see [CHANGELOG](../CHANGELOG.md) for details on the changes in each
72+
release.
73+
74+
## Contact
75+
76+
For questions or comments, please contact
77+
[Martin Geisler](mailto:[email protected]) or
78+
[Alexandre Senges](mailto:[email protected]) or start a
79+
[discussion](https://github.com/google/mdbook-i18n-helpers/discussions). We
80+
would love to hear from you.
81+
82+
---
83+
84+
This is not an officially supported Google product.

0 commit comments

Comments
 (0)