Metadata-Version: 2.1
Name: opdoc
Version: 0.2.1
Summary: Opinionated, self-contained pdoc documentation sites
Home-page: https://gitlab.com/meehai/opdoc
License: MIT
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE.TXT
Requires-Dist: pdoc==16.0.0
Provides-Extra: dev
Requires-Dist: pytest>=8.4; extra == "dev"

# opdoc

Opinionated, self-contained [pdoc](https://pdoc.dev/) documentation sites. One command turns a
project's `docs/` directory plus its `README.md` into a themed static site with prose pages, API
reference, client-side search, and no config file.

```bash
opdoc docs/ public
```

`DOCS` is required; `OUT` defaults to `<project-root>/public`. The project root is the parent of
`DOCS`, so `opdoc docs/` works from a normal checkout.

## What a project supplies

```
project/
├── README.md                    home page (rendered as guide.html)
├── docs/
│   ├── custom.css               optional project CSS, appended after opdoc's base style
│   ├── source/**/PAGE.md        prose pages; the page-dir tree is the "Pages" sidebar
│   └── scripts/*.py             optional build-time page generators
└── <packages>/                  auto-detected API roots
```

That is the whole contract. Theme, template, search, link rewriting, and the pdoc pin live in
opdoc.

## API pages

Without flags, opdoc documents every top-level package directory (a directory with `__init__.py`),
skipping `docs/`, `test/`, `examples/`, `pkg/`, `build/`, `dist/`, and `public/`. Each package's
re-exports are blanked in memory by default, so a class is documented once on its own module page.

For a `src/` layout, namespace packages, or a subset of packages, pass `--api-package` and the
matching import roots:

```bash
opdoc docs/ public \
  --api-package src/robolib \
  --api-package src/robosim \
  --import-path src \
  --import-path .
```

`--keep-reexports` leaves `__all__` alone when a package landing page should show its re-exports.

## Scripts

Every non-underscore `docs/scripts/*.py` is imported before `docs/source` is scanned. It must
define:

```python
def generate(site):
    text, _missing = build_the_page()
    site.write_page("reference/generated/PAGE.md", text)  # text starts with the PAGE.md header
```

`site.write_page(relative_path, text)` writes a `PAGE.md` below `docs/source`; the normal scan
then renders it to HTML. `site.root`, `site.docs`, and `site.out` are absolute paths. Scripts run
in filename order. `_`-prefixed files are helpers and are not run.

Scripts can import project code: `--import-path` entries are already on `sys.path` and in
`PYTHONPATH`. The scripts directory is on `sys.path` too, so a script may `import _helper` from a
sibling `_`-prefixed file.

## Pages menu

A page is a directory holding a `PAGE.md`. The file starts with a header, then free-form
markdown:

```markdown
**Menu Title**: Getting started
**Menu Position**: 1

# Getting started

...
```

```
docs/source/
├── examples/
│   ├── PAGE.md                  header only (empty body) -> a label-only menu group
│   └── getting-started/
│       ├── PAGE.md              a page, child of "examples"
│       └── images/run.png       asset: ![run](images/run.png)
└── architecture/
    └── PAGE.md
```

- the header holds exactly `**Menu Title**` (the sidebar label) and `**Menu Position**`;
  sibling pages are numbered 1..N (no holes, no repeats) and sort by it;
- a subdirectory with its own `PAGE.md` is a child page, to any depth; the URL comes from the
  dir names (`examples/getting-started` -> `guide/examples/getting_started.html`);
- any other file or subdirectory is an asset of the page; linking to it (from any page or the
  README) copies it next to the page;
- an empty body makes a label-only group; a page with an empty body and no children is an error;
- a `.md` that is not a `PAGE.md`, or a `PAGE.md` below a plain (asset) dir, is an error;
- `_`-prefixed files/dirs are drafts; dir names that slugify to the same module are an error.

Links are plain relative paths, relative to the file holding them, the way GitLab's file view
and editors resolve them, so one link works on GitLab, locally, and in the site. opdoc rewrites a
link to a page (`<dir>/PAGE.md` or `<dir>/`) to the generated page and a link to `README.md` to
the home page, copies linked page assets and images, and sends other project paths to GitLab
blob/tree URLs. A link in a page whose target does not exist, or leaves the project, fails the
build (README links are not checked); the error names each link as `file:line:col`, where it
resolved to, and the closest page. Links inside code blocks and inline code are left alone. Set
`--repo-slug owner/project` and `--repo-branch branch` when the git remote does not describe the
published repo (for example, a vendored checkout).

## Vendored sites

`--vendored NAME` adds `vendored/NAME/index.html` to the sidebar. It does **not** build that site;
an orchestrating project script builds each `pkg/NAME/docs` into `OUT/vendored/NAME/` with the same
tool. This keeps every site self-contained and avoids module collisions between projects.

## Install

```bash
pip install opdoc
```

opdoc pins the pdoc version it is tested against (`pdoc==16.0.0`) because it drives pdoc's render
API directly. Python 3.12+.

For development:

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
python -m pytest test/
python -m opdoc docs/ public
```

## Tests

- `test/unit/` exercises the pure helpers (slugging, PAGE.md headers, source scanning and layout
  errors, script loading, path guards).
- `test/integration/` builds a real fixture site with pdoc and checks the home page, API pages,
  generated script page, nested and label-only pages, rewritten links, page assets, and CSS.
