1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _react = require("react");
|
8 |
|
9 | var _react2 = _interopRequireDefault(_react);
|
10 |
|
11 | var _config = require("config");
|
12 |
|
13 | var _config2 = _interopRequireDefault(_config);
|
14 |
|
15 | var _lodash = require("lodash");
|
16 |
|
17 | var _lodash2 = _interopRequireDefault(_lodash);
|
18 |
|
19 | var _paths = require("./paths");
|
20 |
|
21 | var _paths2 = _interopRequireDefault(_paths);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 |
|
26 | const BodyContent = (page, allPages) => ({ location }) => render({
|
27 | section: getSection(page, location.pathname, allPages),
|
28 | config: _config2.default,
|
29 | page,
|
30 | location
|
31 | });
|
32 |
|
33 | function getSection(page, pathname, allPages) {
|
34 | const sectionName = page.sectionName;
|
35 | const section = _config2.default.paths[sectionName || "/"] || _config2.default.paths["/"] || {};
|
36 |
|
37 |
|
38 |
|
39 | if (!section.name) {
|
40 | section.name = sectionName;
|
41 | }
|
42 |
|
43 |
|
44 | section.all = () => getAllSectionPages(allPages);
|
45 |
|
46 |
|
47 | section.pages = name => getSectionPages(_config2.default, name || sectionName, allPages);
|
48 |
|
49 | return section;
|
50 | }
|
51 |
|
52 | function getAllSectionPages(allPages) {
|
53 | return _lodash2.default.map(_config2.default.paths, (path, name) => ({
|
54 | url: name,
|
55 | path,
|
56 | pages: getSectionPages(_config2.default, name, allPages)
|
57 | }));
|
58 | }
|
59 |
|
60 | function getSectionPages(config, name, allPages) {
|
61 | return _lodash2.default.filter(_paths2.default.getSectionPages(config, name, allPages), p => p.type === "page");
|
62 | }
|
63 |
|
64 | function render(props) {
|
65 | let content;
|
66 |
|
67 | if (props.page.layout) {
|
68 | content = _react2.default.createFactory(props.page.layout)(props);
|
69 | } else {
|
70 | console.error("Trying to render a page with an unknown type", props);
|
71 | }
|
72 |
|
73 |
|
74 | if (props.config.layout) {
|
75 | return _react2.default.createFactory(props.config.layout())(props, content);
|
76 | }
|
77 |
|
78 | return content;
|
79 | }
|
80 |
|
81 | exports.default = BodyContent; |
\ | No newline at end of file |