mirror of
https://github.com/comeonzhj/Auto-Redbook-Skills.git
synced 2026-03-27 12:49:27 +08:00
feat: optimize cover title font size dynamic adjustment
This commit is contained in:
@@ -148,12 +148,20 @@ def generate_cover_html(metadata: dict, theme: str, width: int, height: int) ->
|
|||||||
title = metadata.get('title', '标题')
|
title = metadata.get('title', '标题')
|
||||||
subtitle = metadata.get('subtitle', '')
|
subtitle = metadata.get('subtitle', '')
|
||||||
|
|
||||||
# 限制标题和副标题长度
|
|
||||||
if len(title) > 15:
|
|
||||||
title = title[:15]
|
|
||||||
if len(subtitle) > 15:
|
|
||||||
subtitle = subtitle[:15]
|
|
||||||
|
|
||||||
|
# 动态调整标题字体大小
|
||||||
|
title_len = len(title)
|
||||||
|
if title_len <= 6:
|
||||||
|
title_size = int(width * 0.14) # 极大
|
||||||
|
elif title_len <= 10:
|
||||||
|
title_size = int(width * 0.12) # 大
|
||||||
|
elif title_len <= 18:
|
||||||
|
title_size = int(width * 0.09) # 中
|
||||||
|
elif title_len <= 30:
|
||||||
|
title_size = int(width * 0.07) # 小
|
||||||
|
else:
|
||||||
|
title_size = int(width * 0.055) # 极小
|
||||||
|
|
||||||
# 获取主题背景色
|
# 获取主题背景色
|
||||||
theme_backgrounds = {
|
theme_backgrounds = {
|
||||||
'default': 'linear-gradient(180deg, #f3f3f3 0%, #f9f9f9 100%)',
|
'default': 'linear-gradient(180deg, #f3f3f3 0%, #f9f9f9 100%)',
|
||||||
@@ -231,7 +239,7 @@ def generate_cover_html(metadata: dict, theme: str, width: int, height: int) ->
|
|||||||
|
|
||||||
.cover-title {{
|
.cover-title {{
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
font-size: {int(width * 0.12)}px;
|
font-size: {title_size}px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
background: {title_bg};
|
background: {title_bg};
|
||||||
-webkit-background-clip: text;
|
-webkit-background-clip: text;
|
||||||
|
|||||||
@@ -295,12 +295,20 @@ def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
|
|||||||
title = metadata.get('title', '标题')
|
title = metadata.get('title', '标题')
|
||||||
subtitle = metadata.get('subtitle', '')
|
subtitle = metadata.get('subtitle', '')
|
||||||
|
|
||||||
# 限制标题和副标题长度
|
|
||||||
if len(title) > 15:
|
|
||||||
title = title[:15]
|
|
||||||
if len(subtitle) > 15:
|
|
||||||
subtitle = subtitle[:15]
|
|
||||||
|
|
||||||
|
# 动态调整标题字体大小
|
||||||
|
title_len = len(title)
|
||||||
|
if title_len <= 6:
|
||||||
|
title_size = 150 # 极大 (width * 0.14)
|
||||||
|
elif title_len <= 10:
|
||||||
|
title_size = 130 # 大 (width * 0.12)
|
||||||
|
elif title_len <= 18:
|
||||||
|
title_size = 100 # 中 (width * 0.09)
|
||||||
|
elif title_len <= 30:
|
||||||
|
title_size = 80 # 小 (width * 0.07)
|
||||||
|
else:
|
||||||
|
title_size = 60 # 极小 (width * 0.055)
|
||||||
|
|
||||||
# 暗黑模式特殊处理
|
# 暗黑模式特殊处理
|
||||||
is_dark = style_key == "dark"
|
is_dark = style_key == "dark"
|
||||||
text_color = "#ffffff" if is_dark else "#000000"
|
text_color = "#ffffff" if is_dark else "#000000"
|
||||||
@@ -335,7 +343,7 @@ def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
|
|||||||
}}
|
}}
|
||||||
.cover-emoji {{ font-size: 180px; line-height: 1.2; margin-bottom: 50px; }}
|
.cover-emoji {{ font-size: 180px; line-height: 1.2; margin-bottom: 50px; }}
|
||||||
.cover-title {{
|
.cover-title {{
|
||||||
font-weight: 900; font-size: 130px; line-height: 1.4;
|
font-weight: 900; font-size: {title_size}px; line-height: 1.4;
|
||||||
background: {title_gradient};
|
background: {title_gradient};
|
||||||
-webkit-background-clip: text;
|
-webkit-background-clip: text;
|
||||||
-webkit-text-fill-color: transparent;
|
-webkit-text-fill-color: transparent;
|
||||||
|
|||||||
Reference in New Issue
Block a user