Skip to content

Commit 1cec98c

Browse files
committed
set up documentation using mkdocs
1 parent 9c76b7b commit 1cec98c

File tree

9 files changed

+841
-254
lines changed

9 files changed

+841
-254
lines changed

.readthedocs.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
version: 2
5+
6+
build:
7+
os: ubuntu-24.04
8+
tools:
9+
python: '3.12'
10+
11+
# custom commands to run mkdocs build within hatch, as suggested by maintainer in
12+
# https://github.com/readthedocs/readthedocs.org/issues/10706
13+
commands:
14+
- pip install hatch
15+
- hatch run build-ext
16+
- mkdocs build
17+
- mkdir --parents $READTHEDOCS_OUTPUT
18+
- mv site $READTHEDOCS_OUTPUT/html

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- Set up documentation using `mkdocs`, published on readthedocs.com (#186)
11+
812
## [3.6.0] - 2024-10-15
913

1014
### Added

docs/assets/openzim.png

9.69 KB
Loading

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: libzim Documentation
3+
---
4+
5+
{%
6+
include-markdown "../README.md"
7+
%}

docs/license.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: License
3+
---
4+
5+
```
6+
--8<-- "LICENSE"
7+
```

docs/scripts/generate_api_nav.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Script called by mkdocs-gen-files that generates markdown documents
3+
with API reference placeholders.
4+
5+
https://oprypin.github.io/mkdocs-gen-files/api.html
6+
"""
7+
8+
from pathlib import Path
9+
10+
import mkdocs_gen_files
11+
12+
nav = mkdocs_gen_files.Nav()
13+
14+
root = Path(__file__).parent.parent.parent
15+
src = root / "libzim"
16+
api_reference = Path("api_reference")
17+
18+
# Because we are inspecting a compiled module and all the classes can be seen
19+
# from the `libzim` namespace, their documentation is shown in the home page.
20+
# We hide them from the home page as their documentation is also shown in the
21+
# respective modules where they are defined.
22+
LIBZIM_ROOT_OPTIONS = """
23+
options:
24+
members: false
25+
"""
26+
27+
28+
for path in sorted(src.rglob("*.pyi")):
29+
module_path = path.relative_to(root).with_suffix("")
30+
31+
# Package docs get the parent module name.
32+
if module_path.name == "__init__":
33+
module_path = module_path.parent
34+
module_options = LIBZIM_ROOT_OPTIONS
35+
else:
36+
module_options = ""
37+
38+
if module_path.name.startswith("_"):
39+
# Skip other hidden items
40+
continue
41+
identifier = ".".join(module_path.parts)
42+
43+
doc_path = identifier + ".md"
44+
full_doc_path = api_reference / doc_path
45+
46+
nav[identifier] = doc_path
47+
48+
# Create a document with mkdocstrings placeholders.
49+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
50+
fd.write(
51+
f"""---
52+
title: {identifier}
53+
---
54+
55+
56+
::: {identifier}
57+
{module_options}
58+
"""
59+
)
60+
61+
# Make the edit button on the page link to the source file.
62+
mkdocs_gen_files.set_edit_path(full_doc_path, Path("..") / path.relative_to(root))
63+
64+
# Write a navigation file that will be interpreted by literate-nav.
65+
with mkdocs_gen_files.open(api_reference / "NAVIGATION.md", "w") as fd:
66+
fd.writelines(nav.build_literate_nav())

0 commit comments

Comments
 (0)