From 374532059724ccc5877e7d5605e79dcc01cbb96e Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Thu, 22 Oct 2026 18:31:55 -0400 Subject: [PATCH 1/6] Prepare shared sidebars before Quarto rendering --- great_docs/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/great_docs/core.py b/great_docs/core.py index b867a50d..795015be 100644 --- a/great_docs/core.py +++ b/great_docs/core.py @@ -32,6 +32,7 @@ from ._website.navigation import github as nav_github from ._website.navigation import label as nav_label from ._website.navigation import release as nav_release +from ._website.navigation import shared_sidebar from ._website.scripts import script_include, script_tag from ._website.seo import description as seo_description from ._website.seo import noindex @@ -16421,6 +16422,13 @@ class Result: # ── Pre-render termshow recordings ────────────────────── self._prerender_term_player(log) + # Render each long reference sidebar once rather than on every page. + # A versioned build does this in each version's own directory. + if watch or not self._config.has_versions: + shared = shared_sidebar.prepare(self.build_dir) + if shared: + log.detail("Sharing rendered sidebar(s): " + ", ".join(shared)) + # ── Step 16: Build site with Quarto ──────────────────────── step += 1 log.step_start(step, "Build site with Quarto") @@ -16428,6 +16436,7 @@ class Result: log.step_done("Starting watch mode...") log.footer(watch_mode=True) self._print_layout_notice() + quarto_env[shared_sidebar.PREVIEW_ENV] = "1" subprocess.run(["quarto", "preview", "--no-browser"], env=quarto_env) return elif self._config.has_versions: From e5708734c6ffe80938e3f9b6f47f7f618f2aeef8 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Thu, 22 Oct 2026 18:32:22 -0400 Subject: [PATCH 2/6] Add post-render shared sidebar restoration --- great_docs/assets/share-sidebars.py | 223 ++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 great_docs/assets/share-sidebars.py diff --git a/great_docs/assets/share-sidebars.py b/great_docs/assets/share-sidebars.py new file mode 100644 index 00000000..bd1950a3 --- /dev/null +++ b/great_docs/assets/share-sidebars.py @@ -0,0 +1,223 @@ +""" +Copy each shared sidebar into the pages that show it (Quarto post-render) + +Before rendering, Great Docs trims each long reference sidebar and adds a +template page that shows it in full (see `shared_sidebar.py`). This script +takes the full sidebar from the template, then gives every page that shows +the trimmed sidebar the full one, with the page's own link marked as current +and the sections around it open, as Quarto would. It also restores the +search crumbs Quarto takes from the sidebar and, unless the site is being +previewed, removes the template. + +During `quarto preview`, a re-render of one page doesn't render the +template again, so the full sidebar is cached in the project. +""" + +import json +import os +import re +from pathlib import Path, PurePosixPath + +build_dir = Path.cwd() +manifest_path = build_dir / "_gd_sidebars.json" +cache_dir = build_dir / "_gd_sidebars" + +_NAV_OPEN = re.compile(r'