gitbook-plugin-variables
v1.1.0
Published
Load variables from files and use them in your GitBook templates
Downloads
45
Maintainers
Readme
GitBook Variables Plugin
Load variables from files and use them in your GitBook templates.
Requirements
Usage
Add the plugin to your book.json
file:
{
"plugins": [ "variables" ],
"pluginsConfig": {
"variables": {
"files": {
"myVariable": "data.json"
}
}
}
}
This will load the data.json
file in your book's directory and make its contents available as the myVariable
variable.
You may then use it in your Markdown, for example like this:
The file `data.json` contains: {{ book.myVariable }}
Configuration
The following options are available under your book.json
file's pluginsConfig.variables
section.
files
An object where each key is a variable to add to your book, and the corresponding value is a file path or an array of file paths to load into that variable.
This configuration loads the contents of 2 files into variables a
and b
:
{
"plugins": [ "variables" ],
"pluginsConfig": {
"variables": {
"files": {
"a": "data/a/some.json",
"b": "data/b/c/some.yml"
}
}
}
}
Multiple files may be loaded into the same variable:
{
"plugins": [ "variables" ],
"pluginsConfig": {
"variables": {
"files": {
"a": [ "data/a/some.json", "data/b/c/some.yml" ]
}
}
}
}
- Successive files representing arrays are concatenated in order (e.g.
["foo"]
and["bar"]
becomes["foo","bar"]
). - Successive files representing objects are merged in order. (e.g.
{"foo":"bar"}
and{"foo":"qux","bar":"baz"}
becomes{"foo":"qux","bar":"baz"}
). - Other or differing successive types simply replace the previous value (e.g.
["foo"]
and{"foo":"bar"}
becomes{"foo":"bar"}
).