1 | "use strict";
|
2 |
|
3 | const _path = require("path");
|
4 | const _os = require("os");
|
5 |
|
6 | const _ = require("lodash");
|
7 | const async = require("neo-async");
|
8 |
|
9 | exports.pages = (o, environment, configurationPaths) => finalCb => {
|
10 | const data = Object.keys(o.allPages).map(function (page) {
|
11 | const p = _path.join(o.output, page);
|
12 |
|
13 | return {
|
14 | path: p,
|
15 | page,
|
16 | title: o.allPages[page].title
|
17 | };
|
18 | });
|
19 |
|
20 | async.map(data, function (d, cb) {
|
21 | return cb(null, {
|
22 | path: getPath(d.path),
|
23 | page: d.page,
|
24 | title: d.title
|
25 | });
|
26 | }, function (err, d) {
|
27 | if (err) {
|
28 | return finalCb(err);
|
29 | }
|
30 |
|
31 | return finalCb(null, _.chunk(d, _os.cpus().length).map(function (partition) {
|
32 | return {
|
33 | environment,
|
34 | configurationPaths,
|
35 | outputPath: o.output,
|
36 | pages: partition,
|
37 | templates: o.templates
|
38 | };
|
39 | }));
|
40 | });
|
41 | };
|
42 |
|
43 | function getPath(path) {
|
44 |
|
45 |
|
46 | if (_path.extname(path)) {
|
47 | return path;
|
48 | }
|
49 |
|
50 |
|
51 | return path.split("/").slice(-1)[0] === "index" ? _path.join(path, "..", "index.html") : _path.join(path, "index.html");
|
52 | } |
\ | No newline at end of file |