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
30 changes: 29 additions & 1 deletion docs/user_guide/05-configuration.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,18 @@ user_guide: guides
The path is relative to the configuration directory. If both the config option and a `user_guide/` directory
exist, the config option takes precedence.

See [User Guides](user-guides.qmd) for details on writing and organizing User Guide content.
By default, the guide publishes under `user-guide/`. Set `output` to keep a different URL
prefix, such as `user_guide/` on an existing site.

```{.yaml filename="docs/great-docs.yml"}
user_guide:
dir: user_guide
output: user_guide
```

Omit `dir` to use the conventional source directory. Use `sections` within the mapping
to list pages in an explicit order, using the same entries as the list form of `user_guide`.
See [User Guides](user-guides.qmd) for details on writing and organising guide content.

## Homepage Mode

Expand Down Expand Up @@ -852,6 +863,23 @@ Default sections can generate a card-grid index and sidebar navigation. Blog-typ
native `listing:` directive. Posts are sorted by date and displayed with author, categories, and
descriptions.

Great Docs normally lowercases the section's directory name, replaces spaces and underscores
with hyphens, and drops numeric prefixes from page and subdirectory names. To keep an
existing URL such as `Tutorials/01_basics/02-setup.html`, set both options.

```{.yaml filename="docs/great-docs.yml"}
sections:
- title: Tutorials
dir: Tutorials
output: Tutorials
keep_numeric_prefixes: true
```

Each option works on its own. Blog posts already keep their numeric prefixes. Guide and
section outputs are relative to the site root and can contain multiple directories.
Use directory names that begin with a letter or digit. Hyphens, underscores and internal
spaces are allowed.

See [Custom Sections](custom-sections.qmd) and [Blog](blog.qmd) for full details.

## Site Root
Expand Down
31 changes: 17 additions & 14 deletions great_docs/_build/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .._content import sections as authored_sections
from .._content import user_guide as authored_guide
from .._content.naming import title_from_name
from .._content.pages import PageMap
from .._content.pages import PageMap, output_destination
from .._contribution import Contribution, NavbarLink, Sidebar
from .._website import page_dates, quarto_yml, social_cards, website_overlay
from .._website.ai_agents import llms_txt as llms_files
Expand Down Expand Up @@ -181,7 +181,9 @@ def homepage(
pages=pages,
page_authors=page_authors,
has_api_reference=run.api_spec is not None,
has_user_guide=lambda: guide is not None,
user_guide_entry=lambda: (
authored_guide.entry(guide, output=config.user_guide_output) if guide else None
),
llms_txt=llms_files.published(config, run.api_spec),
report=print,
)
Expand Down Expand Up @@ -250,7 +252,7 @@ def user_guide(
blend_homepage = False

copied_files, resources = _publish_guide_pages(config, layout, guide, page_authors=page_authors)
print(f" Copied {len(copied_files)} file(s) to docs/user-guide/")
print(f" Copied {len(copied_files)} file(s) to {config.user_guide_output}/")

blended_first_page = None
if blend_homepage:
Expand Down Expand Up @@ -302,7 +304,7 @@ def _publish_guide_pages(
Both are relative to the build directory.
"""
source_dir = guide["source_dir"]
target_dir = layout.build_dir / authored_guide.SIDEBAR_ID
target_dir = output_destination(layout, config.user_guide_output)
strip_prefix = not guide.get("explicit", False)
add_dates = partial(page_dates.add_to_page, config=config, authors=page_authors)
resources = publish.copy_asset_dirs(
Expand Down Expand Up @@ -345,7 +347,7 @@ def _promote_first_page(
"""
Promote the first user guide page to `index.qmd` in blended homepage mode

Remove the original page from `user-guide/` after writing the homepage.
Remove the original page from the guide's directory after writing the homepage.

Parameters
----------
Expand All @@ -366,14 +368,14 @@ def _promote_first_page(
Returns
-------
:
The promoted page's former path under `user-guide/`, or `None` when no page was
The promoted page's former path in the guide, or `None` when no page was
promoted.
"""
if not guide["files"]:
return None

dest_rel = authored_guide.published(guide, guide["files"][0])
first_ug_path = layout.build_dir / authored_guide.SIDEBAR_ID / dest_rel
first_ug_path = layout.build_dir / config.user_guide_output / dest_rel

if not first_ug_path.exists():
print(f" ⚠️ First UG page '{first_ug_path}' not found for blended homepage")
Expand All @@ -394,7 +396,7 @@ def _promote_first_page(
first_ug_path.unlink()

print(" 📄 Blended homepage: first UG page → index.qmd")
return f"user-guide/{dest_rel}"
return first_ug_path.relative_to(layout.build_dir).as_posix()


def _guide_navigation(
Expand All @@ -410,7 +412,7 @@ def _guide_navigation(
guide
The user guide.
blended_first_page
The promoted page's former path under `user-guide/`, or `None` when no page was
The promoted page's former path in the guide, or `None` when no page was
promoted.

Returns
Expand All @@ -419,7 +421,8 @@ def _guide_navigation(
The sidebar and, unless the guide's first page became the homepage, a navbar
link to that page.
"""
sidebar = authored_guide.sidebar(guide)
output = config.user_guide_output
sidebar = authored_guide.sidebar(guide, output=output)

# The sidebar must link to the homepage after the first guide page moves there.
if blended_first_page:
Expand All @@ -429,7 +432,7 @@ def _guide_navigation(
navbar: tuple[NavbarLink, ...] = ()
if not blended_first_page:
label = nav_navbar.USER_GUIDE.label(config)
navbar = (NavbarLink(label, authored_guide.entry(guide), kind="user_guide"),)
navbar = (NavbarLink(label, authored_guide.entry(guide, output=output), kind="user_guide"),)
return Contribution(navbar=navbar, sidebars=(_sidebar(sidebar),))


Expand Down Expand Up @@ -483,7 +486,7 @@ def sections(
if not found:
return "No sections to process"

section_ids = {section.slug for section in found}
section_ids = {section.sidebar_id for section in found}
generated_ids = {
sidebar.id for contribution in run.contributions for sidebar in contribution.sidebars
}
Expand All @@ -510,7 +513,7 @@ def sections(
layout,
section.source,
section.destination,
strip_prefix=not section.blog,
strip_prefix=section.strip_prefix,
pages=section.files,
)

Expand All @@ -523,7 +526,7 @@ def sections(
section.files,
section.source,
section.destination,
strip_prefix=True,
strip_prefix=section.strip_prefix,
report=print_warning,
)

Expand Down
80 changes: 76 additions & 4 deletions great_docs/_build/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
from __future__ import annotations

import shutil
from typing import TYPE_CHECKING
from dataclasses import replace
from pathlib import Path
from typing import TYPE_CHECKING, cast

from .._content import sections, site_root
from .._content.naming import strip_numeric_prefix
from .._content.naming import section_strips_prefix, strip_numeric_prefix
from .._content.pages import output_destination, section_destination
from .._website import quarto_extensions
from .._website.ai_agents import llms_txt
from .ownership import recognised_build_dirs, validate_build_dir, validate_layout_outputs

if TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path

from .._project.layout import Layout
from ..config import Config
Expand Down Expand Up @@ -63,12 +64,83 @@ def validate(config: Config, layout: Layout) -> None:
for entry in versions:
validate_build_dir(layout.build_dir_for(entry.tag, latest_tag))
_validate_section_claims(config, layout)
_validate_content_outputs(config, layout)
site_root.validate(config, layout)
_ = llms_txt.project_files(config, layout)
_validate_reference_output(config, layout)
quarto_extensions.validate(layout)


def _validate_content_outputs(config: Config, layout: Layout) -> None:
"""Reject configured output directories that overlap another destination"""
guide = config.user_guide
guide_explicit = isinstance(guide, dict) and guide.get("output") is not None
entries = cast("object", config.sections)
sections_config = (
[
cast("dict[str, object]", entry)
for entry in cast("list[object]", entries)
if isinstance(entry, dict)
]
if isinstance(entries, list)
else []
)
if not guide_explicit and not any(entry.get("output") is not None for entry in sections_config):
return

generated = site_root.generated_names(config, layout, include_content_directories=False)
guide_name = site_root.user_guide_name(config)
reserved = [
replace(name, path=name.path.casefold()) for name in generated if name != guide_name
]
build_dir = layout.build_dir.resolve()
destinations = [("user_guide.output", config.user_guide_output, guide_explicit)]
for entry in sections_config:
destination = section_destination(layout, entry)
if destination is not None and destination != build_dir:
destinations.append(
(
f"sections ({entry['dir']})",
destination.relative_to(build_dir).as_posix(),
entry.get("output") is not None,
)
)

for entry in config.custom_pages:
if config["custom_pages"] is None and not (layout.source_dir / entry["dir"]).is_dir():
continue
try:
destination = output_destination(layout, entry["output"])
except ValueError:
continue
if destination != build_dir:
destinations.append(
(
f"custom_pages ({entry['dir']})",
destination.relative_to(build_dir).as_posix(),
False,
)
)

for index, (key, output, configured) in enumerate(destinations):
if not configured:
continue
if (clash := site_root.find_generated(output.casefold(), reserved)) is not None:
raise ValueError(f"`{key}` publishes to '{output}/', but Great Docs {clash.writer}")
directory = Path(output.casefold())
for other_index, (other, other_output, _) in enumerate(destinations):
if index == other_index:
continue
other_directory = Path(other_output.casefold())
if directory.is_relative_to(other_directory) or other_directory.is_relative_to(
directory
):
raise ValueError(
f"`{key}` publishes to '{output}/', which overlaps "
f"'{other_output}/' from `{other}`"
)


def _validate_reference_output(config: Config, layout: Layout) -> None:
"""
Reject a reference directory that other pages publish into
Expand Down Expand Up @@ -97,7 +169,7 @@ def _validate_reference_output(config: Config, layout: Layout) -> None:
f"sections ({section.get('title') or section.get('dir')})",
destination,
layout.source_dir / section["dir"],
section.get("type") != "blog",
section_strips_prefix(section),
)
for section in config.sections
if (destination := section_destination(layout, section)) is not None
Expand Down
11 changes: 11 additions & 0 deletions great_docs/_content/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@

import re
from pathlib import Path
from typing import TYPE_CHECKING
from urllib.parse import unquote

if TYPE_CHECKING:
from collections.abc import Mapping

DEFAULT_USER_GUIDE_OUTPUT = "user-guide"


def section_strips_prefix(section: Mapping[str, object]) -> bool:
"""Check whether section page paths drop their numeric prefixes"""
return section.get("type") != "blog" and section.get("keep_numeric_prefixes") is not True


def strip_numeric_prefix(filename: str) -> str:
"""
Expand Down
13 changes: 8 additions & 5 deletions great_docs/_content/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import TYPE_CHECKING, cast

from . import notebooks, site_root
from .naming import is_private_path, published_path, section_slug
from .naming import is_private_path, published_path, section_slug, section_strips_prefix

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping
Expand Down Expand Up @@ -54,8 +54,8 @@ def section_destination(layout: Layout, section: Mapping[str, object]) -> Path |
"""
Resolve a section's destination directory in the build tree

The destination is the slug of the section's `dir`. If `dir` is absolute or contains
`..`, use its path relative to the package root. This preserves the name of a shared
Use `output` when set. Otherwise slug the section's `dir`. If `dir` is absolute or
contains `..`, use its path relative to the package root. This preserves the name of a shared
section when documentation sources are in a subdirectory. For a section outside the
package, use only the directory name.

Expand All @@ -74,6 +74,9 @@ def section_destination(layout: Layout, section: Mapping[str, object]) -> Path |
directory = section.get("dir")
if not directory or not isinstance(directory, str):
return None
output = section.get("output")
if isinstance(output, str):
return output_destination(layout, output)
source = Path(directory)
if source.is_absolute() or ".." in source.parts:
resolved = (layout.source_dir / source).resolve()
Expand Down Expand Up @@ -171,7 +174,7 @@ def make(
roots.append(
PageRoot(
guide["source_dir"].resolve(),
layout.build_dir / "user-guide",
output_destination(layout, config.user_guide_output),
not guide.get("explicit", False),
)
)
Expand All @@ -185,7 +188,7 @@ def make(
PageRoot(
(layout.source_dir / str(section["dir"])).resolve(),
destination,
section.get("type") != "blog",
section_strips_prefix(section),
prefer_markdown_index=True,
exclude_private=True,
)
Expand Down
Loading
Loading