koishi-plugin-ll-mc 3.1.5 → 3.1.6
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.js +24 -6
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -357,6 +357,7 @@ async function apply(ctx, config) {
|
|
|
357
357
|
const fontsPath = import_path.default.join(messageCounterRoot, "fonts");
|
|
358
358
|
const avatarsPath = import_path.default.join(messageCounterRoot, "avatars");
|
|
359
359
|
const emptyHtmlPath = import_path.default.join(messageCounterRoot, "emptyHtml.html").replace(/\\/g, "/");
|
|
360
|
+
const templateHtmlPath = import_path.default.join(messageCounterRoot, "leaderboard-template.html").replace(/\\/g, "/");
|
|
360
361
|
const oldIconsPath = import_path.default.join(dataRoot, "messageCounterIcons");
|
|
361
362
|
const oldBarBgImgsPath = import_path.default.join(dataRoot, "messageCounterBarBgImgs");
|
|
362
363
|
await fs.mkdir(fontsPath, { recursive: true });
|
|
@@ -2559,7 +2560,7 @@ ${targetUserRecord[0].username}
|
|
|
2559
2560
|
</div>`;
|
|
2560
2561
|
}
|
|
2561
2562
|
__name(buildLeaderboardRow, "buildLeaderboardRow");
|
|
2562
|
-
function buildLeaderboardHtml(title, date, items, backgroundCss) {
|
|
2563
|
+
function buildLeaderboardHtml(title, date, items, backgroundCss, fontFaces) {
|
|
2563
2564
|
const maxCount = Math.max(1, ...items.map((item) => item.count || 0));
|
|
2564
2565
|
const rows = items.map((item, index) => buildLeaderboardRow(item, index, maxCount)).join("\n");
|
|
2565
2566
|
return `<!DOCTYPE html>
|
|
@@ -2568,6 +2569,7 @@ ${targetUserRecord[0].username}
|
|
|
2568
2569
|
<meta charset="UTF-8">
|
|
2569
2570
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
2570
2571
|
<style>
|
|
2572
|
+
${fontFaces || ""}
|
|
2571
2573
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
2572
2574
|
html, body {
|
|
2573
2575
|
width: 900px;
|
|
@@ -2576,7 +2578,7 @@ ${targetUserRecord[0].username}
|
|
|
2576
2578
|
background-color: #F5F7FA;
|
|
2577
2579
|
}
|
|
2578
2580
|
body {
|
|
2579
|
-
font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
2581
|
+
font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "NotoEmoji", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
|
|
2580
2582
|
-webkit-font-smoothing: antialiased;
|
|
2581
2583
|
}
|
|
2582
2584
|
.card {
|
|
@@ -2621,14 +2623,30 @@ ${rows}
|
|
|
2621
2623
|
if (typeof ctx.puppeteer?.page !== "function") return null;
|
|
2622
2624
|
let page;
|
|
2623
2625
|
try {
|
|
2624
|
-
|
|
2626
|
+
// 复用图表的内置字体(含纯 emoji 的 NotoEmoji),以相对路径 fonts/<file> 加载,
|
|
2627
|
+
// 所以必须把模板写到 data/messageCounter/ 目录里再用 file:// 访问,相对路径才能解析。
|
|
2628
|
+
const fontFaces = generateFontFacesCSS(["HarmonyOS_Sans_Medium.ttf", "NotoEmoji.ttf"]);
|
|
2629
|
+
const html = buildLeaderboardHtml(title, date, items, backgroundCss, fontFaces);
|
|
2625
2630
|
page = await ctx.puppeteer.page();
|
|
2626
2631
|
await page.setViewport({ width: 900, height: 400, deviceScaleFactor: 2 });
|
|
2632
|
+
const pageUrl = templateHtmlPath.includes(":") ? `file:///${templateHtmlPath}` : `file://${templateHtmlPath}`;
|
|
2627
2633
|
try {
|
|
2628
|
-
await
|
|
2629
|
-
} catch (
|
|
2630
|
-
logger.warn("
|
|
2634
|
+
await fs.writeFile(templateHtmlPath, html);
|
|
2635
|
+
} catch (writeError) {
|
|
2636
|
+
logger.warn("无法写入排行榜模板文件,改用 setContent:", writeError?.message);
|
|
2631
2637
|
}
|
|
2638
|
+
if (typeof page.goto === "function") {
|
|
2639
|
+
try {
|
|
2640
|
+
await page.goto(pageUrl, { waitUntil: "load", timeout: 20000 });
|
|
2641
|
+
} catch (e) {
|
|
2642
|
+
logger.warn("Leaderboard template goto failed, using setContent:", e?.message);
|
|
2643
|
+
await page.setContent(html, { waitUntil: "networkidle0", timeout: 20000 }).catch(() => {});
|
|
2644
|
+
}
|
|
2645
|
+
} else {
|
|
2646
|
+
await page.setContent(html, { waitUntil: "networkidle0", timeout: 20000 }).catch(() => {});
|
|
2647
|
+
}
|
|
2648
|
+
// 确保 emoji 字体就绪再截图
|
|
2649
|
+
await page.evaluate(() => document.fonts.ready).catch(() => {});
|
|
2632
2650
|
await page.waitForSelector(".card").catch(() => {});
|
|
2633
2651
|
// 背景(自定义 CSS/API 背景)是加在 html 上的,必须截整页才能把卡片外的背景一起截进来;
|
|
2634
2652
|
// body 高度由内容撑开(无 min-height),所以 fullPage 不会产生多余空白。
|