Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,31 @@ def render_language_pages(
f'<span class="muted">{html.escape(issue["repo"])}, opened {issue["created"]}</span></li>'
for issue in items[:LANGUAGE_PAGE_LIMIT]
]
structured = {
"@context": "https://schema.org",
"@type": "CollectionPage",
"name": f"Beginner {language} issues",
"url": url,
"dateModified": generated_at,
"isPartOf": {"@type": "WebSite", "name": "Open Source Radar", "url": SITE_URL},
"breadcrumb": {
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Open Source Radar", "item": SITE_URL},
{"@type": "ListItem", "position": 2, "name": f"Beginner {language} issues", "item": url},
],
},
"mainEntity": {
"@type": "ItemList",
"numberOfItems": len(items),
"itemListElement": [
{"@type": "ListItem", "position": n, "url": issue["url"], "name": issue["title"]}
for n, issue in enumerate(items[:LANGUAGE_PAGE_LIMIT], 1)
],
},
}
# "</" inside a title must not close the script element early.
json_ld = json.dumps(structured, ensure_ascii=False).replace("</", "<\\/")
page = [
"<!doctype html>",
'<html lang="en">',
Expand All @@ -1206,6 +1231,7 @@ def render_language_pages(
f' <link rel="alternate" type="application/rss+xml" title="{name} beginner issues" '
f'href="../../feeds/{slug}.xml">',
' <link rel="stylesheet" href="../../assets/style.css">',
f' <script type="application/ld+json">{json_ld}</script>',
" <script>",
' try { const t = localStorage.getItem("radar-theme"); '
"if (t) document.documentElement.dataset.theme = t; } catch (e) {}",
Expand Down
6 changes: 6 additions & 0 deletions scripts/test_radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,4 +2091,10 @@ def test_writes_crawlable_page_and_sitemap_entry(self):
self.assertIn('property="og:description" content="1 open, unclaimed good first issues in C++', page)
self.assertIn("Fix &lt;docs&gt;", page)
self.assertNotIn("Hard one", page)
data = json.loads(page.split('<script type="application/ld+json">')[1].split("</script>")[0])
self.assertEqual(data["@type"], "CollectionPage")
self.assertEqual(data["mainEntity"]["numberOfItems"], 1)
self.assertEqual(data["mainEntity"]["itemListElement"][0]["url"], "https://github.com/a/b/issues/1")
self.assertEqual(data["mainEntity"]["itemListElement"][0]["name"], "Fix <docs>")
self.assertEqual(data["breadcrumb"]["itemListElement"][1]["item"], data["url"])
self.assertIn("<loc>https://tanbirramim.github.io/open-source-radar/beginner/cpp/</loc>", sitemap)
Loading