diff --git a/docs/user_guide/05-configuration.qmd b/docs/user_guide/05-configuration.qmd index 72d19bd4..bab5a51a 100644 --- a/docs/user_guide/05-configuration.qmd +++ b/docs/user_guide/05-configuration.qmd @@ -694,6 +694,13 @@ homepage: user_guide | `index` (default) | Separate homepage from README / `index.qmd`. "User Guide" appears as a navbar link. | | `user_guide` | First User Guide page becomes the landing page. Left sidebar shows the UG table of contents. Right sidebar shows project metadata. No separate "User Guide" navbar link. | +### Homepage Metadata + +Set `show_homepage_metadata: false` to hide the generated margin with project links, +authors and other metadata. The setting applies to an authored Markdown homepage, a +README homepage and a homepage taken from the User Guide. Community pages such as +`contributing.html` still publish according to their own settings. + ### Homepage Front Matter In `index` mode, the homepage preserves its source file's front matter, including `execute`, diff --git a/great_docs/_website/homepage/margin.py b/great_docs/_website/homepage/margin.py index 2b6fef34..2b5e38de 100644 --- a/great_docs/_website/homepage/margin.py +++ b/great_docs/_website/homepage/margin.py @@ -69,6 +69,7 @@ def render( Render the homepage sidebar as Markdown The sidebar links to the community and package information pages that the site publishes. + Return empty Markdown when `show_homepage_metadata` is disabled. Parameters ---------- @@ -93,6 +94,8 @@ def render( : The sidebar's Markdown, or `""` if no section has entries. """ + if not config.show_homepage_metadata: + return "" lang = config.lang build_dir = layout.build_dir sections = [ diff --git a/great_docs/assets/great-docs.default.yml b/great_docs/assets/great-docs.default.yml index a1ec0fe7..c2c8d47d 100644 --- a/great_docs/assets/great-docs.default.yml +++ b/great_docs/assets/great-docs.default.yml @@ -400,6 +400,9 @@ site_root: # : user_guide - the first user-guide page becomes the landing page homepage: index +# Show the generated metadata margin on the homepage. +show_homepage_metadata: true + # User Guide # ---------- # Where the User Guide .qmd files live, and optionally how they are ordered. diff --git a/great_docs/config.py b/great_docs/config.py index 4890fd01..08ec7a9b 100644 --- a/great_docs/config.py +++ b/great_docs/config.py @@ -1429,6 +1429,11 @@ def display_name(self) -> str | None: """ return self["display_name"] + @property + def show_homepage_metadata(self) -> bool: + """Whether to show the generated metadata margin on the homepage""" + return bool(self["show_homepage_metadata"]) + @property def homepage(self) -> str: """ diff --git a/tests/test_build_content.py b/tests/test_build_content.py index 0512e153..d914d836 100644 --- a/tests/test_build_content.py +++ b/tests/test_build_content.py @@ -363,6 +363,41 @@ def test_community_links_follow_published_pages(tmp_path: Path) -> None: assert "(code-of-conduct.md)" in (layout.build_dir / "index.qmd").read_text() +@pytest.mark.parametrize("source", ["index.qmd", "README.md", "user_guide/01-intro.qmd"]) +@pytest.mark.parametrize("enabled", [True, False]) +def test_homepage_metadata_is_independent_of_community_pages( + tmp_path: Path, source: str, enabled: bool +) -> None: + mode = "user_guide" if source.startswith("user_guide/") else "index" + docs = _project( + tmp_path, + { + "pyproject.toml": '[project]\nname = "example"\nversion = "1.0"\n', + "great-docs.yml": ( + f"homepage: {mode}\nshow_homepage_metadata: {str(enabled).lower()}\n" + ), + source: "# Introduction\n\nWelcome to the project.\n", + "CONTRIBUTING.md": "# Contributing\n\nSend a pull request.\n", + "LICENSE": "MIT License\n", + "CITATION.cff": 'title: "Example"\nauthors: []\n', + }, + ) + guide = discover_user_guide(docs) + layout = docs.layout + config = docs._config + run = make_run(docs, user_guide=guide) + content.homepage(run, config, layout, page_authors=run.page_authors, remote=StubRemote()) + if mode == "user_guide": + content.user_guide(run, config, layout, page_authors=run.page_authors, remote=StubRemote()) + + home = (layout.build_dir / "index.qmd").read_text() + assert "Welcome to the project." in home + assert (".gd-homepage-sidebar" in home) is enabled + for filename in ("contributing.qmd", "license.qmd", "citation.qmd"): + assert (layout.build_dir / filename).is_file() + assert (filename in home) is enabled + + def test_the_user_guide_step_publishes_pages_with_a_sidebar_and_navbar_link(tmp_path: Path): docs = _project( tmp_path, diff --git a/tests/test_config_defaults.py b/tests/test_config_defaults.py index 6bfa4ebf..e0d16535 100644 --- a/tests/test_config_defaults.py +++ b/tests/test_config_defaults.py @@ -79,6 +79,7 @@ # Added after the snapshot: pages and files published at the site root. "site_root": {"pages": None, "files": []}, "homepage": "index", + "show_homepage_metadata": True, "user_guide": None, "bibliography": [], "csl": None,