mirror of
https://github.com/vinta/awesome-python.git
synced 2026-05-09 22:53:49 +08:00
feat(website): add slug and url to subcategory entries
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+8
-2
@@ -11,7 +11,7 @@ from pathlib import Path
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from readme_parser import ParsedGroup, ParsedSection, parse_readme, parse_sponsors
|
from readme_parser import ParsedGroup, ParsedSection, parse_readme, parse_sponsors, slugify
|
||||||
|
|
||||||
GITHUB_REPO_URL_RE = re.compile(r"^https?://github\.com/([^/]+/[^/]+?)(?:\.git)?/?$")
|
GITHUB_REPO_URL_RE = re.compile(r"^https?://github\.com/([^/]+/[^/]+?)(?:\.git)?/?$")
|
||||||
MARKDOWN_LINK_RE = re.compile(r"\[[^\]]+\]\(([^)\s]+)\)")
|
MARKDOWN_LINK_RE = re.compile(r"\[[^\]]+\]\(([^)\s]+)\)")
|
||||||
@@ -243,7 +243,13 @@ def extract_entries(
|
|||||||
if subcat:
|
if subcat:
|
||||||
scoped = f"{cat['name']} > {subcat}"
|
scoped = f"{cat['name']} > {subcat}"
|
||||||
if not any(s["value"] == scoped for s in existing["subcategories"]):
|
if not any(s["value"] == scoped for s in existing["subcategories"]):
|
||||||
existing["subcategories"].append({"name": subcat, "value": scoped})
|
sub_slug = slugify(subcat)
|
||||||
|
existing["subcategories"].append({
|
||||||
|
"name": subcat,
|
||||||
|
"value": scoped,
|
||||||
|
"slug": sub_slug,
|
||||||
|
"url": f"/categories/{cat['slug']}/{sub_slug}/",
|
||||||
|
})
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -714,6 +714,36 @@ class TestExtractEntries:
|
|||||||
entries = extract_entries(categories, groups)
|
entries = extract_entries(categories, groups)
|
||||||
assert entries[0]["source_type"] == "Built-in"
|
assert entries[0]["source_type"] == "Built-in"
|
||||||
|
|
||||||
|
def test_subcategory_includes_slug_and_url(self):
|
||||||
|
readme = textwrap.dedent("""\
|
||||||
|
# T
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Tools**
|
||||||
|
|
||||||
|
## Web Frameworks
|
||||||
|
|
||||||
|
- Synchronous
|
||||||
|
|
||||||
|
- [django](https://example.com/django) - A framework.
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Done.
|
||||||
|
""")
|
||||||
|
groups = parse_readme(readme)
|
||||||
|
categories = [c for g in groups for c in g["categories"]]
|
||||||
|
entries = extract_entries(categories, groups)
|
||||||
|
assert entries[0]["subcategories"] == [
|
||||||
|
{
|
||||||
|
"name": "Synchronous",
|
||||||
|
"value": "Web Frameworks > Synchronous",
|
||||||
|
"slug": "synchronous",
|
||||||
|
"url": "/categories/web-frameworks/synchronous/",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# annotate_entries_with_stars
|
# annotate_entries_with_stars
|
||||||
|
|||||||
Reference in New Issue
Block a user