feat(website): lead category meta description with real description when present, count first as fallback

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-05-03 19:57:31 +08:00
parent 2f398acefb
commit c886e470b6
3 changed files with 9 additions and 5 deletions

View File

@@ -171,8 +171,11 @@ def build_homepage_json_ld(entries: Sequence[TemplateEntry], total_categories: i
def category_meta_description(name: str, entry_count: int, description: str) -> str:
suffix = description if description else "Part of the Awesome Python catalog."
return f"Explore {entry_count} curated Python projects in {name}. {suffix}"
count_sentence = f"Explore {entry_count} curated Python projects in {name}."
if description:
lead = description if description.endswith((".", "!", "?")) else f"{description}."
return f"{lead} {count_sentence}"
return f"{count_sentence} Part of the Awesome Python catalog."
def build_category_json_ld(name: str, url: str, description: str, entries: Sequence[TemplateEntry]) -> dict:
@@ -504,6 +507,7 @@ def build(repo_root: Path) -> None:
tpl_category.render(
category=category,
category_url=category_url,
category_description=category_description,
entries=entries,
total_categories=len(categories),
category_urls=category_urls,

View File

@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block title %}{{ category.name }} Python Libraries | Awesome Python{% endblock %}
{% block description %}Explore {{ entries | length }} curated Python projects in {{ category.name }}. {% if category.description %}{{ category.description }}{% else %}Part of the Awesome Python catalog.{% endif %}{% endblock %}
{% block description %}{{ category_description }}{% endblock %}
{% block canonical_url %}{{ category_url }}{% endblock %}
{% block alternate_links %}{% endblock %}
{% block extra_head %}

View File

@@ -269,7 +269,7 @@ class TestBuild:
assert 'href="/categories/widgets/"' in index_html
assert 'data-value="Widgets"' in index_html
assert parser.title.strip() == "Widgets Python Libraries | Awesome Python"
assert parser.meta_by_name["description"] == "Explore 2 curated Python projects in Widgets. Widget libraries. Also see awesome-widgets."
assert parser.meta_by_name["description"] == "Widget libraries. Also see awesome-widgets. Explore 2 curated Python projects in Widgets."
assert parser.links_by_rel["canonical"] == "https://awesome-python.com/categories/widgets/"
assert parser.meta_by_property["og:url"] == "https://awesome-python.com/categories/widgets/"
assert '<link rel="alternate" type="text/markdown" href="/index.md" />' not in category_html
@@ -562,7 +562,7 @@ class TestBuild:
assert collection["name"] == "Widgets Python Libraries"
assert collection["@id"] == "https://awesome-python.com/categories/widgets/"
assert collection["url"] == "https://awesome-python.com/categories/widgets/"
assert collection["description"] == "Explore 2 curated Python projects in Widgets. Widget libraries."
assert collection["description"] == "Widget libraries. Explore 2 curated Python projects in Widgets."
assert collection["isPartOf"] == {"@type": "WebSite", "@id": "https://awesome-python.com/#website"}
item_list = collection["mainEntity"]