@canopycanopycanopy/b-ber-tasks 1.2.16 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clean/index.js +0 -15
- package/dist/container/index.js +1 -20
- package/dist/copy/index.js +2 -20
- package/dist/cover/index.js +36 -91
- package/dist/deploy/index.js +22 -63
- package/dist/epub/index.js +0 -12
- package/dist/footnotes/index.js +0 -27
- package/dist/generate/index.js +5 -32
- package/dist/index.js +0 -52
- package/dist/init/index.js +4 -29
- package/dist/inject/index.js +3 -31
- package/dist/loi/index.js +27 -74
- package/dist/mobi/index.js +8 -17
- package/dist/mobi/mobi-css.js +2 -39
- package/dist/opf/ManifestAndMetadata.js +18 -35
- package/dist/opf/Navigation.js +28 -82
- package/dist/opf/Opf.js +3 -20
- package/dist/opf/helpers.js +5 -20
- package/dist/opf/index.js +0 -10
- package/dist/pdf/index.js +3 -29
- package/dist/reader/index.js +26 -66
- package/dist/render/index.js +2 -28
- package/dist/sample/index.js +0 -6
- package/dist/sass/index.js +51 -85
- package/dist/scripts/index.js +0 -24
- package/dist/serialize.js +5 -18
- package/dist/serve/index.js +44 -61
- package/dist/validate/index.js +4 -22
- package/dist/web/Template.js +0 -21
- package/dist/web/index.js +42 -139
- package/dist/xml/index.js +0 -30
- package/package.json +13 -12
package/dist/web/index.js
CHANGED
|
@@ -1,85 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _Object$
|
|
4
|
-
|
|
3
|
+
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
+
var _filterInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
+
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
+
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
5
11
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
|
-
_Object$defineProperty2(exports, "__esModule", {
|
|
12
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
8
13
|
value: true
|
|
9
14
|
});
|
|
10
|
-
|
|
11
15
|
exports.default = void 0;
|
|
12
|
-
|
|
13
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
14
|
-
|
|
15
17
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
16
|
-
|
|
17
18
|
var _splice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/splice"));
|
|
18
|
-
|
|
19
19
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
20
|
-
|
|
21
20
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
|
-
|
|
23
21
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
24
|
-
|
|
25
22
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
26
|
-
|
|
27
|
-
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
28
|
-
|
|
29
|
-
var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
|
|
30
|
-
|
|
31
|
-
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"));
|
|
32
|
-
|
|
33
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
34
|
-
|
|
35
|
-
var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"));
|
|
36
|
-
|
|
37
|
-
var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-properties"));
|
|
38
|
-
|
|
39
|
-
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
|
40
|
-
|
|
41
23
|
var _path = _interopRequireDefault(require("path"));
|
|
42
|
-
|
|
43
24
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
44
|
-
|
|
45
25
|
var _find = _interopRequireDefault(require("lodash/find"));
|
|
46
|
-
|
|
47
26
|
var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
|
|
48
|
-
|
|
49
27
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
50
|
-
|
|
51
28
|
var _cheerio = _interopRequireDefault(require("cheerio"));
|
|
52
|
-
|
|
53
29
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
54
|
-
|
|
55
30
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
56
|
-
|
|
57
31
|
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
58
|
-
|
|
59
32
|
var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
|
|
60
|
-
|
|
61
33
|
var _Toc = _interopRequireDefault(require("@canopycanopycanopy/b-ber-templates/Toc"));
|
|
62
|
-
|
|
63
34
|
var _recursiveReaddir = _interopRequireDefault(require("recursive-readdir"));
|
|
64
|
-
|
|
65
35
|
var _Template = _interopRequireDefault(require("./Template"));
|
|
66
|
-
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context7; (0, _forEach.default)(_context7 = ownKeys(Object(source), true)).call(_context7, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (_getOwnPropertyDescriptors.default) { (0, _defineProperties.default)(target, (0, _getOwnPropertyDescriptors.default)(source)); } else { var _context8; (0, _forEach.default)(_context8 = ownKeys(Object(source))).call(_context8, function (key) { (0, _defineProperty3.default)(target, key, (0, _getOwnPropertyDescriptor.default)(source, key)); }); } } return target; }
|
|
70
|
-
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
71
38
|
let ASSETS_TO_UNLINK;
|
|
72
39
|
let DIST_PATH;
|
|
73
40
|
let OPS_PATH;
|
|
74
41
|
let OMIT_FROM_SEARCH;
|
|
75
42
|
let BASE_URL;
|
|
76
43
|
let flow; // copy of spine for web task, see `WebFlow` below
|
|
44
|
+
|
|
77
45
|
// Class to manage pagination for web layout. when building an epub, figures are
|
|
78
46
|
// handled outside of the spine, mostly so that they can have hashed file names
|
|
79
47
|
// (since they're generated on the fly), and so that the individual figures
|
|
80
48
|
// pages are not listed in the YAML files. the `WebFlow` class creates a new
|
|
81
49
|
// spine by merging in the loi
|
|
82
|
-
|
|
83
50
|
class WebFlow {
|
|
84
51
|
constructor({
|
|
85
52
|
spine,
|
|
@@ -91,60 +58,51 @@ class WebFlow {
|
|
|
91
58
|
this.addFiguresToSpine();
|
|
92
59
|
this.removeNonLinearEntriesFromSpine();
|
|
93
60
|
this.removeTocFromSpine();
|
|
94
|
-
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// TODO: the naming scheme for figures is slightly different for figures (the
|
|
95
64
|
// `fileName` property has a file extension). @issue:
|
|
96
65
|
// https://github.com/triplecanopy/b-ber/issues/208
|
|
97
|
-
|
|
98
|
-
|
|
99
66
|
prepareLoi() {
|
|
100
67
|
var _context;
|
|
101
|
-
|
|
102
68
|
this.loi = (0, _map.default)(_context = this.loi).call(_context, a => {
|
|
103
69
|
const b = _objectSpread({}, a);
|
|
104
|
-
|
|
105
70
|
b.fileName = b.fileName.replace(/\.xhtml$/, '');
|
|
106
71
|
b.relativePath = b.relativePath.replace(/\.xhtml$/, '');
|
|
107
72
|
return b;
|
|
108
73
|
});
|
|
109
74
|
}
|
|
110
|
-
|
|
111
75
|
getFiguresPageIndex() {
|
|
112
76
|
const fileName = 'figures-titlepage';
|
|
113
77
|
return (0, _findIndex.default)(this.spine.flattened, {
|
|
114
78
|
fileName
|
|
115
79
|
});
|
|
116
80
|
}
|
|
117
|
-
|
|
118
81
|
addFiguresToSpine() {
|
|
119
82
|
var _context2;
|
|
120
|
-
|
|
121
83
|
if (!this.loi.length) return;
|
|
122
84
|
const figuresPageIndex = this.getFiguresPageIndex();
|
|
123
85
|
if (figuresPageIndex < 0) return;
|
|
124
86
|
(0, _splice.default)(_context2 = this.spine.flattened).call(_context2, figuresPageIndex + 1, 0, ...this.loi);
|
|
125
87
|
}
|
|
126
|
-
|
|
127
88
|
removeNonLinearEntriesFromSpine() {
|
|
128
89
|
var _context3;
|
|
129
|
-
|
|
130
90
|
this.spine = (0, _filter.default)(_context3 = this.spine.flattened).call(_context3, a => a.linear);
|
|
131
91
|
}
|
|
132
|
-
|
|
133
92
|
removeTocFromSpine() {
|
|
134
93
|
var _context4;
|
|
135
|
-
|
|
136
94
|
this.spine = (0, _filter.default)(_context4 = this.spine).call(_context4, a => a.fileName !== 'toc');
|
|
137
95
|
}
|
|
96
|
+
}
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
98
|
+
// Make sure we're using the correct build variables
|
|
142
99
|
async function initialize() {
|
|
143
100
|
DIST_PATH = _State.default.distDir;
|
|
144
101
|
OPS_PATH = _path.default.join(DIST_PATH, 'OPS');
|
|
145
102
|
BASE_URL = _bBerLib.Url.addTrailingSlash(_State.default.config.base_url);
|
|
146
|
-
ASSETS_TO_UNLINK = [_path.default.join(DIST_PATH, 'mimetype'), _path.default.join(DIST_PATH, 'META-INF'), _path.default.join(DIST_PATH, 'OPS/content.opf'), _path.default.join(DIST_PATH, 'OPS/toc.ncx')];
|
|
103
|
+
ASSETS_TO_UNLINK = [_path.default.join(DIST_PATH, 'mimetype'), _path.default.join(DIST_PATH, 'META-INF'), _path.default.join(DIST_PATH, 'OPS/content.opf'), _path.default.join(DIST_PATH, 'OPS/toc.ncx')];
|
|
147
104
|
|
|
105
|
+
// List of spine item entry `fileName`s
|
|
148
106
|
OMIT_FROM_SEARCH = ['toc'];
|
|
149
107
|
const {
|
|
150
108
|
spine,
|
|
@@ -155,126 +113,97 @@ async function initialize() {
|
|
|
155
113
|
loi
|
|
156
114
|
});
|
|
157
115
|
}
|
|
158
|
-
|
|
159
116
|
async function moveAssetsToRootDirctory() {
|
|
160
117
|
const files = _fsExtra.default.readdirSync(OPS_PATH);
|
|
161
|
-
|
|
162
118
|
const dirs = (0, _filter.default)(files).call(files, file => file.charAt(0) !== '.' && _fsExtra.default.statSync(_path.default.join(OPS_PATH, file)).isDirectory());
|
|
163
119
|
const promises = (0, _map.default)(dirs).call(dirs, dir => {
|
|
164
120
|
const from = _path.default.join(OPS_PATH, dir);
|
|
165
|
-
|
|
166
121
|
const to = _path.default.join(DIST_PATH, dir);
|
|
167
|
-
|
|
168
122
|
_bBerLogger.default.info('Moving [%s]', dir);
|
|
169
|
-
|
|
170
123
|
return _fsExtra.default.move(from, to);
|
|
171
|
-
});
|
|
124
|
+
});
|
|
172
125
|
|
|
126
|
+
// Remove the OPS dir once all the moving assets have been moved
|
|
173
127
|
await _promise.default.all(promises);
|
|
174
128
|
return _fsExtra.default.remove(OPS_PATH);
|
|
175
129
|
}
|
|
176
|
-
|
|
177
130
|
function unlinkRedundantAssets() {
|
|
178
131
|
const promises = (0, _map.default)(ASSETS_TO_UNLINK).call(ASSETS_TO_UNLINK, file => {
|
|
179
132
|
_bBerLogger.default.info('Removing [%s]', _path.default.basename(file));
|
|
180
|
-
|
|
181
133
|
return _fsExtra.default.remove(file);
|
|
182
134
|
});
|
|
183
135
|
return _promise.default.all(promises);
|
|
184
136
|
}
|
|
185
|
-
|
|
186
137
|
function getProjectTitle() {
|
|
187
138
|
let title = '';
|
|
188
139
|
const titleEntry = (0, _utils.getBookMetadata)('title', _State.default);
|
|
189
|
-
|
|
190
140
|
if (titleEntry && titleEntry.value) {
|
|
191
141
|
title = titleEntry.value;
|
|
192
142
|
}
|
|
193
|
-
|
|
194
143
|
return title;
|
|
195
144
|
}
|
|
196
|
-
|
|
197
145
|
function getChapterTitle(fileName) {
|
|
198
146
|
if (typeof fileName !== 'string') return getProjectTitle();
|
|
199
|
-
|
|
200
147
|
const meta = _State.default.spine.frontMatter.get(fileName);
|
|
201
|
-
|
|
202
148
|
if (!(meta !== null && meta !== void 0 && meta.title)) return getProjectTitle();
|
|
203
149
|
return meta.title;
|
|
204
150
|
}
|
|
205
|
-
|
|
206
151
|
function getProjectMetadataHTML() {
|
|
207
152
|
return _Template.default.metadata(_State.default.metadata.json());
|
|
208
153
|
}
|
|
209
|
-
|
|
210
154
|
function getHeaderElement(fileName) {
|
|
211
155
|
const title = getChapterTitle(fileName);
|
|
212
156
|
return _Template.default.header(title);
|
|
213
157
|
}
|
|
214
|
-
|
|
215
158
|
function createNavigationElement() {
|
|
216
159
|
const {
|
|
217
160
|
toc: prevToc
|
|
218
|
-
} = _State.default;
|
|
161
|
+
} = _State.default;
|
|
219
162
|
|
|
163
|
+
// Filter out toc entry if it exists
|
|
220
164
|
const toc = (0, _filter.default)(prevToc).call(prevToc, item => item.fileName !== 'toc');
|
|
221
|
-
|
|
222
165
|
const tocHTML = _Toc.default.items(toc).replace(/a href="/g, `a href="${BASE_URL}`);
|
|
223
|
-
|
|
224
166
|
const metadataHTML = getProjectMetadataHTML();
|
|
225
167
|
const title = getProjectTitle();
|
|
226
|
-
|
|
227
168
|
const tocElement = _Template.default.toc(BASE_URL, title, tocHTML);
|
|
228
|
-
|
|
229
169
|
const infoElement = _Template.default.info(metadataHTML);
|
|
230
|
-
|
|
231
170
|
return {
|
|
232
171
|
tocElement,
|
|
233
172
|
infoElement
|
|
234
173
|
};
|
|
235
174
|
}
|
|
236
|
-
|
|
237
175
|
function buttonPrev(filePath) {
|
|
238
176
|
const fileName = _path.default.basename(filePath, '.xhtml');
|
|
239
|
-
|
|
240
177
|
const index = (0, _findIndex.default)(flow.spine, {
|
|
241
178
|
fileName
|
|
242
179
|
});
|
|
243
180
|
const prevIndex = index - 1;
|
|
244
181
|
let html = '';
|
|
245
|
-
|
|
246
182
|
if (index > -1 && flow.spine[prevIndex]) {
|
|
247
183
|
const href = `${flow.spine[prevIndex].fileName}.xhtml`;
|
|
248
184
|
html = _Template.default.prev(BASE_URL, href);
|
|
249
185
|
}
|
|
250
|
-
|
|
251
186
|
return html;
|
|
252
187
|
}
|
|
253
|
-
|
|
254
188
|
function buttonNext(filePath) {
|
|
255
189
|
const fileName = _path.default.basename(filePath, '.xhtml');
|
|
256
|
-
|
|
257
190
|
const index = (0, _findIndex.default)(flow.spine, {
|
|
258
191
|
fileName
|
|
259
192
|
});
|
|
260
193
|
const nextIndex = index + 1;
|
|
261
194
|
let html = '';
|
|
262
|
-
|
|
263
195
|
if (index > -1 && flow.spine[nextIndex]) {
|
|
264
196
|
const href = `${flow.spine[nextIndex].fileName}.xhtml`;
|
|
265
197
|
html = _Template.default.next(BASE_URL, href);
|
|
266
198
|
}
|
|
267
|
-
|
|
268
199
|
return html;
|
|
269
200
|
}
|
|
270
|
-
|
|
271
201
|
function paginate(filePath) {
|
|
272
202
|
return {
|
|
273
203
|
prev: buttonPrev(filePath),
|
|
274
204
|
next: buttonNext(filePath)
|
|
275
205
|
};
|
|
276
206
|
}
|
|
277
|
-
|
|
278
207
|
function paginationNavigation(filePath) {
|
|
279
208
|
const {
|
|
280
209
|
prev,
|
|
@@ -282,31 +211,25 @@ function paginationNavigation(filePath) {
|
|
|
282
211
|
} = paginate(filePath);
|
|
283
212
|
return _Template.default.pagination(prev, next);
|
|
284
213
|
}
|
|
285
|
-
|
|
286
214
|
function injectBaseURL(script) {
|
|
287
215
|
const script_ = typeof script === 'string' ? script : String(script);
|
|
288
216
|
return Buffer.from(script_.replace(/%BASE_URL%/g, BASE_URL));
|
|
289
217
|
}
|
|
290
|
-
|
|
291
218
|
function getStyleBlock() {
|
|
292
219
|
return _Template.default.styles();
|
|
293
220
|
}
|
|
294
|
-
|
|
295
221
|
function getNavigationToggleScript() {
|
|
296
222
|
const content = injectBaseURL(_fsExtra.default.readFileSync(_path.default.join(__dirname, 'navigation.js')));
|
|
297
223
|
return _Template.default.scripts(content);
|
|
298
224
|
}
|
|
299
|
-
|
|
300
225
|
function getWebWorkerScript() {
|
|
301
226
|
const content = injectBaseURL(_fsExtra.default.readFileSync(_path.default.join(__dirname, 'search.js')));
|
|
302
227
|
return _Template.default.scripts(content);
|
|
303
228
|
}
|
|
304
|
-
|
|
305
229
|
function getEventHandlerScript() {
|
|
306
230
|
const content = injectBaseURL(_fsExtra.default.readFileSync(_path.default.join(__dirname, 'event-handlers.js')));
|
|
307
231
|
return _Template.default.scripts(content);
|
|
308
232
|
}
|
|
309
|
-
|
|
310
233
|
function injectPageElementsIntoFile(filePath) {
|
|
311
234
|
const {
|
|
312
235
|
tocElement,
|
|
@@ -318,43 +241,35 @@ function injectPageElementsIntoFile(filePath) {
|
|
|
318
241
|
const webWorkerScript = getWebWorkerScript();
|
|
319
242
|
const evenHandlerScript = getEventHandlerScript();
|
|
320
243
|
const headerElement = getHeaderElement(_path.default.basename(filePath, _path.default.extname(filePath)));
|
|
321
|
-
|
|
322
244
|
_bBerLogger.default.info(`Adding pagination to ${_path.default.basename(filePath)}`);
|
|
245
|
+
const data = _fsExtra.default.readFileSync(filePath, 'utf8');
|
|
323
246
|
|
|
324
|
-
|
|
247
|
+
// Prepare to modify publication content
|
|
248
|
+
let contents;
|
|
325
249
|
|
|
326
|
-
|
|
327
|
-
let contents; // Prepend the dynamically generated elements to body, adding a
|
|
250
|
+
// Prepend the dynamically generated elements to body, adding a
|
|
328
251
|
// wrapper around the main publication content. this allows us to
|
|
329
252
|
// create a sliding nav, fixed header, etc.
|
|
253
|
+
contents = data.replace(/(<body[^>]*?>)/, _Template.default.body(styleBlock, headerElement));
|
|
330
254
|
|
|
331
|
-
|
|
255
|
+
// Close the wrapper element, adding a little javascript for the
|
|
332
256
|
// navigation toggle. should be moved to core when stable
|
|
333
|
-
|
|
334
257
|
contents = contents.replace(/(<\/body>)/, _Template.default.footer(pageNavigation, tocElement, infoElement, navigationToggleScript, webWorkerScript, evenHandlerScript));
|
|
335
|
-
|
|
336
258
|
_bBerLogger.default.info(`web writing ${_path.default.basename(filePath)}`);
|
|
337
|
-
|
|
338
259
|
return _fsExtra.default.writeFile(filePath, contents);
|
|
339
260
|
}
|
|
340
|
-
|
|
341
261
|
function injectPageElementsIntoFiles(elements) {
|
|
342
262
|
var _context5;
|
|
343
|
-
|
|
344
263
|
const textPath = _path.default.join(DIST_PATH, 'text');
|
|
345
|
-
|
|
346
264
|
const files = (0, _filter.default)(_context5 = _fsExtra.default.readdirSync(textPath)).call(_context5, file => _path.default.extname(file) === '.xhtml');
|
|
347
265
|
const promises = (0, _map.default)(files).call(files, file => {
|
|
348
266
|
const filePath = _path.default.resolve(textPath, file);
|
|
349
|
-
|
|
350
267
|
return injectPageElementsIntoFile(filePath, elements);
|
|
351
268
|
});
|
|
352
269
|
return _promise.default.all(promises).then(() => elements);
|
|
353
270
|
}
|
|
354
|
-
|
|
355
271
|
function indexPageContent() {
|
|
356
272
|
var _context6;
|
|
357
|
-
|
|
358
273
|
const {
|
|
359
274
|
spine
|
|
360
275
|
} = flow;
|
|
@@ -362,7 +277,6 @@ function indexPageContent() {
|
|
|
362
277
|
let fileIndex = -1;
|
|
363
278
|
const promises = (0, _map.default)(_context6 = (0, _filter.default)(spine).call(spine, a => (0, _indexOf.default)(OMIT_FROM_SEARCH).call(OMIT_FROM_SEARCH, a.fileName) < 0)).call(_context6, entry => _fsExtra.default.readFile(_path.default.join(OPS_PATH, `${entry.relativePath}.xhtml`), 'utf8').then(data => {
|
|
364
279
|
const $ = _cheerio.default.load(data);
|
|
365
|
-
|
|
366
280
|
const title = $('h1,h2,h3,h4,h5,h6').first().text();
|
|
367
281
|
const body = $('body').text();
|
|
368
282
|
const url = `${BASE_URL}text/${entry.fileName}.xhtml`;
|
|
@@ -376,63 +290,50 @@ function indexPageContent() {
|
|
|
376
290
|
}));
|
|
377
291
|
return _promise.default.all(promises).then(() => (0, _stringify.default)(records));
|
|
378
292
|
}
|
|
379
|
-
|
|
380
293
|
function writeJSONPageData(json) {
|
|
381
294
|
return _fsExtra.default.writeFile(_path.default.join(DIST_PATH, 'search-index.json'), json);
|
|
382
295
|
}
|
|
383
|
-
|
|
384
296
|
function importVendorScripts() {
|
|
385
297
|
const lunrPath = require.resolve('lunr');
|
|
386
|
-
|
|
387
298
|
const outputPath = _path.default.join(DIST_PATH, 'lunr.js');
|
|
388
|
-
|
|
389
299
|
return _fsExtra.default.copy(lunrPath, outputPath);
|
|
390
300
|
}
|
|
391
|
-
|
|
392
301
|
function writeWebWorker() {
|
|
393
302
|
const worker = injectBaseURL(_fsExtra.default.readFileSync(_path.default.join(__dirname, 'worker.js')));
|
|
394
303
|
return _fsExtra.default.writeFile(_path.default.join(DIST_PATH, 'worker.js'), worker);
|
|
395
304
|
}
|
|
396
|
-
|
|
397
305
|
function writeWebpubManifest() {
|
|
398
306
|
return new _promise.default((resolve, reject) => {
|
|
399
307
|
(0, _recursiveReaddir.default)(_State.default.distDir, (err1, files) => {
|
|
400
308
|
if (err1) reject(err1);
|
|
401
309
|
const manifest = (0, _utils.generateWebpubManifest)(files);
|
|
402
|
-
|
|
403
310
|
_fsExtra.default.writeJson(_path.default.join(DIST_PATH, 'manifest.json'), manifest).then(resolve);
|
|
404
311
|
});
|
|
405
312
|
});
|
|
406
|
-
}
|
|
407
|
-
// which is 0-indexed
|
|
408
|
-
|
|
313
|
+
}
|
|
409
314
|
|
|
315
|
+
// subtracts 1 from `n` argument since `getPage` refrerences state.spine,
|
|
316
|
+
// which is 0-indexed
|
|
410
317
|
function getPage(_n = -1) {
|
|
411
318
|
const n = _n - 1;
|
|
412
319
|
const url = `${BASE_URL}text/${flow.spine[n].fileName}.xhtml`;
|
|
413
320
|
return url;
|
|
414
321
|
}
|
|
415
|
-
|
|
416
322
|
function getFirstPage() {
|
|
417
323
|
return getPage(1);
|
|
418
324
|
}
|
|
419
|
-
|
|
420
325
|
function getCoverImage() {
|
|
421
326
|
const metadata = _State.default.metadata.json();
|
|
422
|
-
|
|
423
327
|
const coverEntry = (0, _find.default)(metadata, {
|
|
424
328
|
term: 'cover'
|
|
425
329
|
});
|
|
426
330
|
const firstPage = getFirstPage();
|
|
427
331
|
let coverImageSrc = 'images/';
|
|
428
|
-
|
|
429
332
|
if (coverEntry && (0, _has.default)(coverEntry, 'value')) {
|
|
430
333
|
coverImageSrc += coverEntry.value;
|
|
431
334
|
}
|
|
432
|
-
|
|
433
335
|
return _Template.default.cover(firstPage, coverImageSrc);
|
|
434
336
|
}
|
|
435
|
-
|
|
436
337
|
function createIndexHTML() {
|
|
437
338
|
const {
|
|
438
339
|
tocElement,
|
|
@@ -444,20 +345,22 @@ function createIndexHTML() {
|
|
|
444
345
|
const webWorkerScript = getWebWorkerScript();
|
|
445
346
|
const headerElement = getHeaderElement();
|
|
446
347
|
const styleBlock = getStyleBlock();
|
|
348
|
+
const robotsMeta = _Template.default.robots(_State.default.config.private);
|
|
447
349
|
|
|
448
|
-
|
|
350
|
+
// TODO: should get dynamic page template here to ensure asset hash on production build
|
|
449
351
|
// @issue: https://github.com/triplecanopy/b-ber/issues/232
|
|
450
|
-
|
|
451
|
-
|
|
452
352
|
const indexHTML = _Template.default.index(BASE_URL, robotsMeta, title, styleBlock, tocElement, infoElement, headerElement, coverImage, navigationToggleScript, webWorkerScript);
|
|
453
|
-
|
|
454
353
|
return _fsExtra.default.writeFile(_path.default.resolve(DIST_PATH, 'index.html'), indexHTML);
|
|
455
354
|
}
|
|
355
|
+
const web = () => initialize().then(unlinkRedundantAssets)
|
|
456
356
|
|
|
457
|
-
|
|
458
|
-
.then(indexPageContent).then(writeJSONPageData)
|
|
459
|
-
|
|
460
|
-
.
|
|
357
|
+
// Create search index
|
|
358
|
+
.then(indexPageContent).then(writeJSONPageData)
|
|
359
|
+
|
|
360
|
+
// move files to root directory and create an index.html
|
|
361
|
+
.then(moveAssetsToRootDirctory).then(injectPageElementsIntoFiles).then(createIndexHTML)
|
|
461
362
|
|
|
363
|
+
// write scripts into HTML files
|
|
364
|
+
.then(importVendorScripts).then(writeWebpubManifest).then(writeWebWorker).catch(_bBerLogger.default.error);
|
|
462
365
|
var _default = web;
|
|
463
366
|
exports.default = _default;
|
package/dist/xml/index.js
CHANGED
|
@@ -1,63 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
14
|
-
|
|
15
10
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
16
|
-
|
|
17
11
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
18
|
-
|
|
19
12
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
20
|
-
|
|
21
13
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
22
|
-
|
|
23
14
|
var _splice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/splice"));
|
|
24
|
-
|
|
25
15
|
var _path = _interopRequireDefault(require("path"));
|
|
26
|
-
|
|
27
16
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
28
|
-
|
|
29
17
|
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
30
|
-
|
|
31
18
|
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
32
|
-
|
|
33
19
|
var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
|
|
34
|
-
|
|
35
20
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
36
|
-
|
|
37
21
|
var _HtmlToXml = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/HtmlToXml"));
|
|
38
|
-
|
|
39
22
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
40
|
-
|
|
41
23
|
var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
|
|
42
|
-
|
|
43
24
|
const fileExtension = '.xhtml';
|
|
44
|
-
|
|
45
25
|
const writeXML = str => {
|
|
46
26
|
const cwd = process.cwd();
|
|
47
27
|
const uuid = (0, _utils.getBookMetadata)('identifier', _State.default);
|
|
48
|
-
|
|
49
28
|
const filePath = _path.default.join(cwd, `${uuid}.xml`);
|
|
50
|
-
|
|
51
29
|
return _fsExtra.default.writeFile(filePath, str, 'utf8');
|
|
52
30
|
};
|
|
53
|
-
|
|
54
31
|
const parseHTMLFiles = files => new _promise.default(resolve => {
|
|
55
32
|
const content = (0, _reduce.default)(files).call(files, (acc, curr) => {
|
|
56
33
|
const filePath = (0, _isPlainObject.default)(curr) ? (0, _keys.default)(curr)[0] : (0, _isString.default)(curr) ? curr : null;
|
|
57
34
|
if (!filePath) return acc;
|
|
58
|
-
|
|
59
35
|
const data = _fsExtra.default.readFileSync(filePath, 'utf8');
|
|
60
|
-
|
|
61
36
|
return (0, _concat.default)(acc).call(acc, `${data}`);
|
|
62
37
|
}, []).join('<pagebreak></pagebreak>');
|
|
63
38
|
const parser = new _HtmlToXml.default({
|
|
@@ -66,23 +41,18 @@ const parseHTMLFiles = files => new _promise.default(resolve => {
|
|
|
66
41
|
});
|
|
67
42
|
parser.parse();
|
|
68
43
|
});
|
|
69
|
-
|
|
70
44
|
const xml = () => {
|
|
71
45
|
let files = [..._State.default.spine.flattened];
|
|
72
46
|
const figuresTitlePageIndex = (0, _findIndex.default)(files, {
|
|
73
47
|
fileName: 'figures-titlepage'
|
|
74
48
|
});
|
|
75
49
|
files = (0, _map.default)(files).call(files, entry => `${entry.absolutePath}${fileExtension}`);
|
|
76
|
-
|
|
77
50
|
if (figuresTitlePageIndex > -1 && _State.default.loi.length) {
|
|
78
51
|
var _context;
|
|
79
|
-
|
|
80
52
|
const loi = (0, _map.default)(_context = _State.default.loi).call(_context, entry => entry.absolutePath);
|
|
81
53
|
(0, _splice.default)(files).call(files, figuresTitlePageIndex + 1, 0, ...loi);
|
|
82
54
|
}
|
|
83
|
-
|
|
84
55
|
return parseHTMLFiles(files).then(writeXML).catch(_bBerLogger.default.error);
|
|
85
56
|
};
|
|
86
|
-
|
|
87
57
|
var _default = xml;
|
|
88
58
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-tasks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/runtime-corejs3": "^7.10.5",
|
|
22
|
-
"@canopycanopycanopy/b-ber-lib": "
|
|
23
|
-
"@canopycanopycanopy/b-ber-logger": "
|
|
24
|
-
"@canopycanopycanopy/b-ber-markdown-renderer": "
|
|
25
|
-
"@canopycanopycanopy/b-ber-reader": "
|
|
26
|
-
"@canopycanopycanopy/b-ber-resources": "
|
|
27
|
-
"@canopycanopycanopy/b-ber-shapes-sequences": "
|
|
28
|
-
"@canopycanopycanopy/b-ber-templates": "
|
|
29
|
-
"@canopycanopycanopy/b-ber-validator": "
|
|
22
|
+
"@canopycanopycanopy/b-ber-lib": "2.0.2",
|
|
23
|
+
"@canopycanopycanopy/b-ber-logger": "2.0.2",
|
|
24
|
+
"@canopycanopycanopy/b-ber-markdown-renderer": "2.0.2",
|
|
25
|
+
"@canopycanopycanopy/b-ber-reader": "2.0.2",
|
|
26
|
+
"@canopycanopycanopy/b-ber-resources": "2.0.2",
|
|
27
|
+
"@canopycanopycanopy/b-ber-shapes-sequences": "2.0.2",
|
|
28
|
+
"@canopycanopycanopy/b-ber-templates": "2.0.2",
|
|
29
|
+
"@canopycanopycanopy/b-ber-validator": "2.0.2",
|
|
30
30
|
"autoprefixer": "^9.6.1",
|
|
31
31
|
"browser-sync": "^2.27.7",
|
|
32
32
|
"bs-html-injector": "^3.0.3",
|
|
@@ -54,9 +54,10 @@
|
|
|
54
54
|
"@babel/cli": "^7.10.5",
|
|
55
55
|
"@babel/core": "^7.10.5",
|
|
56
56
|
"@babel/preset-env": "^7.10.4",
|
|
57
|
-
"
|
|
57
|
+
"browserslist": "^4.17.4",
|
|
58
|
+
"jest": "^26.6.3",
|
|
58
59
|
"mock-fs": "^4.4.2",
|
|
59
|
-
"rimraf": "^2.
|
|
60
|
+
"rimraf": "^2.7.1"
|
|
60
61
|
},
|
|
61
62
|
"files": [
|
|
62
63
|
"dist"
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"url": "https://maxwellsimmer.com"
|
|
76
77
|
}
|
|
77
78
|
],
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
|
|
79
80
|
}
|