|
@@ -5,8 +5,8 @@ import * as cheerio from "cheerio";
|
|
|
// 置换文件中的图片路径
|
|
|
async function processFiles(elmDate) {
|
|
|
const rows = elmDate.toString().split(/\n/);
|
|
|
- let htmlStr = ''
|
|
|
- for (const rowtext of rows) {
|
|
|
+ let htmlStr = "";
|
|
|
+ for (const rowtext of rows) {
|
|
|
if (
|
|
|
rowtext.includes("Images") &&
|
|
|
(rowtext.includes(".png") ||
|
|
@@ -18,7 +18,27 @@ async function processFiles(elmDate) {
|
|
|
const [imgText, imgPath, imageSrc] = match;
|
|
|
const imgRow = await searchFileByPath(imageSrc);
|
|
|
if (imgRow) {
|
|
|
- const text = rowtext.replace(imgPath, `/api/v1/epub/img/${imgRow.file_id}`);
|
|
|
+ const text = rowtext.replace(
|
|
|
+ imgPath,
|
|
|
+ `/api/v1/epub/img/${imgRow.file_id}`
|
|
|
+ );
|
|
|
+ htmlStr += text + "\n";
|
|
|
+ } else {
|
|
|
+ htmlStr += rowtext + "\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ htmlStr += rowtext + "\n";
|
|
|
+ }
|
|
|
+ } else if (rowtext.includes(".css")) {
|
|
|
+ const match = rowtext.match(/.*"(.*\/(.*\.css))/);
|
|
|
+ if (match) {
|
|
|
+ const [cssText, cssPath, cssSrc] = match;
|
|
|
+ const imgRow = await searchFileByPath(imageSrc);
|
|
|
+ if (imgRow) {
|
|
|
+ const text = rowtext.replace(
|
|
|
+ imgPath,
|
|
|
+ `/api/v1/epub/css/${imgRow.file_id}`
|
|
|
+ );
|
|
|
htmlStr += text + "\n";
|
|
|
} else {
|
|
|
htmlStr += rowtext + "\n";
|
|
@@ -30,7 +50,7 @@ async function processFiles(elmDate) {
|
|
|
htmlStr += rowtext + "\n";
|
|
|
}
|
|
|
}
|
|
|
- return Promise.resolve(htmlStr)
|
|
|
+ return Promise.resolve(htmlStr);
|
|
|
}
|
|
|
|
|
|
export async function htmlParser(epub, zipEpubExtract) {
|
|
@@ -44,7 +64,7 @@ export async function htmlParser(epub, zipEpubExtract) {
|
|
|
const elmDate = fs.readFileSync(zipEpubExtract + elm);
|
|
|
let htmlStr = await processFiles(elmDate);
|
|
|
// 修改源数据
|
|
|
- fs.writeFileSync(zipEpubExtract + elm, htmlStr)
|
|
|
+ fs.writeFileSync(zipEpubExtract + elm, htmlStr);
|
|
|
console.log(48, zipEpubExtract + elm);
|
|
|
}
|
|
|
}
|