feat(html): Add HTML output format support (#143 @lekoOwO)

* feat: add HTML output format support

- Add HTML settings section to _conf_schema.json with base URL and output directory configuration
- Add HTML configuration methods to ConfigManager (get_html_output_dir, get_html_base_url, get_html_filename_format)
- Create html_template.html files for all themes (fallback to image_template.html)
- Implement generate_html_report method in ReportGenerator to save HTML and JSON files
- Update main.py to handle HTML output format and send both file and URL if base_url is configured
- Update set_output_format command to include HTML as a valid format option

Co-authored-by: lekoOwO <20151124+lekoOwO@users.noreply.github.com>

* feat: enhance JSON serialization in HTML report generation

* fix: 优化输出目录获取逻辑

---------

Co-authored-by: anthropic-code-agent[bot] <242468646+Claude@users.noreply.github.com>
Co-authored-by: lekoOwO <20151124+lekoOwO@users.noreply.github.com>
Co-authored-by: SXP-Simon <sxp20061207@163.com>
This commit is contained in:
leko
2026-03-31 20:06:57 +08:00
committed by GitHub
co-authored by lekoOwO anthropic-code-agent[bot] SXP-Simon
parent 697213826c
commit 3662ac3d75
13 changed files with 4820 additions and 39 deletions
+30 -4
View File
@@ -619,7 +619,7 @@ class GroupDailyAnalysis(Star):
pdf_path = await self.report_generator.generate_pdf_report(
analysis_result,
group_id,
avatar_url_getter=avatar_url_getter,
avatar_getter=avatar_url_getter,
nickname_getter=nickname_getter,
)
if pdf_path:
@@ -630,6 +630,31 @@ class GroupDailyAnalysis(Star):
else:
yield event.plain_result("⚠️ PDF 生成失败。")
elif output_format == "html":
html_path, json_path = await self.report_generator.generate_html_report(
analysis_result,
group_id,
avatar_url_getter=avatar_url_getter,
nickname_getter=nickname_getter,
)
if html_path:
# 发送 HTML 文件
if not await adapter.send_file(group_id, html_path):
yield event.chain_result(
[File(name=Path(html_path).name, file=html_path)]
)
# 如果配置了外链 Base URL,则也发送超链接
base_url = self.config_manager.get_html_base_url()
if base_url:
filename = Path(html_path).name
url = f"{base_url.rstrip('/')}/{filename}"
link_message = f"报告已生成: {url}"
if not await adapter.send_text(group_id, link_message):
yield event.plain_result(link_message)
else:
yield event.plain_result("⚠️ HTML 生成失败。")
else:
text_report = self.report_generator.generate_text_report(analysis_result)
if not await adapter.send_text(group_id, text_report):
@@ -640,7 +665,7 @@ class GroupDailyAnalysis(Star):
async def set_output_format(self, event: AstrMessageEvent, format_type: str = ""):
"""
设置分析报告输出格式(跨平台支持)
用法: /设置格式 [image|text|pdf]
用法: /设置格式 [image|text|pdf|html]
"""
group_id = self._get_group_id_from_event(event)
@@ -661,13 +686,14 @@ class GroupDailyAnalysis(Star):
• image - 图片格式 (默认)
• text - 文本格式
• pdf - PDF 格式 {pdf_status}
• html - HTML 格式
用法: /设置格式 [格式名称]""")
return
format_type = format_type.lower()
if format_type not in ["image", "text", "pdf"]:
yield event.plain_result("❌ 无效的格式类型,支持: image, text, pdf")
if format_type not in ["image", "text", "pdf", "html"]:
yield event.plain_result("❌ 无效的格式类型,支持: image, text, pdf, html")
return
if format_type == "pdf" and not self.config_manager.playwright_available: