Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set up documentation using mkdocs #215

Merged
merged 1 commit into from
Feb 7, 2025
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
18 changes: 18 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

version: 2

build:
os: ubuntu-24.04
tools:
python: '3.12'

# custom commands to run mkdocs build within hatch, as suggested by maintainer in
# https://github.com/readthedocs/readthedocs.org/issues/10706
commands:
- pip install hatch
- hatch run build-ext
- mkdocs build
- mkdir --parents $READTHEDOCS_OUTPUT
- mv site $READTHEDOCS_OUTPUT/html
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Set up documentation using `mkdocs`, published on readthedocs.com (#186)

## [3.6.0] - 2024-10-15

### Added
Expand Down
Binary file added docs/assets/openzim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: libzim Documentation
---

{%
include-markdown "../README.md"
%}
7 changes: 7 additions & 0 deletions docs/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: License
---

```
--8<-- "LICENSE"
```
66 changes: 66 additions & 0 deletions docs/scripts/generate_api_nav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
Script called by mkdocs-gen-files that generates markdown documents
with API reference placeholders.

https://oprypin.github.io/mkdocs-gen-files/api.html
"""

from pathlib import Path

import mkdocs_gen_files

nav = mkdocs_gen_files.Nav()

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

# Because we are inspecting a compiled module and all the classes can be seen
# from the `libzim` namespace, their documentation is shown in the home page.
# We hide them from the home page as their documentation is also shown in the
# respective modules where they are defined.
LIBZIM_ROOT_OPTIONS = """
options:
members: false
"""


for path in sorted(src.rglob("*.pyi")):
module_path = path.relative_to(root).with_suffix("")

# Package docs get the parent module name.
if module_path.name == "__init__":
module_path = module_path.parent
module_options = LIBZIM_ROOT_OPTIONS
else:
module_options = ""

if module_path.name.startswith("_"):
# Skip other hidden items
continue
identifier = ".".join(module_path.parts)

doc_path = identifier + ".md"
full_doc_path = api_reference / doc_path

nav[identifier] = doc_path

# Create a document with mkdocstrings placeholders.
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
fd.write(
f"""---
title: {identifier}
---


::: {identifier}
{module_options}
"""
)

# Make the edit button on the page link to the source file.
mkdocs_gen_files.set_edit_path(full_doc_path, Path("..") / path.relative_to(root))

# Write a navigation file that will be interpreted by literate-nav.
with mkdocs_gen_files.open(api_reference / "NAVIGATION.md", "w") as fd:
fd.writelines(nav.build_literate_nav())
Loading