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
20 changes: 19 additions & 1 deletion docs/user_guide/05-configuration.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -1456,9 +1456,27 @@ The timestamp records the site's last build.
```{.yaml filename="docs/great-docs.yml"}
show_dates: true # Enable/disable page metadata (default: false)
show_author: true # Show author attribution when enabled (default: true)
show_security: true # Show security policy page from SECURITY.md (default: true)
```

### Community Pages

Great Docs generates these pages when the corresponding project files exist. Set a page's
option to `false` to keep an authored page at its existing URL without generating a second
copy.

| Setting | Project file | Generated URL |
|---------|--------------|---------------|
| `show_contributing` | `CONTRIBUTING.md` | `contributing.html` |
| `show_code_of_conduct` | `CODE_OF_CONDUCT.md` | `code-of-conduct.html` |
| `show_roadmap` | `ROADMAP.md` | `roadmap.html` |
| `show_security` | `SECURITY.md` | `security.html` |
| `show_licence` | `LICENSE` | `license.html` |
| `show_citation` | `CITATION.cff` | `citation.html` |

All six settings default to `true`. For example, if your site already publishes
`conduct.html`, keep its source page in your documentation and set
`show_code_of_conduct: false`.

### Author Attribution

When `show_author` is enabled and a page has author information in its frontmatter, author avatars
Expand Down
4 changes: 3 additions & 1 deletion great_docs/_build/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def homepage(
_ = licence.write_page(config, layout, metadata["license"], page_authors, report=print)
citation_ref = (
source_ref(config, layout.package_root, warn=print_warning)
if run.project.repository is not None and (layout.package_root / "CITATION.cff").is_file()
if config.show_citation
and run.project.repository is not None
and (layout.package_root / citation.SOURCE_FILENAME).is_file()
else "main"
)
_ = citation.write_page(
Expand Down
39 changes: 24 additions & 15 deletions great_docs/_content/site_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"NOT_FOUND_PAGE",
"Files",
"GeneratedName",
"community_page_enabled",
"find_generated",
"find_pages",
"generated_names",
Expand Down Expand Up @@ -75,20 +76,21 @@ class GeneratedName:
"""The source directory whose files may share this section's output"""


_PROJECT_PAGES: dict[str, str | None] = {
"changelog": "changelog.enabled: false",
"citation": None,
"code-of-conduct": None,
"contributing": None,
"license": None,
"package-info": "package_info_page.enabled: false",
"roadmap": None,
"security": "show_security: false",
_COMMUNITY_PAGE_SETTINGS = {
"citation": "show_citation",
"code-of-conduct": "show_code_of_conduct",
"contributing": "show_contributing",
"license": "show_licence",
"roadmap": "show_roadmap",
"security": "show_security",
}
"""
The stems of the project pages that a page beside the configuration replaces, each with
the setting that stops Great Docs generating it, or `None` when no setting does
"""

_PROJECT_PAGES = {
"changelog": "changelog.enabled",
"package-info": "package_info_page.enabled",
**_COMMUNITY_PAGE_SETTINGS,
}
"""The stems of replaceable project pages and the settings for their generators"""

_FILES = {
"_quarto.yml": "writes the Quarto project configuration `_quarto.yml`",
Expand Down Expand Up @@ -180,6 +182,7 @@ def generated_names(
replaceable=True,
)
for stem in _PROJECT_PAGES
if stem not in _COMMUNITY_PAGE_SETTINGS or community_page_enabled(config, stem)
)
names.extend(_llms_txt_names(config))
if config.sitemap_enabled:
Expand Down Expand Up @@ -640,6 +643,11 @@ def validate(config: Config, layout: Layout) -> None:
)


def community_page_enabled(config: Config, stem: str) -> bool:
"""Check whether the project enables the named community page generator"""
return bool(config[_COMMUNITY_PAGE_SETTINGS[stem]])


def generator_off_switch(page: Path) -> str | None:
"""
Find the setting that stops Great Docs generating the project page `page` replaces
Expand All @@ -653,9 +661,10 @@ def generator_off_switch(page: Path) -> str | None:
-------
:
The setting as written in the configuration, such as `changelog.enabled: false`,
or `None` when `page` replaces no project page or no setting stops its generation.
or `None` when `page` has no generated counterpart.
"""
return _PROJECT_PAGES.get(page.stem)
setting = _PROJECT_PAGES.get(page.stem)
return f"{setting}: false" if setting is not None else None


def remove_generated_page(layout: Layout, page: Path) -> Path | None:
Expand Down
31 changes: 14 additions & 17 deletions great_docs/_website/homepage/margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..._project.layout import Layout
from ..._project.repository import Repository
from ...config import Config
from ..project_pages.community import CommunityPage
from ..project_pages.community import Published

__all__ = ["render"]

Expand Down Expand Up @@ -62,14 +62,13 @@ def render(
metadata: Manifest,
repository: Repository | None,
package_name: str | None,
community_pages: Sequence[CommunityPage],
community_pages: Published,
llms_txt: Sequence[str],
) -> str:
"""
Render the homepage sidebar as Markdown

The sidebar links to the licence, citation and package-info pages when they are in the
build directory, so it is rendered after them.
The sidebar links to the community and package information pages that the site publishes.

Parameters
----------
Expand All @@ -85,7 +84,7 @@ def render(
package_name
The package name, for the PyPI link, the curated skill and the citation link.
community_pages
The community pages written for the site.
The site's destinations for the community pages.
llms_txt
The `llms.txt` files the site publishes, which the sidebar links to.

Expand All @@ -100,7 +99,7 @@ def render(
*_links(config, metadata, repository, package_name, lang),
*_ai_agents(config, layout.package_root, package_name, lang, llms_txt=llms_txt),
*_developers(config, metadata, repository, lang),
*_community(build_dir, metadata, package_name, community_pages, lang),
*_community(metadata, package_name, community_pages, lang),
*_meta(config, build_dir, metadata, lang),
]
return "\n".join(sections)
Expand Down Expand Up @@ -419,25 +418,22 @@ def _icon_row(icons: list[str]) -> str:


def _community(
build_dir: Path,
metadata: Manifest,
package_name: str | None,
community_pages: Sequence[CommunityPage],
community_pages: Published,
lang: str,
) -> list[str]:
"""
Render the Community section: community pages, the licence and the citation

Parameters
----------
build_dir
The Quarto project directory, which may hold `license.qmd` and `citation.qmd`.
metadata
The package metadata, with the licence identifier.
package_name
The package name, for the citation link.
community_pages
The community pages written for the site.
The site's destinations for the community pages.
lang
The site language.

Expand All @@ -447,25 +443,26 @@ def _community(
The heading and one line per link, or no lines if there are no links.
"""
items = [
f"[{translate(page.label_key, lang)}]({page.filename})<br>" for page in community_pages
f"[{translate(page.label_key, lang)}]({page.filename})<br>"
for page in community_pages.policies
]

if (build_dir / "license.qmd").exists():
if (licence := community_pages.licence) is not None:
full_licence = translate("full_license", lang)
licence_id: str = metadata.get("license", "")
info = get_license_info(licence_id) if licence_id else None
if info is not None:
items.append(
f'<a href="license.qmd">{full_licence}</a> '
f'<a href="{licence}">{full_licence}</a> '
f'<span title="{html.escape(info.full_name)}" '
f'class="gd-spdx-badge">{info.spdx_id}</span><br>'
)
else:
items.append(f"[{full_licence}](license.qmd)<br>")
items.append(f"[{full_licence}]({licence})<br>")

if (build_dir / "citation.qmd").exists():
if (citation := community_pages.citation) is not None:
citing = translate("citing", lang)
items.append(f"[{citing} {package_name or 'this package'}](citation.qmd)<br>")
items.append(f"[{citing} {package_name or 'this package'}]({citation})<br>")

if not items:
return []
Expand Down
57 changes: 6 additions & 51 deletions great_docs/_website/homepage/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ def write_readme(
# README headings sit below the homepage title.
body = readme.bump_heading_levels(body)

sidebar = _sidebar(
community_pages = community.write_pages(config, layout, page_authors)
sidebar = margin.render(
config,
layout,
metadata=metadata,
repository=repository,
package_name=package_name,
page_authors=page_authors,
community_pages=community_pages,
llms_txt=llms_txt,
)

Expand Down Expand Up @@ -339,13 +340,14 @@ def write_blended(
# Preserve the front matter title so Quarto's title block matches other user guide pages.
content = set_front_matter_option(content, "toc", False)

sidebar = _sidebar(
community_pages = community.write_pages(config, layout, page_authors)
sidebar = margin.render(
config,
layout,
metadata=metadata,
repository=repository,
package_name=package_name,
page_authors=page_authors,
community_pages=community_pages,
llms_txt=llms_txt,
)
hero_html, _ = _hero(
Expand Down Expand Up @@ -428,50 +430,3 @@ def _hero(
pages=pages,
)
return html, found.body if html else None


def _sidebar(
config: Config,
layout: Layout,
*,
metadata: Manifest,
repository: Repository | None,
package_name: str | None,
page_authors: list[dict[str, Any]],
llms_txt: Sequence[str],
) -> str:
"""
Write the community pages and render the homepage's metadata sidebar

Parameters
----------
config
The Great Docs configuration.
layout
The package root to read community pages and discover curated skills, and
the build directory to write community pages and check for linked pages.
metadata
The package metadata.
repository
The selected repository, used for GitHub author-profile fallbacks.
package_name
The package name, or `None` if it is unknown.
page_authors
The configured authors, with local portrait paths replaced by site URLs.
llms_txt
The `llms.txt` files the site publishes.

Returns
-------
:
The sidebar's Markdown, or `""` when it has no sections.
"""
return margin.render(
config,
layout,
metadata=metadata,
repository=repository,
package_name=package_name,
community_pages=community.write_pages(config, layout, page_authors),
llms_txt=llms_txt,
)
9 changes: 5 additions & 4 deletions great_docs/_website/project_pages/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from ..._project.layout import Layout
from ...config import Config

__all__ = ["FILENAME", "write_page"]
__all__ = ["FILENAME", "SOURCE_FILENAME", "write_page"]

FILENAME = "citation.qmd"
SOURCE_FILENAME = "CITATION.cff"


def write_page(
Expand Down Expand Up @@ -64,10 +65,10 @@ def write_page(
Returns
-------
:
The path of the written page, or `None` if the project has no `CITATION.cff` file.
The written page, or `None` when disabled or missing `CITATION.cff`.
"""
source = layout.package_root / "CITATION.cff"
if not source.exists():
source = layout.package_root / SOURCE_FILENAME
if not config.show_citation or not source.is_file():
return None

with open(source, encoding="utf-8") as f:
Expand Down
Loading
Loading