@canopycanopycanopy/b-ber-lib 3.0.0 → 3.0.3
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/Config.js +1 -9
- package/EbookConvert.js +0 -28
- package/GuideItem.js +0 -5
- package/Html.js +0 -6
- package/HtmlToXml.js +0 -38
- package/ManifestItemProperties.js +19 -40
- package/Spine.js +15 -59
- package/SpineItem.js +4 -11
- package/State.js +68 -149
- package/Template.js +0 -8
- package/Theme.js +23 -79
- package/Url.js +0 -11
- package/Yaml.js +5 -38
- package/YamlAdaptor.js +0 -19
- package/index.js +0 -28
- package/package.json +7 -7
- package/utils/index.js +35 -91
package/Config.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
14
|
-
|
|
15
10
|
var _defaultsDeep = _interopRequireDefault(require("lodash/defaultsDeep"));
|
|
16
|
-
|
|
17
11
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
18
|
-
|
|
19
12
|
/* eslint-disable camelcase */
|
|
13
|
+
|
|
20
14
|
class Config {
|
|
21
15
|
constructor(options = {}) {
|
|
22
16
|
(0, _defineProperty2.default)(this, "defaultOptions", {
|
|
@@ -60,8 +54,6 @@ class Config {
|
|
|
60
54
|
const optionsClone = (0, _cloneDeep.default)(options);
|
|
61
55
|
return (0, _defaultsDeep.default)(optionsClone, defaultOptionsClone);
|
|
62
56
|
}
|
|
63
|
-
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
var _default = Config;
|
|
67
59
|
exports.default = _default;
|
package/EbookConvert.js
CHANGED
|
@@ -1,49 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
|
|
5
4
|
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
6
|
-
|
|
7
5
|
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
8
|
-
|
|
9
6
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
10
|
-
|
|
11
7
|
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
12
|
-
|
|
13
8
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
14
|
-
|
|
15
9
|
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
16
|
-
|
|
17
10
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
18
|
-
|
|
19
11
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
20
|
-
|
|
21
12
|
_Object$defineProperty(exports, "__esModule", {
|
|
22
13
|
value: true
|
|
23
14
|
});
|
|
24
|
-
|
|
25
15
|
exports.default = void 0;
|
|
26
|
-
|
|
27
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
28
|
-
|
|
29
17
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
30
|
-
|
|
31
18
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
32
|
-
|
|
33
19
|
var _path = _interopRequireDefault(require("path"));
|
|
34
|
-
|
|
35
20
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
36
|
-
|
|
37
21
|
var _child_process = require("child_process");
|
|
38
|
-
|
|
39
22
|
var _commandExists = _interopRequireDefault(require("command-exists"));
|
|
40
|
-
|
|
41
23
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
42
|
-
|
|
43
24
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
44
|
-
|
|
45
25
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty2(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
46
|
-
|
|
47
26
|
const command = 'ebook-convert';
|
|
48
27
|
const defaults = {
|
|
49
28
|
inputPath: null,
|
|
@@ -53,19 +32,16 @@ const defaults = {
|
|
|
53
32
|
fileName: new Date().toISOString().replace(/:/g, '-'),
|
|
54
33
|
flags: []
|
|
55
34
|
};
|
|
56
|
-
|
|
57
35
|
function checkForCalibre() {
|
|
58
36
|
return new _promise.default((resolve, reject) => {
|
|
59
37
|
(0, _commandExists.default)(command, (err, ok) => {
|
|
60
38
|
if (err || !ok) {
|
|
61
39
|
return reject(new Error("Error: calibre's ebook-convert must be installed. Download calibre here: https://calibre-ebook.com/"));
|
|
62
40
|
}
|
|
63
|
-
|
|
64
41
|
resolve();
|
|
65
42
|
});
|
|
66
43
|
});
|
|
67
44
|
}
|
|
68
|
-
|
|
69
45
|
function convertDocument({
|
|
70
46
|
inputPath,
|
|
71
47
|
bookPath,
|
|
@@ -82,7 +58,6 @@ function convertDocument({
|
|
|
82
58
|
});
|
|
83
59
|
});
|
|
84
60
|
}
|
|
85
|
-
|
|
86
61
|
function convert(options) {
|
|
87
62
|
const props = ['inputPath', 'outputPath', 'fileType'];
|
|
88
63
|
(0, _forEach.default)(props).call(props, prop => {
|
|
@@ -90,14 +65,11 @@ function convert(options) {
|
|
|
90
65
|
throw new Error(`Missing required option [${prop}]`);
|
|
91
66
|
}
|
|
92
67
|
});
|
|
93
|
-
|
|
94
68
|
const settings = _objectSpread(_objectSpread({}, defaults), options);
|
|
95
|
-
|
|
96
69
|
const bookName = `${settings.fileName}.${settings.fileType.replace(/^\./, '')}`;
|
|
97
70
|
settings.bookPath = `"${_path.default.resolve(settings.outputPath, bookName)}"`;
|
|
98
71
|
return checkForCalibre().then(() => convertDocument(settings)).catch(_bBerLogger.default.error);
|
|
99
72
|
}
|
|
100
|
-
|
|
101
73
|
var _default = {
|
|
102
74
|
convert
|
|
103
75
|
};
|
package/GuideItem.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
|
|
9
7
|
exports.default = void 0;
|
|
10
|
-
|
|
11
8
|
class GuideItem {
|
|
12
9
|
constructor({
|
|
13
10
|
fileName,
|
|
@@ -18,8 +15,6 @@ class GuideItem {
|
|
|
18
15
|
this.title = title;
|
|
19
16
|
this.type = type;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
var _default = GuideItem;
|
|
25
20
|
exports.default = _default;
|
package/Html.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
|
|
9
7
|
exports.default = void 0;
|
|
10
|
-
|
|
11
8
|
class Html {
|
|
12
9
|
static comment(str) {
|
|
13
10
|
return `\n<!-- ${str} -->\n`;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
static escape(str) {
|
|
17
13
|
const str_ = typeof str !== 'string' ? String(str) : str;
|
|
18
14
|
const map = {
|
|
@@ -24,8 +20,6 @@ class Html {
|
|
|
24
20
|
};
|
|
25
21
|
return str_.replace(/[&<>"']/g, m => map[m]);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
var _default = Html;
|
|
31
25
|
exports.default = _default;
|
package/HtmlToXml.js
CHANGED
|
@@ -1,40 +1,26 @@
|
|
|
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 _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
14
|
-
|
|
15
10
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
16
|
-
|
|
17
11
|
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
18
|
-
|
|
19
12
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
20
|
-
|
|
21
13
|
var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
|
|
22
|
-
|
|
23
14
|
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
24
|
-
|
|
25
15
|
var _path = _interopRequireDefault(require("path"));
|
|
26
|
-
|
|
27
16
|
var _htmlparser = require("htmlparser2");
|
|
28
|
-
|
|
29
17
|
var _State = _interopRequireDefault(require("./State"));
|
|
30
|
-
|
|
31
18
|
class HtmlToXmlParser {
|
|
32
19
|
constructor({
|
|
33
20
|
content,
|
|
34
21
|
onEndCallback
|
|
35
22
|
}) {
|
|
36
23
|
var _context, _context2, _context3, _context4;
|
|
37
|
-
|
|
38
24
|
this.customElementNames = {
|
|
39
25
|
pullquote: true,
|
|
40
26
|
blockquote: true,
|
|
@@ -160,67 +146,51 @@ class HtmlToXmlParser {
|
|
|
160
146
|
this.onclosetag = (0, _bind.default)(_context3 = this.onclosetag).call(_context3, this);
|
|
161
147
|
this.onend = (0, _bind.default)(_context4 = this.onend).call(_context4, this);
|
|
162
148
|
}
|
|
163
|
-
|
|
164
149
|
writePageBreak() {
|
|
165
150
|
this.output += '<pagebreak></pagebreak>';
|
|
166
151
|
}
|
|
167
|
-
|
|
168
152
|
writeXMLDeclaration() {
|
|
169
153
|
this.output += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
170
154
|
}
|
|
171
|
-
|
|
172
155
|
renameAttribute(name, attribute) {
|
|
173
156
|
if (!this.elementAttributeNames[name]) return attribute;
|
|
174
157
|
return this.elementAttributeNames[name][attribute] || attribute;
|
|
175
158
|
}
|
|
176
|
-
|
|
177
159
|
transformAttributeValue(name, attribute, value) {
|
|
178
160
|
if (!this.elementAttributeTransformers[name] || !this.elementAttributeTransformers[name][attribute]) {
|
|
179
161
|
return value;
|
|
180
162
|
}
|
|
181
|
-
|
|
182
163
|
return this.elementAttributeTransformers[name][attribute](value);
|
|
183
164
|
}
|
|
184
|
-
|
|
185
165
|
writeTagOpen(name, attributes = {}) {
|
|
186
166
|
var _context5;
|
|
187
|
-
|
|
188
167
|
let tag = [name];
|
|
189
168
|
tag = (0, _reduce.default)(_context5 = (0, _entries.default)(attributes)).call(_context5, (acc, [key, val]) => this.whitelistedAttributes[key] ? (0, _concat.default)(acc).call(acc, `${this.renameAttribute(name, key)}="${this.transformAttributeValue(name, key, val)}"`) : acc, tag);
|
|
190
|
-
|
|
191
169
|
if (attributes.class) {
|
|
192
170
|
const classNames = new _set.default(attributes.class.split(' '));
|
|
193
|
-
|
|
194
171
|
if (classNames.has('figure__large') && classNames.has('figure__inline') || classNames.has('gallery__item')) {
|
|
195
172
|
this.writePageBreak();
|
|
196
173
|
}
|
|
197
174
|
}
|
|
198
|
-
|
|
199
175
|
tag = tag.join(' ');
|
|
200
176
|
this.output += `<${tag}>`;
|
|
201
177
|
}
|
|
202
|
-
|
|
203
178
|
writeTagClose(name) {
|
|
204
179
|
this.output += `</${name}>`;
|
|
205
180
|
if (!this.inlineElementNames[name]) this.output += '\n';
|
|
206
181
|
}
|
|
207
|
-
|
|
208
182
|
addTag(name) {
|
|
209
183
|
this.tagList.push(name);
|
|
210
184
|
}
|
|
211
|
-
|
|
212
185
|
removeTag() {
|
|
213
186
|
return this.tagList.pop();
|
|
214
187
|
}
|
|
215
|
-
|
|
216
188
|
getTag() {
|
|
217
189
|
if (!this.tagList.length) return null;
|
|
218
190
|
return this.tagList[this.tagList.length - 1];
|
|
219
191
|
}
|
|
220
|
-
|
|
221
192
|
onopentag(name, attributes = {}) {
|
|
222
193
|
if (this.blacklistedTagNames[name]) return;
|
|
223
|
-
|
|
224
194
|
if (name === 'body') {
|
|
225
195
|
// Special case for body
|
|
226
196
|
if (attributes.class) {
|
|
@@ -239,7 +209,6 @@ class HtmlToXmlParser {
|
|
|
239
209
|
// Generic tag
|
|
240
210
|
if (attributes.class) {
|
|
241
211
|
const classNames = attributes.class.split(' ');
|
|
242
|
-
|
|
243
212
|
for (let i = 0; i < classNames.length; i++) {
|
|
244
213
|
if (this.customElementNames[classNames[i]]) {
|
|
245
214
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -248,28 +217,23 @@ class HtmlToXmlParser {
|
|
|
248
217
|
}
|
|
249
218
|
}
|
|
250
219
|
}
|
|
251
|
-
|
|
252
220
|
this.addTag(name);
|
|
253
221
|
this.writeTagOpen(name, attributes);
|
|
254
222
|
}
|
|
255
|
-
|
|
256
223
|
ontext(text) {
|
|
257
224
|
if (!(0, _trim.default)(text).call(text)) return;
|
|
258
225
|
const name = this.getTag();
|
|
259
226
|
if (!name || this.blacklistedTagNames[name]) return;
|
|
260
227
|
this.output += text;
|
|
261
228
|
}
|
|
262
|
-
|
|
263
229
|
onclosetag() {
|
|
264
230
|
const name = this.removeTag();
|
|
265
231
|
if (name) this.writeTagClose(name);
|
|
266
232
|
}
|
|
267
|
-
|
|
268
233
|
onend() {
|
|
269
234
|
this.writeTagClose('body');
|
|
270
235
|
this.onEndCallback(this.output);
|
|
271
236
|
}
|
|
272
|
-
|
|
273
237
|
parse() {
|
|
274
238
|
this.writeXMLDeclaration();
|
|
275
239
|
this.writeTagOpen('body');
|
|
@@ -284,8 +248,6 @@ class HtmlToXmlParser {
|
|
|
284
248
|
parser.write(this.content);
|
|
285
249
|
parser.end();
|
|
286
250
|
}
|
|
287
|
-
|
|
288
251
|
}
|
|
289
|
-
|
|
290
252
|
var _default = HtmlToXmlParser;
|
|
291
253
|
exports.default = _default;
|
|
@@ -1,110 +1,89 @@
|
|
|
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 _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
14
|
-
|
|
15
10
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
16
|
-
|
|
17
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
18
|
-
|
|
19
12
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
20
|
-
|
|
21
13
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
22
|
-
|
|
23
14
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
24
|
-
|
|
25
15
|
var _bBerShapesDublinCore = require("@canopycanopycanopy/b-ber-shapes-dublin-core");
|
|
26
|
-
|
|
27
16
|
// Class to detect XML media-type properties based on the content of XHTML documents
|
|
28
17
|
class ManifestItemProperties {
|
|
29
18
|
// Detect if a file is an (X)HTML document
|
|
30
19
|
static isHTML(file) {
|
|
31
20
|
var _context;
|
|
32
|
-
|
|
33
21
|
return (0, _includes.default)(_context = ManifestItemProperties.HTMLMimeTypes).call(_context, _mimeTypes.default.lookup(file.absolutePath));
|
|
34
|
-
}
|
|
35
|
-
|
|
22
|
+
}
|
|
36
23
|
|
|
24
|
+
// Detect if a file is an ePub navigation document
|
|
37
25
|
static isNav(file) {
|
|
38
26
|
return ManifestItemProperties.isHTML(file) && /^toc\./.test(file.name);
|
|
39
|
-
}
|
|
40
|
-
|
|
27
|
+
}
|
|
41
28
|
|
|
29
|
+
// Detect if an XHTML file contains JavaScript
|
|
42
30
|
static isScripted(file) {
|
|
43
|
-
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
31
|
+
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
32
|
+
|
|
33
|
+
// TODO: fixme; we need to check if the toc.xhtml is scripted, but it
|
|
44
34
|
// hasn't been written to disk yet. checking right now against the
|
|
45
35
|
// results from `state.template.dynamicTail` for now, since we know
|
|
46
36
|
// that the toc was written using that
|
|
47
37
|
// @issue: https://github.com/triplecanopy/b-ber/issues/206
|
|
48
|
-
|
|
49
38
|
if (ManifestItemProperties.isNav(file)) return true;
|
|
50
|
-
|
|
51
39
|
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
52
|
-
|
|
53
40
|
return contents.match(/<script/) !== null;
|
|
54
|
-
}
|
|
55
|
-
|
|
41
|
+
}
|
|
56
42
|
|
|
43
|
+
// Detect if an XHTML file contains SVG
|
|
57
44
|
static isSVG(file) {
|
|
58
45
|
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
59
|
-
|
|
60
46
|
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
61
|
-
|
|
62
47
|
return contents.match(/<svg/) !== null;
|
|
63
|
-
}
|
|
64
|
-
|
|
48
|
+
}
|
|
65
49
|
|
|
50
|
+
// Detect if a term is a Dublin Core `element`
|
|
66
51
|
static isDCElement(data) {
|
|
67
52
|
return (0, _has.default)(data, 'term') && (0, _indexOf.default)(_bBerShapesDublinCore.elements).call(_bBerShapesDublinCore.elements, data.term) > -1;
|
|
68
|
-
}
|
|
69
|
-
|
|
53
|
+
}
|
|
70
54
|
|
|
55
|
+
// Detect if a term is a Dublin Core `term`
|
|
71
56
|
static isDCTerm(data) {
|
|
72
57
|
return (0, _has.default)(data, 'term') && (0, _indexOf.default)(_bBerShapesDublinCore.terms).call(_bBerShapesDublinCore.terms, data.term) > -1;
|
|
73
|
-
}
|
|
74
|
-
|
|
58
|
+
}
|
|
75
59
|
|
|
60
|
+
// Detect if an XHTML file contains remote resources
|
|
76
61
|
static hasRemoteResources(file) {
|
|
77
62
|
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
78
|
-
|
|
79
63
|
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
80
|
-
|
|
81
64
|
return contents.match(/src=(?:['"]{1})?(?:http|\/\/)/) !== null;
|
|
82
|
-
}
|
|
83
|
-
|
|
65
|
+
}
|
|
84
66
|
|
|
67
|
+
// Test if an XHTML file is a navigation document, contains JavaScript or SVG
|
|
85
68
|
static testHTML(file) {
|
|
86
69
|
const props = [];
|
|
87
70
|
if (ManifestItemProperties.isNav(file)) props.push('nav');
|
|
88
71
|
if (ManifestItemProperties.isScripted(file)) props.push('scripted');
|
|
89
72
|
if (ManifestItemProperties.isSVG(file)) props.push('svg');
|
|
90
|
-
|
|
91
73
|
if (ManifestItemProperties.hasRemoteResources(file)) {
|
|
92
74
|
props.push('remote-resources');
|
|
93
75
|
}
|
|
94
|
-
|
|
95
76
|
return props;
|
|
96
|
-
}
|
|
97
|
-
|
|
77
|
+
}
|
|
98
78
|
|
|
79
|
+
// Test if an object contains Dublin Core `term`s or `element`s
|
|
99
80
|
static testMeta(data) {
|
|
100
81
|
return {
|
|
101
82
|
term: ManifestItemProperties.isDCTerm(data),
|
|
102
83
|
element: ManifestItemProperties.isDCElement(data)
|
|
103
84
|
};
|
|
104
85
|
}
|
|
105
|
-
|
|
106
86
|
}
|
|
107
|
-
|
|
108
87
|
(0, _defineProperty2.default)(ManifestItemProperties, "HTMLMimeTypes", ['text/html', 'application/xhtml+xml']);
|
|
109
88
|
var _default = ManifestItemProperties;
|
|
110
89
|
exports.default = _default;
|
package/Spine.js
CHANGED
|
@@ -1,69 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$keys2 = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
|
|
5
4
|
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
6
|
-
|
|
7
5
|
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
8
|
-
|
|
9
6
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
10
|
-
|
|
11
7
|
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
12
|
-
|
|
13
8
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
14
|
-
|
|
15
9
|
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
16
|
-
|
|
17
10
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
18
|
-
|
|
19
11
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
20
|
-
|
|
21
12
|
_Object$defineProperty(exports, "__esModule", {
|
|
22
13
|
value: true
|
|
23
14
|
});
|
|
24
|
-
|
|
25
15
|
exports.default = void 0;
|
|
26
|
-
|
|
27
16
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
|
28
|
-
|
|
17
|
+
var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectDestructuringEmpty"));
|
|
29
18
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
30
|
-
|
|
31
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
32
|
-
|
|
33
20
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
|
|
34
|
-
|
|
35
21
|
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/entries"));
|
|
36
|
-
|
|
37
22
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
38
|
-
|
|
39
23
|
var _entries2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
40
|
-
|
|
41
24
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
42
|
-
|
|
43
25
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
44
|
-
|
|
45
26
|
var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
46
|
-
|
|
47
27
|
var _path = _interopRequireDefault(require("path"));
|
|
48
|
-
|
|
49
28
|
var _glob = _interopRequireDefault(require("glob"));
|
|
50
|
-
|
|
51
29
|
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
52
|
-
|
|
53
30
|
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
54
|
-
|
|
55
31
|
var _difference = _interopRequireDefault(require("lodash/difference"));
|
|
56
|
-
|
|
57
32
|
var _YamlAdaptor = _interopRequireDefault(require("./YamlAdaptor"));
|
|
58
|
-
|
|
59
33
|
var _SpineItem = _interopRequireDefault(require("./SpineItem"));
|
|
60
|
-
|
|
61
34
|
const _excluded = ["nodes"];
|
|
62
|
-
|
|
63
35
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys2(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
64
|
-
|
|
65
36
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
66
|
-
|
|
67
37
|
class Spine {
|
|
68
38
|
constructor({
|
|
69
39
|
src,
|
|
@@ -76,7 +46,6 @@ class Spine {
|
|
|
76
46
|
this.navigationConfigFile = navigationConfigFile;
|
|
77
47
|
this.entries = this.create();
|
|
78
48
|
this.nested = this.build((0, _entries.default)(this)); // nested navigation
|
|
79
|
-
|
|
80
49
|
this.flattened = this.flattenNodes(this.nested); // one-dimensional page flow
|
|
81
50
|
}
|
|
82
51
|
|
|
@@ -86,34 +55,32 @@ class Spine {
|
|
|
86
55
|
} = this;
|
|
87
56
|
return (0, _reduce.default)(entries).call(entries, (acc, curr, index) => {
|
|
88
57
|
// create new spine item
|
|
89
|
-
let node;
|
|
58
|
+
let node;
|
|
59
|
+
// check if it either has nested entries or attributes that have
|
|
90
60
|
// been assigned in the yaml file
|
|
91
|
-
|
|
92
61
|
if ((0, _isPlainObject.default)(curr)) {
|
|
93
62
|
// we know that nested navigation is wrapped in a `section`
|
|
94
63
|
// object so we check against that
|
|
95
64
|
const {
|
|
96
65
|
section
|
|
97
66
|
} = curr;
|
|
98
|
-
|
|
99
67
|
if (section) {
|
|
100
68
|
// curr has nested navigation. attach the nodes to the
|
|
101
69
|
// previous entry in the tree by querying the last index
|
|
102
70
|
let _index = 0;
|
|
103
|
-
|
|
104
71
|
while ((0, _isUndefined.default)(acc[index - _index]) && _index !== acc.length) {
|
|
105
72
|
_index += 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
73
|
+
}
|
|
108
74
|
|
|
75
|
+
// add the nodes recursively and return the tree
|
|
109
76
|
acc[index - _index].nodes = this.build(section);
|
|
110
77
|
return acc;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const [[fileName, _ref]] = (0, _entries2.default)(curr); // also set frontmatter for easy access later
|
|
78
|
+
}
|
|
115
79
|
|
|
116
|
-
|
|
80
|
+
// curr has attributes
|
|
81
|
+
const [[fileName, _ref]] = (0, _entries2.default)(curr);
|
|
82
|
+
// also set frontmatter for easy access later
|
|
83
|
+
const options = (0, _extends2.default)({}, ((0, _objectDestructuringEmpty2.default)(_ref), _ref));
|
|
117
84
|
this.frontMatter.set(fileName, {});
|
|
118
85
|
node = new _SpineItem.default(_objectSpread({
|
|
119
86
|
fileName,
|
|
@@ -121,59 +88,48 @@ class Spine {
|
|
|
121
88
|
}, options));
|
|
122
89
|
} else {
|
|
123
90
|
// just a plain file name
|
|
124
|
-
const fileName = curr;
|
|
125
|
-
|
|
91
|
+
const fileName = curr;
|
|
92
|
+
// also set frontmatter for easy access later
|
|
126
93
|
this.frontMatter.set(fileName, {});
|
|
127
94
|
node = new _SpineItem.default({
|
|
128
95
|
fileName,
|
|
129
96
|
buildType
|
|
130
97
|
});
|
|
131
98
|
}
|
|
132
|
-
|
|
133
99
|
return (0, _concat.default)(acc).call(acc, node);
|
|
134
100
|
}, []);
|
|
135
101
|
}
|
|
136
|
-
|
|
137
102
|
flattenNodes(arr) {
|
|
138
103
|
return (0, _reduce.default)(arr).call(arr, (acc, curr) => {
|
|
139
104
|
const {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
105
|
+
nodes
|
|
106
|
+
} = curr,
|
|
107
|
+
rest = (0, _objectWithoutProperties2.default)(curr, _excluded);
|
|
143
108
|
const acc_ = (0, _concat.default)(acc).call(acc, rest);
|
|
144
109
|
return nodes && nodes.length ? (0, _concat.default)(acc_).call(acc_, this.flattenNodes(nodes)) : acc_;
|
|
145
110
|
}, []);
|
|
146
111
|
}
|
|
147
|
-
|
|
148
112
|
flattenYAML(data = []) {
|
|
149
113
|
return (0, _reduce.default)(data).call(data, (acc, curr) => {
|
|
150
114
|
if ((0, _isPlainObject.default)(curr)) {
|
|
151
115
|
if ((0, _keys.default)(curr)[0] === 'section') {
|
|
152
116
|
return (0, _concat.default)(acc).call(acc, this.flattenYAML(curr.section));
|
|
153
117
|
}
|
|
154
|
-
|
|
155
118
|
return (0, _concat.default)(acc).call(acc, (0, _keys.default)(curr)[0]);
|
|
156
119
|
}
|
|
157
|
-
|
|
158
120
|
return (0, _concat.default)(acc).call(acc, curr);
|
|
159
121
|
}, []);
|
|
160
122
|
}
|
|
161
|
-
|
|
162
123
|
create() {
|
|
163
124
|
var _context;
|
|
164
|
-
|
|
165
125
|
const pattern = _path.default.resolve(this.src, '_markdown', '*.md');
|
|
166
|
-
|
|
167
126
|
const declaredFiles = _YamlAdaptor.default.load(this.navigationConfigFile);
|
|
168
|
-
|
|
169
127
|
const flattenedFiles = this.flattenYAML(declaredFiles);
|
|
170
128
|
const systemFileNames = (0, _map2.default)(_context = _glob.default.sync(pattern)).call(_context, file => _path.default.basename(file, '.md'));
|
|
171
129
|
const missingEntries = (0, _difference.default)(systemFileNames, flattenedFiles);
|
|
172
130
|
const entries = (0, _concat.default)(declaredFiles).call(declaredFiles, missingEntries);
|
|
173
131
|
return entries;
|
|
174
132
|
}
|
|
175
|
-
|
|
176
133
|
}
|
|
177
|
-
|
|
178
134
|
var _default = Spine;
|
|
179
135
|
exports.default = _default;
|