4949
5050DEFAULT_ORG = "pythonbackport"
5151
52+ # The community hub lives on Discord. GitHub Discussions is disabled for this
53+ # org (the org-level page answers 404 and the `community` repo is archived),
54+ # so the invite is a constant rather than a URL probed at build time.
55+ DISCORD_INVITE = "https://discord.gg/kThZX7bfP"
56+
57+
5258
5359# ---------- HTTP ------------------------------------------------------------
5460
@@ -230,6 +236,7 @@ def render_category(cat_key: str, repos: list[dict]) -> str:
230236</section>"""
231237
232238
239+
233240def render_marquee (repos : list [dict ]) -> str :
234241 items : list [str ] = []
235242 for r in repos :
@@ -268,10 +275,31 @@ def render_marquee(repos: list[dict]) -> str:
268275</section>"""
269276
270277
278+ def _python_versions (repos : list [dict ]) -> list [str ]:
279+ """Collect the CPython versions the backports target.
280+
281+ Repos tag the version they backport in their topics, either as
282+ ``python315`` or ``python3.15``. Both forms are normalised to ``3.15``.
283+ """
284+ versions : set [str ] = set ()
285+ for r in repos :
286+ for t in (r .get ("topics" ) or []):
287+ if not isinstance (t , str ):
288+ continue
289+ m = re .fullmatch (r"python3\.?(\d{2})" , t , re .IGNORECASE )
290+ if m :
291+ versions .add (f"3.{ int (m .group (1 ))} " )
292+ return sorted (versions , key = lambda v : tuple (int (p ) for p in v .split ("." )))
293+
294+
271295def render_stats (repos : list [dict ]) -> str :
272296 items : list [tuple [str , str ]] = []
273297 if repos :
274- items .append ((f"{ len (repos )} +" , "Active Projects" ))
298+ items .append ((f"{ len (repos )} " , "Projects" ))
299+ versions = _python_versions (repos )
300+ if versions :
301+ items .append ((versions [- 1 ], "Newest Backport" ))
302+ items .append (("100%" , "Open Source" ))
275303 if not items :
276304 return ""
277305 cells = "\n " .join (
@@ -288,6 +316,7 @@ def render_stats(repos: list[dict]) -> str:
288316</section>"""
289317
290318
319+
291320# ---------- Pipeline --------------------------------------------------------
292321
293322def build_site (org : str , token : str | None ) -> tuple [dict , list [tuple [str , list [dict ]]]]:
@@ -309,38 +338,6 @@ def build_site(org: str, token: str | None) -> tuple[dict, list[tuple[str, list[
309338 return org_meta , ordered
310339
311340
312- def detect_community_url (org_login : str , categorized : list [tuple [str , list [dict ]]], token : str | None ) -> str | None :
313- """Pick the right 'community' destination.
314-
315- Order of preference:
316- 1. org-level GitHub Discussions is actually reachable
317- (probe by HEAD request, not by the org API field, which lags).
318- 2. a repo was bucketed into 'community' -> that repo's html_url.
319- 3. None (caller should drop the link).
320- """
321- disc_url = f"https://github.com/orgs/{ org_login } /discussions"
322- try :
323- head = urllib .request .Request (disc_url , method = "HEAD" , headers = {
324- "User-Agent" : USER_AGENT ,
325- "Accept" : "text/html" ,
326- })
327- if token :
328- head .add_header ("Authorization" , f"Bearer { token } " )
329- with urllib .request .urlopen (head , timeout = 15 ) as resp :
330- # The GitHub discussions page returns 200 when enabled.
331- if resp .status == 200 :
332- return disc_url
333- except (urllib .error .HTTPError , urllib .error .URLError , TimeoutError , OSError ):
334- pass
335-
336- for cat_key , items in categorized :
337- if cat_key == "community" and items :
338- url = items [0 ].get ("html_url" )
339- if isinstance (url , str ) and url :
340- return url
341- return None
342-
343-
344341def first_section_anchor (categorized : list [tuple [str , list [dict ]]]) -> str | None :
345342 """Anchor of the first category section that actually renders."""
346343 for cat_key , _ in categorized :
@@ -357,15 +354,14 @@ def assemble(org_meta: dict, categorized: list[tuple[str, list[dict]]], token: s
357354
358355 title = org_meta .get ("name" ) or org_meta .get ("login" ) or ""
359356 tagline = org_meta .get ("description" ) or ""
360- org_login = org_meta .get ("login" ) or ""
361357
362358 section_blocks = [render_category (k , items ) for k , items in categorized ]
363359 projects_html = "\n " .join (b for b in section_blocks if b )
364360 stats_html = render_stats (all_repos )
365361 marquee_html = render_marquee (all_repos )
366362
367363 cta_href = first_section_anchor (categorized ) or "#"
368- community_url = detect_community_url ( org_login , categorized , token )
364+ community_url = DISCORD_INVITE
369365
370366 tpl = tpl .replace ("{{site_title}}" , esc (title ))
371367 tpl = tpl .replace ("{{site_tagline}}" , esc (tagline ))
@@ -378,12 +374,11 @@ def assemble(org_meta: dict, categorized: list[tuple[str, list[dict]]], token: s
378374 if ph in tpl :
379375 tpl = tpl .replace (ph , body )
380376
381- # If there is no community destination at all, strip the placeholder
382- # anchors (left as empty href) by removing the whole CTA / footer
383- # community link if its href is empty.
377+ # Safety net: if there is no community destination at all, drop the
378+ # community links rather than shipping an empty href.
384379 if not community_url :
385380 tpl = re .sub (
386- r'<a href="" target="_blank"[^>]*>(?:<span>)?(?:Join discussions|Discussions )(?:</span>)?</a>' ,
381+ r'<a href="" target="_blank"[^>]*>(?:<span>)?(?:Join the Discord|Discord )(?:</span>)?</a>' ,
387382 "" ,
388383 tpl ,
389384 )
0 commit comments