Skip to content

Commit 3174ecb

Browse files
committed
💄 style(template): 优化 Markdown 模板渲染的空白符处理
- 【scripts/sync_stars.py】为 Jinja2 环境启用 `trim_blocks` 和 `lstrip_blocks`,以自动管理模板块周围的空白符。 - 【templates/stars.md.j2】移除模板中显式的空白符控制标记 (`-%}` 和 `{%-`),并调整部分行间距。 - 确保生成的 Markdown 文件具有更一致和美观的格式,避免不必要的空行和多余空格。
1 parent 8fe0acf commit 3174ecb

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

scripts/sync_stars.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ def summarize(self, repo_name: str, description: str, readme: str) -> dict:
314314

315315
class TemplateGenerator:
316316
def __init__(self, template_dir: Path):
317-
self.env = Environment(loader=FileSystemLoader(str(template_dir)))
317+
self.env = Environment(
318+
loader=FileSystemLoader(str(template_dir)),
319+
trim_blocks=True,
320+
lstrip_blocks=True,
321+
)
318322

319323
def render(self, template_name: str, context: dict) -> str:
320324
template = self.env.get_template(template_name)

templates/stars.md.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
---
66

77
## 📑 Index
8-
{% for repo in repos -%}
8+
{% for repo in repos %}
99
- [[#{{ repo.full_name }}|{{ repo.full_name }}]]
10-
{%- endfor %}
10+
{% endfor %}
1111

1212
---
1313

@@ -17,13 +17,13 @@
1717
> [!info]
1818
> ⭐ {{ "{:,}".format(repo.stars) }} · {{ repo.language or "Unknown" }} · {{ repo.updated_at }}
1919
> [GitHub]({{ repo.url }}){% if repo.homepage %} · [Website]({{ repo.homepage }}){% endif %}
20-
> {% set ai_tags = repo.summary.tags or [] %}
21-
> {% set topics = repo.topics or [] %}
20+
{% set ai_tags = repo.summary.tags or [] %}
21+
{% set topics = repo.topics or [] %}
2222
> {% for t in ai_tags %}`#{{ t }}` {% endfor %}{% for t in topics %}`#{{ t }}` {% endfor %}
2323

2424
> {{ repo.summary.zh | trim }}
25-
2625
{% if repo.description %}
26+
2727
> <sub>{{ repo.description | trim }}</sub>
2828
{% endif %}
2929

0 commit comments

Comments
 (0)