wp-epub-gen 0.2.0 → 0.2.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/README.md +1 -1
- package/build/index.js +14 -8
- package/build/libs/safeFineName.d.ts +6 -0
- package/package.json +22 -22
- package/build/types.d.ts +0 -79
- package/cpi.epub +0 -0
- package/test.epub +0 -0
- /package/build/{utils.d.ts → libs/utils.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ epubGen(option).then(
|
|
|
80
80
|
- `appendChapterTitle`:
|
|
81
81
|
optional, Automatically append the chapter title at the beginning of current chapter, this value will overwrite the global `appendChapterTitles`.
|
|
82
82
|
- `verbose`:
|
|
83
|
-
specify whether
|
|
83
|
+
specify whether to console.log progress messages, default: false.
|
|
84
84
|
- `timeoutSeconds`:
|
|
85
85
|
specify timeout in seconds, `0` means no timeout, default: 0.
|
|
86
86
|
- `tocAutoNumber`:
|
package/build/index.js
CHANGED
|
@@ -43,20 +43,25 @@ const errors = {
|
|
|
43
43
|
no_title: "Title is required.",
|
|
44
44
|
no_content: "Content is required."
|
|
45
45
|
};
|
|
46
|
+
function safeFineName(name) {
|
|
47
|
+
return name.replace(/[/\\?%*:|"<>\t\r\n]/g, "_");
|
|
48
|
+
}
|
|
46
49
|
function parseContent(content, index, epubConfigs) {
|
|
47
50
|
let chapter = { ...content };
|
|
48
|
-
|
|
51
|
+
let { filename } = chapter;
|
|
52
|
+
if (!filename) {
|
|
49
53
|
let titleSlug = uslug(diacritics.remove(chapter.title || "no title"));
|
|
50
54
|
titleSlug = titleSlug.replace(/[\/\\]/g, "_");
|
|
51
55
|
chapter.href = `${index}_${titleSlug}.xhtml`;
|
|
52
56
|
chapter.filePath = path.join(epubConfigs.dir, "OEBPS", chapter.href);
|
|
53
57
|
} else {
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
filename = safeFineName(filename);
|
|
59
|
+
let is_xhtml = filename.endsWith(".xhtml");
|
|
60
|
+
chapter.href = is_xhtml ? filename : `${filename}.xhtml`;
|
|
56
61
|
if (is_xhtml) {
|
|
57
|
-
chapter.filePath = path.join(epubConfigs.dir, "OEBPS",
|
|
62
|
+
chapter.filePath = path.join(epubConfigs.dir, "OEBPS", filename);
|
|
58
63
|
} else {
|
|
59
|
-
chapter.filePath = path.join(epubConfigs.dir, "OEBPS", `${
|
|
64
|
+
chapter.filePath = path.join(epubConfigs.dir, "OEBPS", `${filename}.xhtml`);
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
chapter.id = `item_${index}`;
|
|
@@ -361,9 +366,9 @@ const writeFile = util.promisify(fs__namespace.writeFile);
|
|
|
361
366
|
const USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36";
|
|
362
367
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
363
368
|
async function fileIsStable(filename, max_wait = 3e4) {
|
|
364
|
-
let start_time = new Date().getTime();
|
|
369
|
+
let start_time = (/* @__PURE__ */ new Date()).getTime();
|
|
365
370
|
let last_size = fs__namespace.statSync(filename).size;
|
|
366
|
-
while (new Date().getTime() - start_time <= max_wait) {
|
|
371
|
+
while ((/* @__PURE__ */ new Date()).getTime() - start_time <= max_wait) {
|
|
367
372
|
await wait(1e3);
|
|
368
373
|
let size = fs__namespace.statSync(filename).size;
|
|
369
374
|
if (size === last_size)
|
|
@@ -669,12 +674,13 @@ function parseOptions(options) {
|
|
|
669
674
|
author: ["anonymous"],
|
|
670
675
|
tocTitle: "Table Of Contents",
|
|
671
676
|
appendChapterTitles: true,
|
|
672
|
-
date: new Date().toISOString(),
|
|
677
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
673
678
|
lang: "en",
|
|
674
679
|
fonts: [],
|
|
675
680
|
version: 3,
|
|
676
681
|
verbose: true,
|
|
677
682
|
timeoutSeconds: 15 * 60,
|
|
683
|
+
// 15 min
|
|
678
684
|
tocAutoNumber: false,
|
|
679
685
|
...options,
|
|
680
686
|
id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wp-epub-gen",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Epub generator.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -28,39 +28,39 @@
|
|
|
28
28
|
"archiver": "^5.3.1",
|
|
29
29
|
"cheerio": "^0.22.0",
|
|
30
30
|
"diacritics": "^1.3.0",
|
|
31
|
-
"ejs": "^3.1.
|
|
32
|
-
"entities": "^4.
|
|
33
|
-
"fs-extra": "^11.1.
|
|
31
|
+
"ejs": "^3.1.9",
|
|
32
|
+
"entities": "^4.5.0",
|
|
33
|
+
"fs-extra": "^11.1.1",
|
|
34
34
|
"mime": "^3.0.0",
|
|
35
|
-
"superagent": "^8.0
|
|
35
|
+
"superagent": "^8.1.0",
|
|
36
36
|
"uslug": "^1.0.4",
|
|
37
37
|
"uuid": "^9.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/archiver": "^5.3.
|
|
40
|
+
"@types/archiver": "^5.3.2",
|
|
41
41
|
"@types/cheerio": "^0.22.31",
|
|
42
42
|
"@types/diacritics": "^1.3.1",
|
|
43
|
-
"@types/ejs": "^3.1.
|
|
44
|
-
"@types/fs-extra": "^
|
|
43
|
+
"@types/ejs": "^3.1.2",
|
|
44
|
+
"@types/fs-extra": "^11.0.1",
|
|
45
45
|
"@types/mime": "^3.0.1",
|
|
46
|
-
"@types/superagent": "^4.1.
|
|
46
|
+
"@types/superagent": "^4.1.18",
|
|
47
47
|
"@types/uslug": "^1.0.1",
|
|
48
|
-
"@types/uuid": "^9.0.
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
50
|
-
"@typescript-eslint/parser": "^
|
|
48
|
+
"@types/uuid": "^9.0.2",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
50
|
+
"@typescript-eslint/parser": "^6.4.0",
|
|
51
51
|
"chai": "^4.3.7",
|
|
52
52
|
"cross-env": "^7.0.3",
|
|
53
|
-
"eslint": "^8.
|
|
54
|
-
"eslint-config-prettier": "^
|
|
55
|
-
"eslint-plugin-import": "^2.
|
|
53
|
+
"eslint": "^8.47.0",
|
|
54
|
+
"eslint-config-prettier": "^9.0.0",
|
|
55
|
+
"eslint-plugin-import": "^2.28.0",
|
|
56
56
|
"espower-typescript": "^10.0.1",
|
|
57
57
|
"mocha": "^10.2.0",
|
|
58
|
-
"prettier": "^
|
|
59
|
-
"ts-loader": "^9.4.
|
|
60
|
-
"tsconfig-paths": "^4.
|
|
61
|
-
"typescript": "^
|
|
62
|
-
"vite": "^4.
|
|
63
|
-
"vite-plugin-dts": "^
|
|
64
|
-
"vite-tsconfig-paths": "^4.0
|
|
58
|
+
"prettier": "^3.0.1",
|
|
59
|
+
"ts-loader": "^9.4.4",
|
|
60
|
+
"tsconfig-paths": "^4.2.0",
|
|
61
|
+
"typescript": "^5.1.6",
|
|
62
|
+
"vite": "^4.4.9",
|
|
63
|
+
"vite-plugin-dts": "^3.5.2",
|
|
64
|
+
"vite-tsconfig-paths": "^4.2.0"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/build/types.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* types.d.ts
|
|
3
|
-
* @author: oldj
|
|
4
|
-
* @homepage: https://oldj.net
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export interface IEpubImage {
|
|
8
|
-
id: string
|
|
9
|
-
url: string
|
|
10
|
-
dir: string
|
|
11
|
-
mediaType: string
|
|
12
|
-
extension: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface IEpubGenOptions {
|
|
16
|
-
title: string
|
|
17
|
-
author?: string | string[]
|
|
18
|
-
publisher?: string
|
|
19
|
-
cover: string
|
|
20
|
-
output: string
|
|
21
|
-
version?: 2 | 3
|
|
22
|
-
css?: string
|
|
23
|
-
fonts?: string[]
|
|
24
|
-
lang?: 'en'
|
|
25
|
-
tocTitle?: string
|
|
26
|
-
appendChapterTitles?: boolean // For advanced customizations: absolute path to an OPF template.
|
|
27
|
-
customOpfTemplatePath?: string // For advanced customizations: absolute path to a NCX toc template.
|
|
28
|
-
customHtmlTocTemplatePath?: string // For advanced customizations: absolute path to a HTML toc template.
|
|
29
|
-
customNcxTocTemplatePath?: string
|
|
30
|
-
content: IChapter[] // Book Chapters content. It's should be an array of objects. eg. [{title: "Chapter 1",data: "<div>..."}, {data: ""},...]
|
|
31
|
-
verbose?: boolean // specify whether or not to console.log progress messages, default: false
|
|
32
|
-
description?: string
|
|
33
|
-
date?: string
|
|
34
|
-
tmpDir?: string
|
|
35
|
-
timeoutSeconds?: number
|
|
36
|
-
tocAutoNumber?: boolean
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface IEpubData extends IEpubGenOptions {
|
|
40
|
-
id: string
|
|
41
|
-
docHeader: string
|
|
42
|
-
dir: string
|
|
43
|
-
images: IEpubImage[]
|
|
44
|
-
tmpDir: string
|
|
45
|
-
baseDir: string
|
|
46
|
-
_coverMediaType?: string
|
|
47
|
-
_coverExtension?: string
|
|
48
|
-
log: (msg: any) => void
|
|
49
|
-
content: IChapterData[]
|
|
50
|
-
timeoutSeconds: number
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface IChapter {
|
|
54
|
-
id?: string
|
|
55
|
-
title?: string
|
|
56
|
-
author?: string | string[]
|
|
57
|
-
data: string // HTML String of the chapter content. image paths should be absolute path (should start with "http" or "https"), so that they could be downloaded. With the upgrade is possible to use local images (for this the path must start with file: //)
|
|
58
|
-
excludeFromToc?: boolean // default: false
|
|
59
|
-
beforeToc?: boolean // if is shown before Table of content, such like copyright pages. default: false
|
|
60
|
-
filename?: string // specify filename for each chapter
|
|
61
|
-
url?: string
|
|
62
|
-
children?: IChapter[]
|
|
63
|
-
appendChapterTitle?: boolean
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface IChapterData extends IChapter {
|
|
67
|
-
id: string
|
|
68
|
-
href?: string
|
|
69
|
-
dir?: string
|
|
70
|
-
children: IChapterData[]
|
|
71
|
-
filePath: string
|
|
72
|
-
author: string[]
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface IOut {
|
|
76
|
-
success?: boolean
|
|
77
|
-
message?: string
|
|
78
|
-
options?: IEpubGenOptions
|
|
79
|
-
}
|
package/cpi.epub
DELETED
|
Binary file
|
package/test.epub
DELETED
|
Binary file
|
|
File without changes
|