Metalsmith plugin to include JSON models into files and expose the data as metadata on the file object.
npm install --save metalsmith-models
In metalsmith.json
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-models": {
"directory": "models"
},
}
}
var Metalsmith = require('metalsmith');
var models = require('metalsmith-models');
var metalsmith = new Metalsmith(__dirname)
.use(models({
directory: "models"
}));
Type: String
Default value: models
Source directory of all JSON files.
JSON file can be loaded into the files using YAML front matter as below:
{
"key1": "value 1",
"key2": "value 2"
}
---
model: data_file
---
Where data_file is the name of the JSON file that is placed under the models directory (See CLI Usage or API section).
The path of the JSON files is always relative to the root directory (Ex: models).
In case of pages using handlebars:
{{model.key1}}
If you need to load multiple JSON files in a page, use below format:
---
model:
obj1: data_file1
obj2: data_file2
---
In case of pages using handlebars:
{{model.obj1.key1}}
{{model.obj2.key1}}