mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-03-26 03:03:32 +01:00
Implemented draft for py yml and optimized assets urls
This commit is contained in:
parent
0611ddda11
commit
6680f64e50
@ -7,17 +7,26 @@ SPHINXBUILD ?= sphinx-build
|
||||
SPHINX_SOURCE_DIR ?= ../
|
||||
SPHINX_BUILD_DIR ?= ../docs
|
||||
|
||||
.PHONY: help install copy-images Makefile
|
||||
.PHONY: help install copy-images apidoc html Makefile
|
||||
|
||||
# Copy images before running any Sphinx command (except for help)
|
||||
copy-images:
|
||||
@echo "Copying images from ../images/ to ./assets/img/..."
|
||||
@echo "Copying images from ../assets/img/ to ./assets/img/..."
|
||||
cp -r ../assets/img/* ./assets/img/
|
||||
|
||||
# Generate reStructuredText files from Python modules using sphinx-apidoc
|
||||
apidoc:
|
||||
@echo "Running sphinx-apidoc..."
|
||||
sphinx-apidoc -f -o $(SPHINX_SOURCE_DIR)/modules $(SPHINX_SOURCE_DIR)
|
||||
|
||||
# "help" target does not copy images
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
# HTML target depends on apidoc so that sphinx-apidoc runs first
|
||||
html: copy-images apidoc
|
||||
@$(SPHINXBUILD) -M html "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
|
@ -1,3 +1,6 @@
|
||||
Hier die angepasste Version der README.md mit Erläuterungen zu den zusätzlichen Befehlen:
|
||||
|
||||
```markdown
|
||||
# Documentation
|
||||
|
||||
CyMaIS uses [Sphinx](https://www.sphinx-doc.org/) to automatically generate its documentation and leverages the [Awesome Sphinx Theme](https://sphinxawesome.xyz/) for a sleek and responsive design. Enjoy a seamless, visually engaging experience 🚀✨.
|
||||
@ -18,13 +21,39 @@ To generate the documentation locally, run the following command:
|
||||
pkgmgr shell cymais -c "make refresh"
|
||||
```
|
||||
|
||||
This command cleans the previous build and generates the updated documentation. Once complete, you can view it at the output location (e.g., [templates/html/index.html](templates/html/index.html)) 👀💻.
|
||||
This command performs the following steps:
|
||||
- **Copy Images:** Before building, it copies the necessary image assets from `../assets/img/` to `./assets/img/` using the `copy-images` target.
|
||||
- **Generate API Documentation:** It executes `sphinx-apidoc` (via the `apidoc` target) to automatically generate reStructuredText files for all Python modules. These files are stored under a designated directory (e.g., `modules`), ensuring that every Python file is included in the documentation.
|
||||
- **Build HTML Documentation:** Finally, it builds the HTML documentation using `sphinx-build` (triggered by the `html` target).
|
||||
|
||||
Once complete, you can view the documentation at the output location (e.g., [templates/html/index.html](templates/html/index.html)) 👀💻.
|
||||
|
||||
#### On Server
|
||||
|
||||
The same commands can be used on the server to ensure that documentation is always up to date. Make sure the server environment is properly configured with the necessary Python packages and assets.
|
||||
|
||||
### Additional Commands
|
||||
|
||||
- **`make copy-images`:**
|
||||
Copies image files from the assets directory into the local documentation directory. This ensures that all required images are available for the generated documentation.
|
||||
|
||||
- **`make apidoc`:**
|
||||
Runs `sphinx-apidoc` to scan all Python files in the source directory and generate corresponding reStructuredText files. This automates the inclusion of all Python modules into the Sphinx documentation.
|
||||
|
||||
- **`make html`:**
|
||||
This target depends on the `apidoc` target. It first generates the API documentation and then builds the HTML documentation using `sphinx-build`. This is the standard target to produce the final, viewable documentation.
|
||||
|
||||
- **`make refresh`:**
|
||||
A custom target (typically defined as a combination of cleaning the previous build and then running `make html`) that ensures the documentation is regenerated from scratch with the latest changes.
|
||||
|
||||
### Debug
|
||||
To debug and produce an .log execute:
|
||||
|
||||
To debug and produce a log file, execute:
|
||||
|
||||
```bash
|
||||
pkgmgr shell cymais -c "make refresh SPHINXOPTS='-v -c .' 2>&1 | tee debug.log"
|
||||
```
|
||||
|
||||
This command increases the verbosity of the Sphinx build process and redirects all output to `debug.log`, which is useful for troubleshooting any issues during the documentation build.
|
||||
|
||||
```
|
@ -16,6 +16,13 @@ project = 'CyMaIS - Cyber Master Infrastructure Solution'
|
||||
copyright = '2025, Kevin Veen-Birkenbach'
|
||||
author = 'Kevin Veen-Birkenbach'
|
||||
|
||||
# Highlighting for Jinja
|
||||
from sphinx.highlighting import lexers
|
||||
from pygments.lexers.templates import DjangoLexer
|
||||
|
||||
lexers['jinja'] = DjangoLexer()
|
||||
lexers['j2'] = DjangoLexer()
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
templates_path = ['templates']
|
||||
exclude_patterns = ['docs', 'venv', 'venv/**']
|
||||
@ -54,6 +61,9 @@ extensions = [
|
||||
'extensions.local_subfolders',
|
||||
'extensions.roles_overview',
|
||||
'extensions.markdown_include',
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.napoleon', # Optional, wenn Sie Google- oder NumPy-Dokstrings verwenden
|
||||
|
||||
]
|
||||
|
||||
autosummary_generate = True
|
||||
@ -62,7 +72,29 @@ myst_enable_extensions = [
|
||||
"colon_fence",
|
||||
]
|
||||
|
||||
import logging
|
||||
from docutils import nodes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def replace_assets_in_doctree(app, doctree, docname):
|
||||
# Replace asset references in image nodes
|
||||
for node in doctree.traverse(nodes.image):
|
||||
if "assets/" in node['uri']:
|
||||
new_uri = node['uri'].replace("assets/", "_static/")
|
||||
node['uri'] = new_uri
|
||||
logger.info("Replaced image URI in {}: {}".format(docname, new_uri))
|
||||
|
||||
# Replace asset references in raw HTML nodes
|
||||
for node in doctree.traverse(nodes.raw):
|
||||
if node.get('format') == 'html' and "assets/" in node.astext():
|
||||
new_text = node.astext().replace("assets/", "_static/")
|
||||
node.children = [nodes.raw('', new_text, format='html')]
|
||||
logger.info("Replaced raw HTML assets in {}.".format(docname))
|
||||
|
||||
def setup(app):
|
||||
app.connect("doctree-resolved", replace_assets_in_doctree)
|
||||
|
||||
python_domain = app.registry.domains.get('py')
|
||||
if python_domain is not None:
|
||||
directive = python_domain.directives.get('currentmodule')
|
||||
|
@ -1,4 +1,5 @@
|
||||
myst-parser
|
||||
sphinx
|
||||
sphinxawesome-theme
|
||||
docutils
|
||||
docutils
|
||||
sphinxcontrib-jinja
|
@ -1,5 +1,5 @@
|
||||
<div class="sidebar-logo" style="text-align: center; margin-bottom: 1em;">
|
||||
<img src="{{ pathto("assets/img/logo_cymais.png", 1) }}" alt="Logo" style="max-width: 100%;">
|
||||
<img src="{{ pathto("_static/img/logo.png", 1) }}" alt="Logo" style="max-width: 100%;">
|
||||
</div>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user