Skip to content

Commit ae79d28

Browse files
committed
refactor: share bilingual catalog rendering
1 parent bfeff39 commit ae79d28

5 files changed

Lines changed: 84 additions & 132 deletions

File tree

.github/CODEOWNERS

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# Default review owner
22
* @xxg1413
3-
4-
# Release, governance, and catalog policy require maintainer review.
5-
/.github/ @xxg1413
6-
/docs/CURATION_POLICY.md @xxg1413
7-
/_data/ @xxg1413

_config.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ relative_links:
4141
titles_from_headings:
4242
enabled: false
4343

44-
defaults:
45-
- scope:
46-
path: ""
47-
type: pages
48-
values:
49-
layout: default
50-
image:
51-
path: /assets/images/og-image.png
52-
width: 1200
53-
height: 630
54-
alt: FlyPython Python Resource Catalog
55-
5644
kramdown:
5745
input: GFM
5846
hard_wrap: false

_includes/catalog-grid.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<nav class="path-grid" aria-label="{% if page.lang == 'zh-CN' %}学习路径{% else %}Learning paths{% endif %}">
2+
{% for path in site.data.resources.catalog.paths %}
3+
{% assign path_resources = include.resources | where: "path", path.id %}
4+
<a class="path-card" href="#{{ path.id }}">
5+
<span class="path-number">0{{ path.order }}</span>
6+
{% if page.lang == "zh-CN" %}
7+
<strong>{{ path.title_zh }}</strong>
8+
<span>{{ path.summary_zh }}</span>
9+
<small>{{ path_resources.size }} 条资源</small>
10+
{% else %}
11+
<strong>{{ path.title_en }}</strong>
12+
<span>{{ path.summary_en }}</span>
13+
<small>{{ path_resources.size }} resources</small>
14+
{% endif %}
15+
</a>
16+
{% endfor %}
17+
</nav>
18+
19+
{% for path in site.data.resources.catalog.paths %}
20+
{% assign path_resources = include.resources | where: "path", path.id %}
21+
<section class="path-section" id="{{ path.id }}" aria-labelledby="{{ path.id }}-title">
22+
<header class="section-heading">
23+
<div>
24+
<span class="section-eyebrow">{% if page.lang == "zh-CN" %}路径{% else %}Path{% endif %} 0{{ path.order }}</span>
25+
<h2 id="{{ path.id }}-title">{% if page.lang == "zh-CN" %}{{ path.title_zh }}{% else %}{{ path.title_en }}{% endif %}</h2>
26+
</div>
27+
<p>{% if page.lang == "zh-CN" %}{{ path.summary_zh }}{% else %}{{ path.summary_en }}{% endif %}</p>
28+
</header>
29+
30+
<div class="resource-grid">
31+
{% for resource in path_resources %}
32+
<article class="resource-card{% if resource.featured %} featured{% endif %}">
33+
<div class="resource-card-header">
34+
{% if page.lang == "zh-CN" %}
35+
{% case resource.source_type %}
36+
{% when "official-docs" %}<span class="source-badge">官方文档</span>
37+
{% when "official-standard" %}<span class="source-badge">正式标准</span>
38+
{% when "official-project" %}<span class="source-badge">官方项目</span>
39+
{% endcase %}
40+
{% else %}
41+
<span class="source-badge">{{ resource.source_type | replace: "-", " " }}</span>
42+
{% endif %}
43+
{% if resource.featured %}<span class="featured-badge">{% if page.lang == "zh-CN" %}精选{% else %}Featured{% endif %}</span>{% endif %}
44+
</div>
45+
<h3><a href="{{ resource.url }}">{{ resource.title }}</a></h3>
46+
<p>{% if page.lang == "zh-CN" %}{{ resource.why_zh }}{% else %}{{ resource.why_en }}{% endif %}</p>
47+
<ul class="resource-meta" aria-label="{% if page.lang == 'zh-CN' %}资源元数据{% else %}Resource metadata{% endif %}">
48+
{% if page.lang == "zh-CN" %}
49+
{% case resource.level %}
50+
{% when "beginner" %}<li>入门</li>
51+
{% when "intermediate" %}<li>进阶</li>
52+
{% when "advanced" %}<li>高级</li>
53+
{% when "all-levels" %}<li>所有阶段</li>
54+
{% endcase %}
55+
{% case resource.language %}
56+
{% when "en" %}<li>来源语言:英语</li>
57+
{% when "zh" %}<li>来源语言:中文</li>
58+
{% when "multilingual" %}<li>来源语言:多语言</li>
59+
{% endcase %}
60+
<li>审核于 {{ resource.reviewed_on }}</li>
61+
{% else %}
62+
<li>{{ resource.level | replace: "-", " " }}</li>
63+
{% case resource.language %}
64+
{% when "en" %}<li>English</li>
65+
{% when "zh" %}<li>Chinese</li>
66+
{% when "multilingual" %}<li>Multilingual</li>
67+
{% endcase %}
68+
<li>Reviewed {{ resource.reviewed_on }}</li>
69+
{% endif %}
70+
</ul>
71+
{% if resource.requires_key or resource.risk == "medium" %}
72+
<p class="resource-caution">
73+
{% if resource.requires_key %}<span>{% if page.lang == "zh-CN" %}典型用法需要 API Key{% else %}API key required for typical use{% endif %}</span>{% endif %}
74+
{% if resource.requires_key and resource.risk == "medium" %}<span aria-hidden="true">·</span>{% endif %}
75+
{% if resource.risk == "medium" %}<span>{% if page.lang == "zh-CN" %}请检查权限与外部副作用{% else %}Review permissions and side effects{% endif %}</span>{% endif %}
76+
</p>
77+
{% endif %}
78+
</article>
79+
{% endfor %}
80+
</div>
81+
</section>
82+
{% endfor %}

index.md

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,59 +32,7 @@ source, then return to the main learning hub for guided projects and context.
3232
Primary sources first
3333
</p>
3434

35-
<nav class="path-grid" aria-label="Learning paths">
36-
{% for path in site.data.resources.catalog.paths %}
37-
{% assign path_resources = catalog_resources | where: "path", path.id %}
38-
<a class="path-card" href="#{{ path.id }}">
39-
<span class="path-number">0{{ path.order }}</span>
40-
<strong>{{ path.title_en }}</strong>
41-
<span>{{ path.summary_en }}</span>
42-
<small>{{ path_resources.size }} resources</small>
43-
</a>
44-
{% endfor %}
45-
</nav>
46-
47-
{% for path in site.data.resources.catalog.paths %}
48-
{% assign path_resources = catalog_resources | where: "path", path.id %}
49-
<section class="path-section" id="{{ path.id }}" aria-labelledby="{{ path.id }}-title">
50-
<header class="section-heading">
51-
<div>
52-
<span class="section-eyebrow">Path 0{{ path.order }}</span>
53-
<h2 id="{{ path.id }}-title">{{ path.title_en }}</h2>
54-
</div>
55-
<p>{{ path.summary_en }}</p>
56-
</header>
57-
58-
<div class="resource-grid">
59-
{% for resource in path_resources %}
60-
<article class="resource-card{% if resource.featured %} featured{% endif %}">
61-
<div class="resource-card-header">
62-
<span class="source-badge">{{ resource.source_type | replace: "-", " " }}</span>
63-
{% if resource.featured %}<span class="featured-badge">Featured</span>{% endif %}
64-
</div>
65-
<h3><a href="{{ resource.url }}">{{ resource.title }}</a></h3>
66-
<p>{{ resource.why_en }}</p>
67-
<ul class="resource-meta" aria-label="Resource metadata">
68-
<li>{{ resource.level | replace: "-", " " }}</li>
69-
{% case resource.language %}
70-
{% when "en" %}<li>English</li>
71-
{% when "zh" %}<li>Chinese</li>
72-
{% when "multilingual" %}<li>Multilingual</li>
73-
{% endcase %}
74-
<li>Reviewed {{ resource.reviewed_on }}</li>
75-
</ul>
76-
{% if resource.requires_key or resource.risk == "medium" %}
77-
<p class="resource-caution">
78-
{% if resource.requires_key %}<span>API key required for typical use</span>{% endif %}
79-
{% if resource.requires_key and resource.risk == "medium" %}<span aria-hidden="true">·</span>{% endif %}
80-
{% if resource.risk == "medium" %}<span>Review permissions and side effects</span>{% endif %}
81-
</p>
82-
{% endif %}
83-
</article>
84-
{% endfor %}
85-
</div>
86-
</section>
87-
{% endfor %}
35+
{% include catalog-grid.html resources=catalog_resources %}
8836

8937
## How this catalog relates to FlyPython
9038

zh-cn.md

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,68 +31,7 @@ FlyPython 收录官方文档、正式标准和项目的一手资源。通过四
3131
一手来源优先
3232
</p>
3333

34-
<nav class="path-grid" aria-label="学习路径">
35-
{% for path in site.data.resources.catalog.paths %}
36-
{% assign path_resources = catalog_resources | where: "path", path.id %}
37-
<a class="path-card" href="#{{ path.id }}">
38-
<span class="path-number">0{{ path.order }}</span>
39-
<strong>{{ path.title_zh }}</strong>
40-
<span>{{ path.summary_zh }}</span>
41-
<small>{{ path_resources.size }} 条资源</small>
42-
</a>
43-
{% endfor %}
44-
</nav>
45-
46-
{% for path in site.data.resources.catalog.paths %}
47-
{% assign path_resources = catalog_resources | where: "path", path.id %}
48-
<section class="path-section" id="{{ path.id }}" aria-labelledby="{{ path.id }}-title">
49-
<header class="section-heading">
50-
<div>
51-
<span class="section-eyebrow">路径 0{{ path.order }}</span>
52-
<h2 id="{{ path.id }}-title">{{ path.title_zh }}</h2>
53-
</div>
54-
<p>{{ path.summary_zh }}</p>
55-
</header>
56-
57-
<div class="resource-grid">
58-
{% for resource in path_resources %}
59-
<article class="resource-card{% if resource.featured %} featured{% endif %}">
60-
<div class="resource-card-header">
61-
{% case resource.source_type %}
62-
{% when "official-docs" %}<span class="source-badge">官方文档</span>
63-
{% when "official-standard" %}<span class="source-badge">正式标准</span>
64-
{% when "official-project" %}<span class="source-badge">官方项目</span>
65-
{% endcase %}
66-
{% if resource.featured %}<span class="featured-badge">精选</span>{% endif %}
67-
</div>
68-
<h3><a href="{{ resource.url }}">{{ resource.title }}</a></h3>
69-
<p>{{ resource.why_zh }}</p>
70-
<ul class="resource-meta" aria-label="资源元数据">
71-
{% case resource.level %}
72-
{% when "beginner" %}<li>入门</li>
73-
{% when "intermediate" %}<li>进阶</li>
74-
{% when "advanced" %}<li>高级</li>
75-
{% when "all-levels" %}<li>所有阶段</li>
76-
{% endcase %}
77-
{% case resource.language %}
78-
{% when "en" %}<li>来源语言:英语</li>
79-
{% when "zh" %}<li>来源语言:中文</li>
80-
{% when "multilingual" %}<li>来源语言:多语言</li>
81-
{% endcase %}
82-
<li>审核于 {{ resource.reviewed_on }}</li>
83-
</ul>
84-
{% if resource.requires_key or resource.risk == "medium" %}
85-
<p class="resource-caution">
86-
{% if resource.requires_key %}<span>典型用法需要 API Key</span>{% endif %}
87-
{% if resource.requires_key and resource.risk == "medium" %}<span aria-hidden="true">·</span>{% endif %}
88-
{% if resource.risk == "medium" %}<span>请检查权限与外部副作用</span>{% endif %}
89-
</p>
90-
{% endif %}
91-
</article>
92-
{% endfor %}
93-
</div>
94-
</section>
95-
{% endfor %}
34+
{% include catalog-grid.html resources=catalog_resources %}
9635

9736
## 这个目录与 FlyPython 主站的关系
9837

0 commit comments

Comments
 (0)