-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.js
46 lines (37 loc) · 1.1 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var fs = require('fs');
var path = require('path');
var utils = require('./utils');
/**
* Site data
*/
module.exports = function(app) {
if (utils.isRegistered(app, 'hekyll-data')) return;
var paths = app.paths;
var pkgPath = path.resolve(require.resolve('assemble'), '../package.json');
app.dataLoader('yml', function(buf, file) {
var data = utils.yaml.safeLoad(buf);
var name = path.basename(file);
if (name === '_config.yml') {
data.baseurl = data.baseurl || './';
if (data.baseurl === '/') {
data.baseurl = './';
}
}
return data;
});
/**
* Data for rendering templates
*/
app.data('assemble', JSON.parse(fs.readFileSync(pkgPath)));
app.data('site.github.repo', utils.repo.https(app.pkg.data));
app.data(paths.src('*_config.yml'), {namespace: 'site'});
app.data(paths.src('_data/*.{yml,yaml,json,csv}'), {namespace: 'site'});
/**
* Expose path variables on data
*/
app.data('site.assets', paths.assets());
app.data('site.dest', paths.dest());
app.data('assets', paths.assets());
app.data('dest', paths.dest());
};