1 | const async = require('async');
|
2 | const path = require('path');
|
3 | const glob = require('glob');
|
4 | const basePath = process.cwd();
|
5 |
|
6 | module.exports = (section, callback) => {
|
7 |
|
8 |
|
9 | async.parallel([
|
10 |
|
11 |
|
12 | async.apply(getContentList, section),
|
13 |
|
14 |
|
15 | (cb) => async.map(section.children, getContentList, cb)
|
16 |
|
17 | ], done);
|
18 |
|
19 |
|
20 | function done(err, result) {
|
21 | if (err) {
|
22 | callback(err);
|
23 | } else {
|
24 | callback(null, section)
|
25 | }
|
26 | }
|
27 | }
|
28 |
|
29 | function 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 | }
|