I am trying to set up Metalsmith process in gulp. Problem is that I don't know how to set up to load metadata from arbitrary number of files of different formats (YAML or JSON) and then use them globally in pages. It works in partials and layouts.
This is my src folder structure just for static site assets:
_data/
settings.yaml
info.json
_layouts/
default.html
_partials/
menu.html
index.html
This is my latest gulp process:
'use strict';
/***********
* PLUGINS *
***********/
var gulp = require('gulp'),
metalsmith = require('gulp-metalsmith'),
markdown = require('metalsmith-markdown'),
handlebars = require('metalsmith-handlebars'),
layouts = require('metalsmith-layouts'),
ignore = require('metalsmith-ignore'),
rootPath = require('metalsmith-rootpath'),
metadata = require('metalsmith-metadata'),
runSequence = require('run-sequence').use(gulp);
// Paths (external file with all paths)
var app_paths = require('../paths.js');
gulp.task('metalsmith', function() {
return gulp.src('./src/site/**')
.pipe(metalsmith({
// Metalsmith's root directory, for example for locating templates, defaults to CWD
root: './src/site/',
// Parsing frontmatter, defaults to true
frontmatter: true,
json: true,
// Metalsmith plugins to use:
use: [
metadata({
"settings": "_data/settings.yaml",
"info": "_data/info.json"
}),
rootPath(),
markdown(),
ignore(['_layouts/**/*', '_partials/**/*', '_data/**/*']),
layouts({
engine: 'handlebars',
directory: '_layouts/',
partials: '_partials/',
default: 'default.html'
}),
]
}))
.pipe(gulp.dest(app_paths.htmlStaticOut));
});
settings.yaml has this key/value pair:
site_name: Site name
When I try to access some key in settings.yaml by using {{settings.site_name}} in page - nothing happens. I also can't access front matter data from within a page.
Anyone knows where could the problem be?