Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/user_guide/05-configuration.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
3 changes: 3 additions & 0 deletions great_docs/_website/homepage/margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions great_docs/assets/great-docs.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions great_docs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
35 changes: 35 additions & 0 deletions tests/test_build_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/test_config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading