From 62ee02dfcc307345f7bfa1bfe6f58635707bd83b Mon Sep 17 00:00:00 2001 From: Alexander Kireev Date: Thu, 11 Jun 2026 03:45:46 +0700 Subject: [PATCH 1/2] docs: add indexing files to Netlify build --- noxfile.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/noxfile.py b/noxfile.py index d387150c0ca..f324579687c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -26,6 +26,7 @@ Set, Tuple, ) +from xml.sax.saxutils import escape import nox.command @@ -669,6 +670,7 @@ def build_netlify_site(session: nox.Session): PYO3_DOCS_TARGET.rename("netlify_build/internal/doc") _build_netlify_redirects(preview) + _build_netlify_robots_and_sitemap() def _build_netlify_redirects(preview: bool) -> None: @@ -738,6 +740,37 @@ def _build_netlify_redirects(preview: bool) -> None: redirects_file.write("/main/doc /main/doc/pyo3") +def _build_netlify_robots_and_sitemap() -> None: + current_version = os.environ.get("PYO3_VERSION") + netlify_build = Path("netlify_build") + + (netlify_build / "robots.txt").write_text( + "User-agent: *\n" + "Disallow: /internal/\n" + "\n" + "Sitemap: https://pyo3.rs/sitemap.xml\n" + ) + + urls = set(_sitemap_urls_for_path("main")) + if current_version is not None: + urls.update(_sitemap_urls_for_path(f"v{current_version}")) + + sitemap = [ + '', + '', + *(f" {escape(url)}" for url in sorted(urls)), + "", + ] + (netlify_build / "sitemap.xml").write_text("\n".join(sitemap) + "\n") + + +def _sitemap_urls_for_path(path: str) -> Iterable[str]: + for file in glob(f"netlify_build/{path}/**/*.html", recursive=True): + file_path = file.removeprefix("netlify_build") + url_path = _url_path_from_file_path(file_path) + yield f"https://pyo3.rs{url_path}" + + def _url_path_from_file_path(file_path: str) -> str: """Removes index.html and/or .html suffix to match the page URL on the final netlify site""" url_path = file_path From ad0b4c2a27ab50f43f603f89d9c1709fa45bdc81 Mon Sep 17 00:00:00 2001 From: Alexander Kireev Date: Sun, 14 Jun 2026 02:35:25 +0700 Subject: [PATCH 2/2] style: fix ruff formatting in noxfile --- noxfile.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index f324579687c..f05f7b0b6b2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -745,10 +745,12 @@ def _build_netlify_robots_and_sitemap() -> None: netlify_build = Path("netlify_build") (netlify_build / "robots.txt").write_text( - "User-agent: *\n" - "Disallow: /internal/\n" - "\n" - "Sitemap: https://pyo3.rs/sitemap.xml\n" + """\ +User-agent: * +Disallow: /internal/ + +Sitemap: https://pyo3.rs/sitemap.xml +""" ) urls = set(_sitemap_urls_for_path("main"))