UNPKG

774 BJavaScriptView Raw
1const async = require('async');
2const path = require('path');
3const glob = require('glob');
4const basePath = process.cwd();
5
6module.exports = (section, callback) => {
7
8 // Task flow control
9 async.parallel([
10
11 // Get file deps for top level page
12 async.apply(getContentList, section),
13
14 // Get file deps for children if required
15 (cb) => async.map(section.children, getContentList, cb)
16
17 ], done);
18
19 // On complete handler
20 function done(err, result) {
21 if (err) {
22 callback(err);
23 } else {
24 callback(null, section)
25 }
26 }
27}
28
29function getContentList(page, cb) {
30 glob(path.join(basePath, page.contentSrc), (err, filenames) => {
31 if (err) {
32 cb(err)
33 } else {
34 page.fileDependencies = filenames;
35 cb();
36 }
37 });
38}