@canopycanopycanopy/b-ber-lib 3.0.8-nav.0 → 3.0.8-next.61
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 -2
- package/EbookConvert.js +2 -3
- package/GuideItem.js +1 -2
- package/Html.js +1 -2
- package/HtmlToXml.js +1 -2
- package/ManifestItemProperties.js +1 -2
- package/README.md +22 -4
- package/Spine.js +1 -3
- package/SpineItem.js +1 -2
- package/State.js +4 -6
- package/Template.js +1 -2
- package/Theme.js +1 -2
- package/Url.js +4 -5
- package/Yaml.js +1 -3
- package/YamlAdaptor.js +1 -2
- package/package.json +8 -8
- package/utils/index.js +14 -14
package/Config.js
CHANGED
package/EbookConvert.js
CHANGED
|
@@ -70,7 +70,6 @@ function convert(options) {
|
|
|
70
70
|
settings.bookPath = `"${_path.default.resolve(settings.outputPath, bookName)}"`;
|
|
71
71
|
return checkForCalibre().then(() => convertDocument(settings)).catch(_bBerLogger.default.error);
|
|
72
72
|
}
|
|
73
|
-
var _default = {
|
|
73
|
+
var _default = exports.default = {
|
|
74
74
|
convert
|
|
75
|
-
};
|
|
76
|
-
exports.default = _default;
|
|
75
|
+
};
|
package/GuideItem.js
CHANGED
package/Html.js
CHANGED
package/HtmlToXml.js
CHANGED
|
@@ -85,5 +85,4 @@ class ManifestItemProperties {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
(0, _defineProperty2.default)(ManifestItemProperties, "HTMLMimeTypes", ['text/html', 'application/xhtml+xml']);
|
|
88
|
-
var _default = ManifestItemProperties;
|
|
89
|
-
exports.default = _default;
|
|
88
|
+
var _default = exports.default = ManifestItemProperties;
|
package/README.md
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
# `@canopycanopycanopy/b-ber-lib`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`b-ber-lib` is the shared utility library used across the b-ber build pipeline. It provides the central `State` singleton (project configuration, spine, metadata, and src/dist path helpers), `Config` (settings merged from `config.yml`), `Spine` and `SpineItem` (ordered content navigation built from `toc.yml`), `Theme` (SCSS theme loading), and a set of lower-level helpers for URL normalisation, HTML serialisation, YAML I/O, EPUB manifest properties, and Calibre ebook conversion. Virtually every other b-ber package depends on this package.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Key exports
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
| Export | Purpose |
|
|
8
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------------ |
|
|
9
|
+
| `State` | Singleton holding full build state: config, spine, metadata, figures, footnotes, src/dist path helpers |
|
|
10
|
+
| `Config` | Constructs project config by deep-merging `config.yml` over defaults |
|
|
11
|
+
| `Spine` / `SpineItem` | Reads `toc.yml`; produces nested and flattened page-flow for each build type |
|
|
12
|
+
| `YamlAdaptor` | Loads and queries YAML files; supports comment-preserving write-back via yawn-yaml |
|
|
13
|
+
| `Html` / `HtmlToXml` | Helpers for serialising and converting HTML to XHTML |
|
|
14
|
+
| `Url` | URL normalisation utilities |
|
|
15
|
+
| `Theme` | Resolves and loads built-in or user-defined SCSS themes |
|
|
16
|
+
| `Template` | Wraps rendered body content in the XHTML page template |
|
|
17
|
+
| `ManifestItemProperties` | Derives EPUB manifest `properties` attributes from content |
|
|
18
|
+
| `GuideItem` | Represents an EPUB guide reference entry |
|
|
19
|
+
| `EbookConvert` | Shell wrapper for the Calibre `ebook-convert` binary |
|
|
20
|
+
| `utils` | Miscellaneous low-level helpers |
|
|
21
|
+
|
|
22
|
+
## Dev
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm test # jest
|
|
26
|
+
npm run build
|
|
9
27
|
```
|
package/Spine.js
CHANGED
|
@@ -48,7 +48,6 @@ class Spine {
|
|
|
48
48
|
this.nested = this.build((0, _entries.default)(this)); // nested navigation
|
|
49
49
|
this.flattened = this.flattenNodes(this.nested); // one-dimensional page flow
|
|
50
50
|
}
|
|
51
|
-
|
|
52
51
|
build(entries = []) {
|
|
53
52
|
const {
|
|
54
53
|
buildType
|
|
@@ -131,5 +130,4 @@ class Spine {
|
|
|
131
130
|
return entries;
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
|
-
var _default = Spine;
|
|
135
|
-
exports.default = _default;
|
|
133
|
+
var _default = exports.default = Spine;
|
package/SpineItem.js
CHANGED
package/State.js
CHANGED
|
@@ -42,8 +42,8 @@ var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logg
|
|
|
42
42
|
var _Yaml = _interopRequireDefault(require("./Yaml"));
|
|
43
43
|
var _Config = _interopRequireDefault(require("./Config"));
|
|
44
44
|
var _Spine = _interopRequireDefault(require("./Spine"));
|
|
45
|
-
function _toPropertyKey(
|
|
46
|
-
function _toPrimitive(
|
|
45
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
46
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[_Symbol$toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
47
47
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty2(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
48
48
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty2(_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty2(_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; } /* eslint-disable no-continue */
|
|
49
49
|
const themes = {
|
|
@@ -64,9 +64,8 @@ const skipInitialization = () => {
|
|
|
64
64
|
argv.length < 3 ||
|
|
65
65
|
// if there are insufficient arguments
|
|
66
66
|
(0, _includes.default)(argv).call(argv, 'new') // if it's a new project
|
|
67
|
-
|
|
67
|
+
;
|
|
68
68
|
};
|
|
69
|
-
|
|
70
69
|
const SRC_DIR_IMAGES = '_images';
|
|
71
70
|
const SRC_DIR_MARKDOWN = '_markdown';
|
|
72
71
|
const SRC_DIR_STYLESHEETS = '_stylesheets';
|
|
@@ -396,5 +395,4 @@ class State {
|
|
|
396
395
|
this.loadTheme();
|
|
397
396
|
}
|
|
398
397
|
}
|
|
399
|
-
var _default = new State();
|
|
400
|
-
exports.default = _default;
|
|
398
|
+
var _default = exports.default = new State();
|
package/Template.js
CHANGED
package/Theme.js
CHANGED
|
@@ -168,5 +168,4 @@ class Theme {}
|
|
|
168
168
|
}
|
|
169
169
|
return createProjectThemeDirectory(name).then(() => copyThemeAssets(theme)).then(() => updateConfig(name)).then(() => !force && _bBerLogger.default.notice(`Updated theme [${name}]`)).catch(_bBerLogger.default.error);
|
|
170
170
|
});
|
|
171
|
-
var _default = Theme;
|
|
172
|
-
exports.default = _default;
|
|
171
|
+
var _default = exports.default = Theme;
|
package/Url.js
CHANGED
|
@@ -7,7 +7,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
10
|
-
var
|
|
10
|
+
var _Url;
|
|
11
11
|
class Url {
|
|
12
12
|
static trimSlashes(url) {
|
|
13
13
|
return url.replace(/(^\/+|\/+$)/, '');
|
|
@@ -30,14 +30,13 @@ class Url {
|
|
|
30
30
|
return url_;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
_Url = Url;
|
|
34
34
|
(0, _defineProperty2.default)(Url, "removeTrailingSlash", str => {
|
|
35
35
|
if (typeof str !== 'string') return '';
|
|
36
36
|
return str.replace(/\/+$/, '');
|
|
37
37
|
});
|
|
38
38
|
(0, _defineProperty2.default)(Url, "addTrailingSlash", str => {
|
|
39
39
|
if (typeof str !== 'string' || str === '/') return '/';
|
|
40
|
-
return `${
|
|
40
|
+
return `${_Url.removeTrailingSlash(str)}/`;
|
|
41
41
|
});
|
|
42
|
-
var _default = Url;
|
|
43
|
-
exports.default = _default;
|
|
42
|
+
var _default = exports.default = Url;
|
package/Yaml.js
CHANGED
|
@@ -117,7 +117,6 @@ const interfaces = {
|
|
|
117
117
|
}
|
|
118
118
|
// TODO: fill this in with missing options
|
|
119
119
|
},
|
|
120
|
-
|
|
121
120
|
media: {}
|
|
122
121
|
};
|
|
123
122
|
function YawnAPI() {
|
|
@@ -172,5 +171,4 @@ class Yaml {
|
|
|
172
171
|
this.schema = schema;
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
|
-
var _default = Yaml;
|
|
176
|
-
exports.default = _default;
|
|
174
|
+
var _default = exports.default = Yaml;
|
package/YamlAdaptor.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-lib",
|
|
3
|
-
"version": "3.0.8-
|
|
3
|
+
"version": "3.0.8-next.61+2bbec564",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime-corejs3": "^7.10.5",
|
|
31
|
-
"@canopycanopycanopy/b-ber-logger": "3.0.8-
|
|
32
|
-
"@canopycanopycanopy/b-ber-shapes-dublin-core": "3.0.8-
|
|
33
|
-
"@canopycanopycanopy/b-ber-shapes-sequences": "3.0.8-
|
|
34
|
-
"@canopycanopycanopy/b-ber-theme-sans": "3.0.8-
|
|
35
|
-
"@canopycanopycanopy/b-ber-theme-serif": "3.0.8-
|
|
31
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.61+2bbec564",
|
|
32
|
+
"@canopycanopycanopy/b-ber-shapes-dublin-core": "3.0.8-next.61+2bbec564",
|
|
33
|
+
"@canopycanopycanopy/b-ber-shapes-sequences": "3.0.8-next.61+2bbec564",
|
|
34
|
+
"@canopycanopycanopy/b-ber-theme-sans": "3.0.8-next.61+2bbec564",
|
|
35
|
+
"@canopycanopycanopy/b-ber-theme-serif": "3.0.8-next.61+2bbec564",
|
|
36
36
|
"command-exists": "^1.2.2",
|
|
37
37
|
"fs-extra": "^8.1.0",
|
|
38
38
|
"glob": "^7.1.4",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"tar": "^6.1.11",
|
|
45
45
|
"vinyl": "^2.2.0",
|
|
46
46
|
"yargs": "^13.3.0",
|
|
47
|
-
"yawn-yaml": "
|
|
47
|
+
"yawn-yaml": "1.5.0"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"utils",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"url": "https://maxwellsimmer.com"
|
|
78
78
|
}
|
|
79
79
|
],
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "2bbec5643278f53becb0d2ba1f55edfe379d5587"
|
|
81
81
|
}
|
package/utils/index.js
CHANGED
|
@@ -27,7 +27,8 @@ var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
|
27
27
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
28
28
|
var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
|
|
29
29
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
30
|
-
var
|
|
30
|
+
var _Url = _interopRequireDefault(require("../Url"));
|
|
31
|
+
var _State = _interopRequireDefault(require("../State"));
|
|
31
32
|
// import ffprobe from 'ffprobe'
|
|
32
33
|
// import ffprobeStatic from 'ffprobe-static'
|
|
33
34
|
|
|
@@ -73,12 +74,12 @@ const getImageOrientation = (w, h) => {
|
|
|
73
74
|
exports.getImageOrientation = getImageOrientation;
|
|
74
75
|
const getTitle = page => {
|
|
75
76
|
if (page.name === 'figures-titlepage') return 'Figures';
|
|
76
|
-
const meta =
|
|
77
|
+
const meta = _State.default.spine.frontMatter.get(page.name);
|
|
77
78
|
return meta && meta.title ? meta.title : page.title || page.name;
|
|
78
79
|
};
|
|
79
80
|
exports.getTitle = getTitle;
|
|
80
81
|
const getBookMetadata = term => {
|
|
81
|
-
const entry = (0, _find.default)(
|
|
82
|
+
const entry = (0, _find.default)(_State.default.metadata.json(), {
|
|
82
83
|
term
|
|
83
84
|
});
|
|
84
85
|
if (entry && entry.value) return entry.value;
|
|
@@ -180,13 +181,13 @@ const webpubManifestReadingOrderItem = base => ({
|
|
|
180
181
|
// https://github.com/readium/webpub-manifest
|
|
181
182
|
const generateWebpubManifest = files => {
|
|
182
183
|
var _context8, _context9;
|
|
183
|
-
const remoteURL =
|
|
184
|
+
const remoteURL = _Url.default.trimSlashes(_State.default.config.remote_url);
|
|
184
185
|
|
|
185
186
|
// Build a map to sort the files according to the position in the spine
|
|
186
187
|
const fileMap = new _map2.default((0, _map.default)(files).call(files, f => [_path.default.basename(f), f]));
|
|
187
188
|
|
|
188
189
|
// Create the items for the manifest's reading order
|
|
189
|
-
const readingOrderItems = (0, _reduce.default)(_context8 =
|
|
190
|
+
const readingOrderItems = (0, _reduce.default)(_context8 = _State.default.spine.flattened).call(_context8, (acc, curr) => {
|
|
190
191
|
const file = fileMap.get(`${curr.fileName}.xhtml`);
|
|
191
192
|
return !file ? acc : (0, _concat.default)(acc).call(acc, {
|
|
192
193
|
file,
|
|
@@ -199,22 +200,21 @@ const generateWebpubManifest = files => {
|
|
|
199
200
|
'@context': 'https://readium.org/webpub-manifest/context.jsonld',
|
|
200
201
|
metadata: {
|
|
201
202
|
'@type': 'http://schema.org/Book',
|
|
202
|
-
title: getBookMetadata('title',
|
|
203
|
-
author: getBookMetadata('creator',
|
|
204
|
-
identifier: getBookMetadata('identifier',
|
|
205
|
-
language: getBookMetadata('language',
|
|
206
|
-
publisher: getBookMetadata('publisher',
|
|
203
|
+
title: getBookMetadata('title', _State.default),
|
|
204
|
+
author: getBookMetadata('creator', _State.default),
|
|
205
|
+
identifier: getBookMetadata('identifier', _State.default),
|
|
206
|
+
language: getBookMetadata('language', _State.default),
|
|
207
|
+
publisher: getBookMetadata('publisher', _State.default),
|
|
207
208
|
modified: new Date().toISOString()
|
|
208
209
|
},
|
|
209
210
|
links: [{
|
|
210
211
|
rel: 'self',
|
|
211
|
-
href: `${remoteURL}/${trimLeadingSlash(
|
|
212
|
+
href: `${remoteURL}/${trimLeadingSlash(_State.default.distDir)}/manifest.json`,
|
|
212
213
|
type: 'application/webpub+json'
|
|
213
214
|
}
|
|
214
215
|
// { rel: 'alternate', href: `${remoteURL}/publication.epub`, type: 'application/epub+zip' },
|
|
215
216
|
// { rel: 'search', href: `${remoteURL}/search{?query}`, type: 'text/html', templated: true },
|
|
216
217
|
],
|
|
217
|
-
|
|
218
218
|
readingOrder,
|
|
219
219
|
resources
|
|
220
220
|
};
|
|
@@ -224,7 +224,7 @@ const generateWebpubManifest = files => {
|
|
|
224
224
|
// b-ber-grammar-* utilities
|
|
225
225
|
exports.generateWebpubManifest = generateWebpubManifest;
|
|
226
226
|
const validatePosterImage = (asset, type) => {
|
|
227
|
-
const assetPath =
|
|
227
|
+
const assetPath = _State.default.src.images(asset);
|
|
228
228
|
if (!_fsExtra.default.existsSync(assetPath)) {
|
|
229
229
|
_bBerLogger.default.error(`bber-directives: Poster image for [${type}] does not exist`);
|
|
230
230
|
}
|
|
@@ -282,5 +282,5 @@ function ensurePoster(obj, type) {
|
|
|
282
282
|
// Add mediaType to classes
|
|
283
283
|
function ensureSupportedClassNames(obj, supported) {
|
|
284
284
|
// eslint-disable-next-line no-param-reassign
|
|
285
|
-
obj.classes += ` embed ${supported(
|
|
285
|
+
obj.classes += ` embed ${supported(_State.default.build) ? '' : 'un'}supported`;
|
|
286
286
|
}
|