UNPKG

1.25 kBJavaScriptView Raw
1"use strict";
2
3const _path = require("path");
4const _os = require("os");
5
6const _ = require("lodash");
7const async = require("neo-async");
8
9exports.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
43function getPath(path) {
44 // If path ends in a file extension, then output as is! This is
45 // useful for generating 404.html and such.
46 if (_path.extname(path)) {
47 return path;
48 }
49
50 // Avoid writing index/index.html and write index.html instead
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