https://github.com/alphahydrae/gitbook-plugin-variables
Load variables from files and use them in your GitBook templates
https://github.com/alphahydrae/gitbook-plugin-variables
Last synced: 15 days ago
JSON representation
Load variables from files and use them in your GitBook templates
- Host: GitHub
- URL: https://github.com/alphahydrae/gitbook-plugin-variables
- Owner: AlphaHydrae
- License: mit
- Created: 2018-07-22T08:56:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-26T15:45:18.000Z (over 7 years ago)
- Last Synced: 2025-02-22T18:48:09.079Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 240 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# GitBook Variables Plugin
> Load variables from files and use them in your [GitBook](https://www.gitbook.com) templates.
[](https://badge.fury.io/js/gitbook-plugin-variables)
[](https://travis-ci.org/AlphaHydrae/gitbook-plugin-variables)
[](LICENSE.txt)
- [Requirements](#requirements)
- [Usage](#usage)
- [Configuration](#configuration)
- [`files`](#files)
## Requirements
* [GitBook](https://www.gitbook.com) 3+
* [Node.js](https://nodejs.org) 8+
## Usage
Add the plugin to your `book.json` file:
```json
{
"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:
```md
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`:
```json
{
"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:
```json
{
"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"}`).