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
18 changes: 18 additions & 0 deletions scripts/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,9 @@ def _write_beginner_page(
return True


NEW_THIS_WEEK_LIMIT = 15


def render_beginner_hub(
languages: dict[str, str],
topics: dict[str, str],
Expand Down Expand Up @@ -1384,6 +1387,21 @@ def links(entries: list[tuple[str, str, int]]) -> list[str]:
' <p><a href="../">Search everything on the live site</a> · <a href="../feeds/">RSS feeds</a></p>',
" </section>",
]
# Issues opened in the last 7 days, so returning visitors see what changed.
week_ago = (iso_to_datetime(generated_at) - dt.timedelta(days=7)).date().isoformat()
fresh = sorted(
(i for i in beginner if i.get("created", "") >= week_ago and i.get("url")),
key=lambda i: i["created"],
reverse=True,
)[:NEW_THIS_WEEK_LIMIT]
if fresh:
page += [' <h2 id="new">New this week</h2>', " <ul>"]
page += [
f' <li><a href="{html.escape(i["url"], quote=True)}">{html.escape(i["title"])}</a> '
f'<span class="muted">{html.escape(i["repo"])}, opened {i["created"]}</span></li>'
for i in fresh
]
page += [" </ul>"]
if language_entries:
page += [" <h2>By language</h2>", " <ul>", *links(language_entries), " </ul>"]
if topic_entries:
Expand Down
35 changes: 35 additions & 0 deletions scripts/test_radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,41 @@ def test_hub_links_every_page_with_counts_and_is_in_sitemap(self):
self.assertLess(hub.index('href="cpp/"'), hub.index('href="go/"'))
self.assertIn("<loc>https://tanbirramim.github.io/open-source-radar/beginner/</loc>", sitemap)

def test_new_this_week_lists_recent_beginner_issues(self):
import tempfile

repositories = {"a/b": {"language": "Go", "buckets": []}}
issues = [
{
"repo": "a/b",
"level": "beginner",
"created": "2026-11-07",
"title": "Fresh <one>",
"url": "https://github.com/a/b/issues/1",
},
{
"repo": "a/b",
"level": "beginner",
"created": "2026-10-20",
"title": "Old one",
"url": "https://github.com/a/b/issues/2",
},
{
"repo": "a/b",
"level": "help-wanted",
"created": "2026-11-07",
"title": "Hard one",
"url": "https://github.com/a/b/issues/3",
},
]
with tempfile.TemporaryDirectory() as tmp, patch.object(radar, "ROOT", Path(tmp)):
radar.render_beginner_hub({"go": "Go"}, {}, repositories, issues, "2026-11-08T10:00:00Z")
hub = (Path(tmp) / "site" / "beginner" / "index.html").read_text(encoding="utf-8")
self.assertIn('<h2 id="new">New this week</h2>', hub)
self.assertIn("Fresh &lt;one&gt;", hub)
self.assertNotIn("Old one", hub)
self.assertNotIn("Hard one", hub)

def test_no_hub_without_pages(self):
import tempfile

Expand Down
Loading