wp-epub-gen 0.2.0 → 0.2.1

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 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 or not to console.log progress messages, default: false.
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
- if (!chapter.filename) {
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
- let is_xhtml = chapter.filename.endsWith(".xhtml");
55
- chapter.href = is_xhtml ? chapter.filename : `${chapter.filename}.xhtml`;
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", chapter.filename);
62
+ chapter.filePath = path.join(epubConfigs.dir, "OEBPS", filename);
58
63
  } else {
59
- chapter.filePath = path.join(epubConfigs.dir, "OEBPS", `${chapter.filename}.xhtml`);
64
+ chapter.filePath = path.join(epubConfigs.dir, "OEBPS", `${filename}.xhtml`);
60
65
  }
61
66
  }
62
67
  chapter.id = `item_${index}`;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * safeFineName.ts
3
+ * @author: oldj
4
+ * @homepage: https://oldj.net
5
+ */
6
+ export default function (name: string): string;
package/cpi.epub CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-epub-gen",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Epub generator.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
File without changes