@cloud411716/fancy-webnovel 4.26.0 → 4.26.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/lib/scraper-utils.js +23 -37
- package/package.json +1 -1
- package/plugins/fancy-scan/scripts/run-scan.js +2 -3
- package/plugins/fancy-scan/scripts/scrapers/fanqie-rank-scraper.js +3 -3
- package/plugins/fancy-scan/scripts/scrapers/jjwxc-rank-scraper.js +5 -5
- package/plugins/fancy-scan/scripts/scrapers/qimao-rank-scraper.js +3 -3
package/lib/scraper-utils.js
CHANGED
|
@@ -149,55 +149,41 @@ export function sanitizeBookFields(book) {
|
|
|
149
149
|
* 番茄/晋江/七猫的"简介"没有冒号(不像 `**标签:**` 那样一眼看出是字段),
|
|
150
150
|
* 而且简介前多一个空行,跟前面的字段行断开了。
|
|
151
151
|
*
|
|
152
|
-
* 统一成一个无序列表项(2026-11-05
|
|
152
|
+
* 统一成一个无序列表项(2026-11-05 调整,2026-11-25 压缩空行):
|
|
153
153
|
*
|
|
154
|
-
* - **简介:** 首段
|
|
155
|
-
*
|
|
156
|
-
*
|
|
154
|
+
* - **简介:** 首段
|
|
155
|
+
* 第二段
|
|
156
|
+
* 第三段
|
|
157
157
|
*
|
|
158
158
|
* 规则:
|
|
159
159
|
* - 简介本身是一个 `- ` 列表项,和作者/状态/在读等字段同一层级;
|
|
160
|
-
* -
|
|
161
|
-
* -
|
|
162
|
-
* -
|
|
160
|
+
* - 连续空行(两个及以上换行,包括只含空格/全角空格的空行)一律压成单换行;
|
|
161
|
+
* - 每一行都用行尾两个空格做硬换行,简介内部不出现空行;
|
|
162
|
+
* - **每行首尾的空白字符都去掉**(半角空格 / 全角空格 / 换行)。
|
|
163
163
|
*
|
|
164
164
|
* @param {string|string[]} raw - 简介正文,或已切好的段落数组
|
|
165
165
|
* @returns {string[]} markdown 行;没有简介时返回空数组
|
|
166
166
|
*/
|
|
167
167
|
export function renderIntroLines(raw) {
|
|
168
|
-
const source = Array.isArray(raw)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// 去掉每段首尾的空白字符:\s 已含全角空格 U+3000,这里再写一遍是防它被漏
|
|
177
|
-
.map(p => String(p).replace(/^[\s ]+|[\s ]+$/g, ''))
|
|
168
|
+
const source = Array.isArray(raw) ? raw.join('\n') : String(raw == null ? '' : raw);
|
|
169
|
+
const parts = source
|
|
170
|
+
.replace(/\r\n?/g, '\n')
|
|
171
|
+
// 连续空行(含只含半角空格/制表符/全角空格的行)压成单换行。
|
|
172
|
+
// 四个平台都会把作者原文的段落分隔保留成 \n\n,这里统一成逐行硬换行。
|
|
173
|
+
.replace(/\n(?:[ \t ]*\n)+/g, '\n')
|
|
174
|
+
.split('\n')
|
|
175
|
+
.map((line) => sanitizeMarkdownLine(line.trim()))
|
|
178
176
|
.filter(Boolean);
|
|
179
|
-
if (!
|
|
177
|
+
if (!parts.length) return [];
|
|
180
178
|
|
|
181
|
-
//
|
|
182
|
-
// (番茄/起点的 <br> 转出来的)用两个尾随空格做硬换行。
|
|
179
|
+
// 简介本身是列表项;第一行紧跟标签,后续行用两个尾随空格做硬换行。
|
|
183
180
|
const lines = [];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.
|
|
189
|
-
.
|
|
190
|
-
for (let i = 0; i < parts.length; i += 1) {
|
|
191
|
-
const text = parts[i];
|
|
192
|
-
if (first) {
|
|
193
|
-
lines.push('- **简介:** ' + text);
|
|
194
|
-
first = false;
|
|
195
|
-
} else if (i === 0) {
|
|
196
|
-
lines.push('', ' ' + text);
|
|
197
|
-
} else {
|
|
198
|
-
lines[lines.length - 1] += ' ';
|
|
199
|
-
lines.push(' ' + text);
|
|
200
|
-
}
|
|
181
|
+
for (const text of parts) {
|
|
182
|
+
if (!lines.length) {
|
|
183
|
+
lines.push('- **简介:** ' + text);
|
|
184
|
+
} else {
|
|
185
|
+
lines[lines.length - 1] += ' ';
|
|
186
|
+
lines.push(' ' + text);
|
|
201
187
|
}
|
|
202
188
|
}
|
|
203
189
|
return lines;
|
package/package.json
CHANGED
|
@@ -363,9 +363,8 @@ function renderQidianMarkdown(rankLabel, url, books) {
|
|
|
363
363
|
lines.push(`- **打赏:** 今日 ${t} / 本周 ${w}`);
|
|
364
364
|
}
|
|
365
365
|
if (b.intro) {
|
|
366
|
-
//
|
|
367
|
-
//
|
|
368
|
-
// 所以按空行分段,不按单换行。
|
|
366
|
+
// 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数
|
|
367
|
+
// 统一压成单换行,四个平台保持一致。
|
|
369
368
|
lines.push(...renderIntroLines(b.intro));
|
|
370
369
|
}
|
|
371
370
|
if (b.url) lines.push(`- [作品页](${b.url})`);
|
|
@@ -832,9 +832,9 @@ function buildMarkdown(catName, books) {
|
|
|
832
832
|
if (b.wordCount) lines.push(`- **字数:** ${b.wordCount}`);
|
|
833
833
|
if (b.tags && b.tags.length) lines.push(`- **标签:** ${b.tags.join('、')}`);
|
|
834
834
|
if (b.rankChange) lines.push(`- **排名变动:** ${b.rankChange}`);
|
|
835
|
-
// 简介和其他字段一样是 `- `
|
|
836
|
-
//
|
|
837
|
-
//
|
|
835
|
+
// 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
|
|
836
|
+
// 每行用硬换行保留。之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,
|
|
837
|
+
// 且和上下文粘成一段,而且简介首尾的空白字符原样留在文件里。
|
|
838
838
|
lines.push(...renderIntroLines(b.desc || ''));
|
|
839
839
|
if (b.url) lines.push(`- [作品页](https://fanqienovel.com${b.url})`);
|
|
840
840
|
lines.push('');
|
|
@@ -191,8 +191,8 @@ async function extractRankData(page, columns = {}) {
|
|
|
191
191
|
* 1. **积分不带千分位逗号**:晋江榜单页写的是 "1,099,899,136",
|
|
192
192
|
* 存成纯数字,下游才好比较/求和,模型抄数字时也不会把逗号抄进去
|
|
193
193
|
* ("327,650,784" 和 "327650784" 在模型的算术里不是一回事);
|
|
194
|
-
* 2. **简介是 `- `
|
|
195
|
-
*
|
|
194
|
+
* 2. **简介是 `- ` 列表项**:连续空行压成单换行,每行用硬换行保留;
|
|
195
|
+
* 每行首尾无空白,作品页也单独作为一个列表项。
|
|
196
196
|
*
|
|
197
197
|
* @param {object} b - 一本书
|
|
198
198
|
* @returns {string[]} markdown 行
|
|
@@ -207,9 +207,9 @@ export function renderBookLines(raw) {
|
|
|
207
207
|
// 积分是 10 亿级的,榜单页必带千分位逗号 —— 写盘前去掉。
|
|
208
208
|
if (b.score) lines.push(`- **积分:** ${stripThousands(b.score)}`);
|
|
209
209
|
if (b.tags && b.tags.length) lines.push(`- **标签:** ${b.tags.join('、')}`);
|
|
210
|
-
// 简介和其他字段一样是 `- `
|
|
211
|
-
//
|
|
212
|
-
//
|
|
210
|
+
// 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
|
|
211
|
+
// 每行用硬换行保留。之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,
|
|
212
|
+
// 且和上下文粘成一段,而且简介首尾的空白字符原样留在文件里。
|
|
213
213
|
lines.push(...renderIntroLines(b.intro || ''));
|
|
214
214
|
if (b.novelid) lines.push(`- [作品页](https://www.jjwxc.net/onebook.php?novelid=${b.novelid})`);
|
|
215
215
|
return lines;
|
|
@@ -408,9 +408,9 @@ function renderMarkdown(ch, rt, period, url, books, rawCount, now = new Date().t
|
|
|
408
408
|
if (b.status) lines.push(`- **状态:** ${b.status}`);
|
|
409
409
|
if (b.words) lines.push(`- **字数:** ${b.words}`);
|
|
410
410
|
if (b.heat) lines.push(`- **热度:** ${b.heat}`);
|
|
411
|
-
// 简介和其他字段一样是 `- `
|
|
412
|
-
//
|
|
413
|
-
//
|
|
411
|
+
// 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
|
|
412
|
+
// 每行用硬换行保留。之前是「空行 + `**简介**` + 分段」—— 没有冒号、
|
|
413
|
+
// 前后多一个空行,而且段首尾的空白字符原样留在文件里。
|
|
414
414
|
lines.push(...renderIntroLines(cleanDesc(b.desc)));
|
|
415
415
|
// 作品页链接放在简介之后,与起点/番茄/晋江产物保持同一字段顺序。
|
|
416
416
|
if (b.url) lines.push(`- [作品页](${b.url})`);
|