From bbbfa32263a3ce2ee2dde5fde80f91addc88dc09 Mon Sep 17 00:00:00 2001 From: liuwei Date: Sat, 21 Mar 2026 14:18:03 +0800 Subject: [PATCH] style: enhance summary hero section --- utils/markdown_to_image.py | 104 +++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/utils/markdown_to_image.py b/utils/markdown_to_image.py index ca6ba30..f2adb07 100644 --- a/utils/markdown_to_image.py +++ b/utils/markdown_to_image.py @@ -72,10 +72,22 @@ def _split_hero(html_body: str): hero_title = title_match.group(1).strip() if title_match else "聊天总结" remain = re.sub(r'

.*?

', '', html_body, count=1, flags=re.S | re.I).strip() - meta_match = re.match(r'^

(.*?)

', remain, re.S | re.I) - hero_meta = meta_match.group(1).strip() if meta_match else "群聊总结 / 自动生成" - if meta_match: - remain = re.sub(r'^

.*?

', '', remain, count=1, flags=re.S | re.I).strip() + paragraphs = re.findall(r'

(.*?)

', remain, re.S | re.I) + meta_parts = [] + used = 0 + for para in paragraphs[:3]: + clean = re.sub(r'<.*?>', '', para).strip() + if not clean: + continue + if len(clean) <= 80 or any(k in clean for k in ["群", "时间", "日期", "成员", "消息", "统计", "总结", "来源"]): + meta_parts.append(para.strip()) + used += 1 + else: + break + + hero_meta = "
".join(meta_parts) if meta_parts else "群聊总结 / 自动生成" + if used > 0: + remain = re.sub(r'^(\s*

.*?

){' + str(used) + r'}', '', remain, count=1, flags=re.S | re.I).strip() return hero_title, hero_meta, remain @@ -88,14 +100,15 @@ async def md_str_to_html_content(md_content): css = """