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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build and Deploy Docs

on:
workflow_dispatch:
pull_request:
branches:
- main
types:
- closed
{% raw %}
jobs:
build-and-deploy-docs:
if: ${{ github.event.pull_request.merged }} or ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
- uses: ./.github/actions/python-poetry-env
- name: Deploy docs
run: poetry run mkdocs gh-deploy --force{% endraw %}
3 changes: 0 additions & 3 deletions {{cookiecutter.project_slug}}/docs/api_docs.md

This file was deleted.

12 changes: 9 additions & 3 deletions {{cookiecutter.project_slug}}/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ theme:
name: Switch to light mode

nav:
- Introduction: 'index.md'
- api_docs.md
- changelog.md
- Home: 'index.md'
- Code Reference: reference/
- Changelog: changelog.md

watch:
- src/{{ cookiecutter.package_name }}
Expand Down Expand Up @@ -61,6 +61,12 @@ markdown_extensions:
plugins:
- table-reader
- search
- gen-files:
scripts:
- scripts/gen_ref_pages.py
- literate-nav:
nav_vile: SUMMARY.md
- section-index
- mkdocstrings:
default_handler: python
handlers:
Expand Down
6 changes: 6 additions & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ click = "*"
mkdocstrings = {version = ">=0.23", extras = ["python"]}
mkdocs-material = "*"
mkdocs-table-reader-plugin = "*"
mkdocs-gen-files = "^0.5.0"
mkdocs-literate-nav = "^0.6.1"
mkdocs-section-index = "^0.3.9"
mypy = "*"
pre-commit = "*"
pymdown-extensions = "*"
Expand Down Expand Up @@ -78,6 +81,9 @@ ignore = [
"ARG", # "Unused function argument". Fixtures are often unused.
"S105", # "Possible hardcoded password".
]
"scripts/**" = [
"INP001", # "Scripts are not part of a package."
]

[tool.ruff.lint.mccabe]
max-complexity = 10
Expand Down
35 changes: 35 additions & 0 deletions {{cookiecutter.project_slug}}/scripts/gen_ref_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Generate the code reference pages and navigation."""

from pathlib import Path

import mkdocs_gen_files

nav = mkdocs_gen_files.Nav() # type: ignore[attr-defined, no-untyped-call]

root = Path(__file__).parent.parent
src = root / "src"

for path in sorted(src.rglob("*.py")):
module_path = path.relative_to(src).with_suffix("")
doc_path = path.relative_to(src).with_suffix(".md")
full_doc_path = Path("reference", doc_path)

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue

nav[parts] = doc_path.as_posix()

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(f"::: {ident}")

mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
Loading