koishi-plugin-cs2-update-log 2.4.0 → 2.4.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/index.d.ts +1 -0
- package/lib/index.js +12 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.Config = koishi_1.Schema.object({
|
|
|
43
43
|
})).default([]).description('推送目标列表。'),
|
|
44
44
|
brandName: koishi_1.Schema.string().default('CS2 update').description('图片顶部品牌名。'),
|
|
45
45
|
siteName: koishi_1.Schema.string().default('Github仓库').description('图片底部站点名。'),
|
|
46
|
+
author: koishi_1.Schema.string().default('BestBcz').description('图片底部显示的作者名。'),
|
|
46
47
|
picture: koishi_1.Schema.boolean().default(true).description('是否以 Puppeteer 截图长图形式推送。关闭后推送纯文本。'),
|
|
47
48
|
appendLink: koishi_1.Schema.boolean().default(true).description('图片或文本后是否附带 Steam 原文链接。'),
|
|
48
49
|
trans: koishi_1.Schema.boolean().default(false).description('是否启用 AI 翻译。关闭时推送 Steam 返回的原文。'),
|
|
@@ -204,7 +205,7 @@ function apply(ctx, config) {
|
|
|
204
205
|
const rawItems = parsed.rss?.channel?.item;
|
|
205
206
|
const items = Array.isArray(rawItems) ? rawItems : rawItems ? [rawItems] : [];
|
|
206
207
|
const parsedItems = items
|
|
207
|
-
.map(parseRssItem)
|
|
208
|
+
.map((item) => parseRssItem(item, config.author))
|
|
208
209
|
.filter((item) => !!item?.gid && !!item.title);
|
|
209
210
|
if (!parsedItems.length)
|
|
210
211
|
throw new Error('返回内容中没有有效新闻');
|
|
@@ -329,7 +330,7 @@ function apply(ctx, config) {
|
|
|
329
330
|
return buildTextMessage(news, title, bodyMarkdown, link);
|
|
330
331
|
}
|
|
331
332
|
try {
|
|
332
|
-
const cacheKey = hashCacheKey('card-image', news.item.gid, news.category, config.brandName, config.siteName, title, bodyMarkdown);
|
|
333
|
+
const cacheKey = hashCacheKey('card-image', news.item.gid, news.category, config.brandName, config.siteName, config.author, title, bodyMarkdown);
|
|
333
334
|
let png = cache.cardImages.get(cacheKey);
|
|
334
335
|
if (!png) {
|
|
335
336
|
png = await renderCard(puppeteer, news, title, bodyMarkdown);
|
|
@@ -542,7 +543,7 @@ function classifyNews(item) {
|
|
|
542
543
|
category: isUpdate ? 'update' : 'announcement',
|
|
543
544
|
};
|
|
544
545
|
}
|
|
545
|
-
function parseRssItem(item) {
|
|
546
|
+
function parseRssItem(item, author) {
|
|
546
547
|
const title = decodeHtmlEntities(readXmlText(item.title));
|
|
547
548
|
const url = readXmlText(item.link);
|
|
548
549
|
const guid = readXmlText(item.guid);
|
|
@@ -555,7 +556,7 @@ function parseRssItem(item) {
|
|
|
555
556
|
gid,
|
|
556
557
|
title,
|
|
557
558
|
url,
|
|
558
|
-
author
|
|
559
|
+
author,
|
|
559
560
|
content: readXmlText(item.description),
|
|
560
561
|
date: Number.isFinite(dateValue) ? Math.floor(dateValue / 1000) : 0,
|
|
561
562
|
};
|
|
@@ -613,11 +614,15 @@ function steamContentToMarkdown(input) {
|
|
|
613
614
|
.replace(/\[img\]([\s\S]*?)\[\/img\]/gi, '')
|
|
614
615
|
.replace(/\[previewyoutube=[^\]]+\]([\s\S]*?)\[\/previewyoutube\]/gi, '')
|
|
615
616
|
.replace(/\[list\]|\[\/list\]|\[olist\]|\[\/olist\]/gi, '\n')
|
|
616
|
-
.replace(
|
|
617
|
+
.replace(/[ \t]*\[\/p\][ \t]*\[\/\*\]/gi, '\n')
|
|
618
|
+
.replace(/^\s*\[\*\]\s*(?:\[p\]\s*)?/gim, '- ')
|
|
619
|
+
.replace(/\[\/\*\]/gi, '\n')
|
|
620
|
+
.replace(/\[p\]\s*/gi, '')
|
|
621
|
+
.replace(/[ \t]*\[\/p\]/gi, '\n')
|
|
617
622
|
.replace(/<br\s*\/?>/gi, '\n')
|
|
618
623
|
.replace(/<\/p>\s*<p>/gi, '\n\n')
|
|
619
624
|
.replace(/<\/?p>/gi, '\n');
|
|
620
|
-
output = output.replace(sectionHeadingPattern, (_, section) => `\n## [${String(section).toUpperCase()}]\n`);
|
|
625
|
+
output = output.replace(sectionHeadingPattern, (_, section) => `\n## [${String(section).trim().toUpperCase()}]\n`);
|
|
621
626
|
sectionHeadingPattern.lastIndex = 0;
|
|
622
627
|
return output
|
|
623
628
|
.replace(/\n{3,}/g, '\n\n')
|
|
@@ -652,7 +657,7 @@ function buildCardHtml(news, title, bodyMarkdown, config, assets) {
|
|
|
652
657
|
const categoryTag = news.category === 'update' ? 'UPDATE LOG' : 'ANNOUNCEMENT';
|
|
653
658
|
const rendered = markdown.render(bodyMarkdown);
|
|
654
659
|
const publishedAt = formatDate(news.item.date);
|
|
655
|
-
const author = news.item.author ||
|
|
660
|
+
const author = news.item.author || config.author;
|
|
656
661
|
return `<!doctype html>
|
|
657
662
|
<html lang="zh-CN">
|
|
658
663
|
<head>
|
package/package.json
CHANGED