Skip to content

Commit 97e4520

Browse files
committed
fix dead links via live URL resolution
1 parent 4c91de6 commit 97e4520

3 files changed

Lines changed: 64 additions & 71 deletions

File tree

‎index.html‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,7 @@
467467
</a>
468468
<ul class="nav-links">
469469
<li><a href="#mission">Mission</a></li>
470-
<li><a href="#projects">Projects</a></li>
471-
<li><a href="#stack">Stack</a></li>
470+
<li><a href="#backports">Projects</a></li>
472471
<li><a href="#community">Community</a></li>
473472
<li><a href="https://github.com/pythonbackport" target="_blank" rel="noopener">GitHub ↗</a></li>
474473
</ul>
@@ -488,7 +487,7 @@ <h1 class="hero-title">
488487
An organization for backporting Python's new features
489488
</p>
490489
<div class="hero-actions">
491-
<a href="#projects" class="btn btn-primary">
490+
<a href="#backports" class="btn btn-primary">
492491
<span>Explore our projects</span>
493492
<span>→</span>
494493
</a>
@@ -602,31 +601,6 @@ <h2 class="section-title">Community</h2>
602601
</div>
603602
</section>
604603

605-
<section id="stack">
606-
<div class="container">
607-
<div class="section-head reveal">
608-
<span class="section-eyebrow">Backporting the ecosystem</span>
609-
<h2 class="section-title">From PEPs to PyPI</h2>
610-
<p class="section-desc">We work across the entire Python ecosystem — interpreters, compilers, libraries and tooling.</p>
611-
</div>
612-
</div>
613-
<div class="stack-marquee">
614-
<div class="stack-track">
615-
<span class="stack-item"><span class="bullet"></span>PEP 690</span>
616-
<span class="stack-item"><span class="bullet"></span>PEP 769</span>
617-
<span class="stack-item"><span class="bullet"></span>profiling.sampling</span>
618-
<span class="stack-item"><span class="bullet"></span>profiling.tracing</span>
619-
<span class="stack-item"><span class="bullet"></span>sentinel</span>
620-
<span class="stack-item"><span class="bullet"></span>frozendict</span>
621-
<span class="stack-item"><span class="bullet"></span>CPython 3.14</span>
622-
<span class="stack-item"><span class="bullet"></span>CPython 3.15</span>
623-
<span class="stack-item"><span class="bullet"></span>CPython 3.16</span>
624-
<span class="stack-item"><span class="bullet"></span>CPython 3.17</span>
625-
<span class="stack-item"><span class="bullet"></span>CPython 3.18</span>
626-
</div>
627-
</div>
628-
</section>
629-
630604
<section id="community" class="cta">
631605
<div class="container">
632606
<div class="cta-box reveal">

‎scripts/build.py‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,46 @@ def build_site(org: str, token: str | None) -> tuple[dict, list[tuple[str, list[
309309
return org_meta, ordered
310310

311311

312-
def assemble(org_meta: dict, categorized: list[tuple[str, list[dict]]]) -> str:
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+
344+
def first_section_anchor(categorized: list[tuple[str, list[dict]]]) -> str | None:
345+
"""Anchor of the first category section that actually renders."""
346+
for cat_key, _ in categorized:
347+
return f"#{cat_key}"
348+
return None
349+
350+
351+
def assemble(org_meta: dict, categorized: list[tuple[str, list[dict]]], token: str | None) -> str:
313352
if not TEMPLATE.exists():
314353
raise SystemExit(f"Missing template: {TEMPLATE}")
315354
tpl = TEMPLATE.read_text(encoding="utf-8")
@@ -318,20 +357,37 @@ def assemble(org_meta: dict, categorized: list[tuple[str, list[dict]]]) -> str:
318357

319358
title = org_meta.get("name") or org_meta.get("login") or ""
320359
tagline = org_meta.get("description") or ""
360+
org_login = org_meta.get("login") or ""
321361

322362
section_blocks = [render_category(k, items) for k, items in categorized]
323363
projects_html = "\n".join(b for b in section_blocks if b)
324364
stats_html = render_stats(all_repos)
325365
marquee_html = render_marquee(all_repos)
326366

367+
cta_href = first_section_anchor(categorized) or "#"
368+
community_url = detect_community_url(org_login, categorized, token)
369+
327370
tpl = tpl.replace("{{site_title}}", esc(title))
328371
tpl = tpl.replace("{{site_tagline}}", esc(tagline))
372+
tpl = tpl.replace("{{hero_cta_href}}", esc(cta_href))
373+
tpl = tpl.replace("{{community_url}}", esc(community_url or ""))
329374
if "{{projects}}" not in tpl:
330375
raise SystemExit("Template missing {{projects}} placeholder")
331376
tpl = tpl.replace("{{projects}}", projects_html)
332377
for ph, body in (("{{stats}}", stats_html), ("{{marquee}}", marquee_html)):
333378
if ph in tpl:
334379
tpl = tpl.replace(ph, body)
380+
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.
384+
if not community_url:
385+
tpl = re.sub(
386+
r'<a href="" target="_blank"[^>]*>(?:<span>)?(?:Join discussions|Discussions)(?:</span>)?</a>',
387+
"",
388+
tpl,
389+
)
390+
335391
return tpl
336392

337393

@@ -347,7 +403,7 @@ def main(argv: list[str] | None = None) -> int:
347403

348404
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
349405
org_meta, categorized = build_site(args.org, token)
350-
rendered = assemble(org_meta, categorized)
406+
rendered = assemble(org_meta, categorized, token)
351407

352408
if args.stdout:
353409
sys.stdout.buffer.write(rendered.encode("utf-8"))

‎templates/index.template.html‎

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,7 @@
467467
</a>
468468
<ul class="nav-links">
469469
<li><a href="#mission">Mission</a></li>
470-
<li><a href="#projects">Projects</a></li>
471-
<li><a href="#stack">Stack</a></li>
470+
<li><a href="#backports">Projects</a></li>
472471
<li><a href="#community">Community</a></li>
473472
<li><a href="https://github.com/pythonbackport" target="_blank" rel="noopener">GitHub ↗</a></li>
474473
</ul>
@@ -488,7 +487,7 @@ <h1 class="hero-title">
488487
{{site_tagline}}
489488
</p>
490489
<div class="hero-actions">
491-
<a href="#projects" class="btn btn-primary">
490+
<a href="{{hero_cta_href}}" class="btn btn-primary">
492491
<span>Explore our projects</span>
493492
<span>→</span>
494493
</a>
@@ -576,42 +575,6 @@ <h3>Community-first</h3>
576575

577576
{{projects}}
578577

579-
<section id="stack">
580-
<div class="container">
581-
<div class="section-head reveal">
582-
<span class="section-eyebrow">Backporting the ecosystem</span>
583-
<h2 class="section-title">From PEPs to PyPI</h2>
584-
<p class="section-desc">We work across the entire Python ecosystem — interpreters, compilers, libraries and tooling.</p>
585-
</div>
586-
</div>
587-
<div class="stack-marquee">
588-
<div class="stack-track">
589-
<span class="stack-item"><span class="bullet"></span>PEP 690</span>
590-
<span class="stack-item"><span class="bullet"></span>PEP 769</span>
591-
<span class="stack-item"><span class="bullet"></span>profiling.sampling</span>
592-
<span class="stack-item"><span class="bullet"></span>profiling.tracing</span>
593-
<span class="stack-item"><span class="bullet"></span>Tachyon</span>
594-
<span class="stack-item"><span class="bullet"></span>frozendict</span>
595-
<span class="stack-item"><span class="bullet"></span>CPython 3.14</span>
596-
<span class="stack-item"><span class="bullet"></span>CPython 3.15</span>
597-
<span class="stack-item"><span class="bullet"></span>C Extensions</span>
598-
<span class="stack-item"><span class="bullet"></span>Flame Graphs</span>
599-
<span class="stack-item"><span class="bullet"></span>Remote Debugging</span>
600-
<span class="stack-item"><span class="bullet"></span>PEP 690</span>
601-
<span class="stack-item"><span class="bullet"></span>PEP 769</span>
602-
<span class="stack-item"><span class="bullet"></span>profiling.sampling</span>
603-
<span class="stack-item"><span class="bullet"></span>profiling.tracing</span>
604-
<span class="stack-item"><span class="bullet"></span>Tachyon</span>
605-
<span class="stack-item"><span class="bullet"></span>frozendict</span>
606-
<span class="stack-item"><span class="bullet"></span>CPython 3.14</span>
607-
<span class="stack-item"><span class="bullet"></span>CPython 3.15</span>
608-
<span class="stack-item"><span class="bullet"></span>C Extensions</span>
609-
<span class="stack-item"><span class="bullet"></span>Flame Graphs</span>
610-
<span class="stack-item"><span class="bullet"></span>Remote Debugging</span>
611-
</div>
612-
</div>
613-
</section>
614-
615578
<section id="community" class="cta">
616579
<div class="container">
617580
<div class="cta-box reveal">
@@ -622,7 +585,7 @@ <h2>Join the backport movement 🐍</h2>
622585
tomorrow's Python to yesterday's interpreters.
623586
</p>
624587
<div class="cta-actions">
625-
<a href="https://github.com/orgs/pythonbackport/discussions" target="_blank" rel="noopener" class="btn btn-primary">
588+
<a href="{{community_url}}" target="_blank" rel="noopener" class="btn btn-primary">
626589
<span>Join discussions</span>
627590
</a>
628591
<a href="https://github.com/pythonbackport" target="_blank" rel="noopener" class="btn btn-ghost">
@@ -640,7 +603,7 @@ <h2>Join the backport movement 🐍</h2>
640603
</div>
641604
<div class="footer-links">
642605
<a href="https://github.com/pythonbackport" target="_blank" rel="noopener">GitHub</a>
643-
<a href="https://github.com/orgs/pythonbackport/discussions" target="_blank" rel="noopener">Discussions</a>
606+
<a href="{{community_url}}" target="_blank" rel="noopener">Discussions</a>
644607
<a href="LICENSE">License</a>
645608
</div>
646609
</div>

0 commit comments

Comments
 (0)