-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from elfkuzco/online-api-doc
set up documentation using mkdocs
- Loading branch information
Showing
9 changed files
with
841 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: libzim Documentation | ||
--- | ||
|
||
{% | ||
include-markdown "../README.md" | ||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: License | ||
--- | ||
|
||
``` | ||
--8<-- "LICENSE" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Oops, something went wrong.