auto-sync: 2026-06-07 13:50:55
Deploy / ci (push) Waiting to run
Deploy / deploy (push) Blocked by required conditions
Deploy / notify-deploy-failure (push) Blocked by required conditions

This commit is contained in:
cfdaily
2026-06-07 13:50:55 +08:00
parent 70f4e026f1
commit 97d2f58b53
2 changed files with 35 additions and 9 deletions
+8 -1
View File
@@ -56,6 +56,11 @@ def _load_template(name: str) -> str:
return content
def _escape_braces(value: str) -> str:
"""转义花括号防止 format_map 报错"""
return str(value).replace("{", "{{").replace("}", "}}")
def render_template(name: str, variables: Dict[str, str]) -> str:
"""渲染模板,将 {variable} 占位符替换为实际值。
@@ -69,7 +74,9 @@ def render_template(name: str, variables: Dict[str, str]) -> str:
渲染后的文本
"""
template_text = _load_template(name)
safe_vars: Dict[str, str] = defaultdict(str, variables)
# 先对所有变量值转义花括号,防止 format_map 报错
escaped_vars = {k: _escape_braces(v) for k, v in variables.items()}
safe_vars: Dict[str, str] = defaultdict(str, escaped_vars)
return template_text.format_map(safe_vars)