mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-04-28 10:26:54 +02:00
Compare commits
No commits in common. "74edb197debbcd7ce0a528bd67a709e1fdae5f2f" and "2095f164028a26490a39e1c649f47af7ef04a549" have entirely different histories.
74edb197de
...
2095f16402
@ -1,10 +1,11 @@
|
||||
# CyMaIS NonCommercial License (CNCL)
|
||||
# License Agreement
|
||||
## CyMaIS NonCommercial License (CNCL)
|
||||
|
||||
## Definitions
|
||||
### Definitions
|
||||
- **"Software":** Refers to *"[CyMaIS - Cyber Master Infrastructure Solution](https://cymais.cloud/)"* and its associated source code.
|
||||
- **"Commercial Use":** Any use of the Software intended for direct or indirect financial gain, including but not limited to sales, rentals, or provision of services.
|
||||
|
||||
## Provisions
|
||||
### Provisions
|
||||
|
||||
1. **Attribution of the Original Licensor:** In any distribution or publication of the Software or derivative works, the original licensor, *Kevin Veen-Birkenbach, Email: [license@veen.world](mailto:license@veen.world), Website: [https://www.veen.world/](https://www.veen.world/)* must be explicitly named.
|
||||
|
||||
@ -23,5 +24,5 @@
|
||||
|
||||
7. **Ownership of Rights:** All rights, including copyright, trademark, and other forms of intellectual property related to the Software, belong exclusively to Kevin Veen-Birkenbach.
|
||||
|
||||
## Consent
|
||||
### Consent
|
||||
By using, modifying, or distributing the Software, you agree to these terms.
|
@ -1,4 +1,5 @@
|
||||
# CyMaIS - Cyber Master Infrastructure Solution
|
||||
# CyMaIS
|
||||
## Cyber Master Infrastructure Solution
|
||||
[](https://github.com/sponsors/kevinveenbirkenbach) [](https://www.patreon.com/c/kevinveenbirkenbach) [](https://buymeacoffee.com/kevinveenbirkenbach) [](https://s.veen.world/paypaldonate)
|
||||
|
||||
|
||||
@ -14,7 +15,7 @@ Our intuitive interface, coupled with in-depth documentation, makes it accessibl
|
||||
|
||||
With CyMaIS, setting up a secure, scalable, and robust IT infrastructure is not just faster and easier, but also aligned with the best industry practices, ensuring that your organization stays ahead in the ever-evolving digital landscape.
|
||||
|
||||
## Vision
|
||||
### Vision
|
||||
Our project is anchored in the vision of transforming IT infrastructure deployment into a seamless, secure, and scalable experience.
|
||||
|
||||
We are committed to developing a fully automated solution that enables businesses of any size and industry to set up a 100% secure and infinitely scalable IT infrastructure in just 24 hours.
|
||||
@ -45,7 +46,7 @@ For a deeper understanding of our goals and the ethos driving our project, we in
|
||||
|
||||
CyMaIS is more than just an IT solution; it's a commitment to empowering your business with the technology it needs to thrive in today’s digital landscape, effortlessly and securely.
|
||||
|
||||
## Professional CyMaIS Implementation
|
||||
### Professional CyMaIS Implementation
|
||||
<img src="https://cybermaster.space/wp-content/uploads/sites/7/2023/11/FVG_8364BW-scaled.jpg" width="300" style="float: right; margin-left: 30px;">
|
||||
|
||||
My name is Kevin Veen-Birkenbach and I'm glad to assist you in the implementation of your secure and scalable IT infrastrucutre solution with CyMaIS.
|
||||
@ -60,6 +61,6 @@ Contact me for more details:
|
||||
📧 Email: [kevin@veen.world](mailto:kevin@veen.world)<br />
|
||||
☎️ Phone: [+ 49 178 179 80 23](tel:00491781798023)
|
||||
|
||||
## License
|
||||
### License
|
||||
|
||||
This project is licensed from Kevin Veen-Birkenbach. The full license is available in the [LICENSE.md](./LICENSE.md) of this repository.
|
||||
|
@ -550,8 +550,8 @@ defaults_applications:
|
||||
## Sphinx
|
||||
sphinx:
|
||||
version: "3.9-slim" # Use latest docker image
|
||||
repository_sphinx_source: "https://github.com/kevinveenbirkenbach/cymais.git" # Repository address to pull the source repository from
|
||||
sphinx_exec_dir_relative: "sphinx/" # The relative path to the sphinx Makefile folder from the source dir
|
||||
volumes:
|
||||
source_dir: "{ansible_playbook_dir}" # Path from which sphinx reads the documentation
|
||||
|
||||
|
||||
## Taiga
|
||||
|
@ -1,4 +1,3 @@
|
||||
Applications by Category
|
||||
=========================
|
||||
# Applications by Category
|
||||
|
||||
.. roles-overview::
|
@ -676,7 +676,6 @@ navigation:
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
- name: Support Us
|
||||
description: "Discover all the ways you can support our work."
|
||||
icon:
|
||||
@ -702,17 +701,13 @@ navigation:
|
||||
icon:
|
||||
class: fa-brands fa-github
|
||||
url: https://s.veen.world/githubsponsors
|
||||
|
||||
{% if "sphinx" in group_names %}
|
||||
|
||||
- name: Documentation
|
||||
{% if "spinx" in group_names %}
|
||||
- name: Documentation & Support
|
||||
description: Access our comprehensive documentation and support resources to help you get the most out of the software.
|
||||
icon:
|
||||
class: fas fa-book
|
||||
url: https://{{domains.sphinx}}
|
||||
|
||||
{% endif %}
|
||||
|
||||
- name: Imprint
|
||||
description: Check out the imprint information
|
||||
icon:
|
||||
|
@ -1,33 +0,0 @@
|
||||
ARG DOCKER_PYTHON_VERSION
|
||||
FROM python:${DOCKER_PYTHON_VERSION}
|
||||
|
||||
ARG SPHINX_SOURCE_DIR
|
||||
ARG SPHINX_BUILD_DIR
|
||||
ARG SPHINX_EXEC_DIR
|
||||
ARG SPHINX_APP_DIR
|
||||
ARG SPHINX_SOURCE_DIR_RELATIVE
|
||||
|
||||
# Set the environment variables so they are available during build for Makefile
|
||||
ENV SPHINX_SOURCE_DIR=${SPHINX_SOURCE_DIR}
|
||||
ENV SPHINX_BUILD_DIR=${SPHINX_BUILD_DIR}
|
||||
|
||||
# Install required packages
|
||||
RUN apt-get update && apt-get install -y make curl
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR ${SPHINX_APP_DIR}
|
||||
|
||||
# Copy the project files into the container
|
||||
COPY ${SPHINX_SOURCE_DIR_RELATIVE} ${SPHINX_APP_DIR}
|
||||
|
||||
# Install Python packages via requirements.txt
|
||||
RUN cd ${SPHINX_EXEC_DIR} && pip install --upgrade pip && pip install -r requirements.txt
|
||||
|
||||
# Build the HTML documentation using Sphinx with the defined directories
|
||||
RUN cd ${SPHINX_EXEC_DIR} && make html
|
||||
|
||||
# Expose port 8000 where the HTTP server will run
|
||||
EXPOSE 8000
|
||||
|
||||
# Start a simple HTTP server to serve the built documentation
|
||||
CMD python -m http.server 8000 --directory "${SPHINX_BUILD_DIR}html/"
|
@ -4,19 +4,12 @@
|
||||
include_role:
|
||||
name: docker-compose
|
||||
|
||||
- name: "Create {{ host_sphinx_source_dir_absolute }} directory"
|
||||
file:
|
||||
path: "{{ host_sphinx_source_dir_absolute }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: pull the source repository to build the Sphinx documentation from {{ applications.sphinx.repository_sphinx_source }}
|
||||
- name: pull cymais repository
|
||||
git:
|
||||
repo: "{{ applications.sphinx.repository_sphinx_source }}"
|
||||
dest: "{{ host_sphinx_source_dir_absolute }}"
|
||||
repo: "{{ repository_address_cymais }}"
|
||||
dest: "{{ host_cymais_volume_dir_absolute }}"
|
||||
update: yes
|
||||
clone: yes
|
||||
notify: docker compose project build and setup
|
||||
notify: docker compose project setup
|
||||
become: true
|
||||
|
||||
- name: "include role nginx-domain-setup for {{application_id}}"
|
||||
@ -27,12 +20,12 @@
|
||||
http_port: "{{ ports.localhost.http[application_id] }}"
|
||||
|
||||
- name: "create {{ sphinx_docker_file }}"
|
||||
copy:
|
||||
src: "Dockerfile"
|
||||
template:
|
||||
src: "Dockerfile.j2"
|
||||
dest: "{{ sphinx_docker_file }}"
|
||||
mode: '770'
|
||||
force: yes
|
||||
notify: docker compose project build and setup
|
||||
notify: docker compose project setup
|
||||
|
||||
- name: "copy docker-compose.yml and env file"
|
||||
include_tasks: copy-docker-compose-and-env.yml
|
22
roles/docker-sphinx/templates/Dockerfile.j2
Normal file
22
roles/docker-sphinx/templates/Dockerfile.j2
Normal file
@ -0,0 +1,22 @@
|
||||
FROM python:{{applications[application_id].version}}
|
||||
|
||||
# Install required packages including 'make'
|
||||
RUN apt-get update && apt-get install -y make
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR {{docker_app_dir}}
|
||||
|
||||
# Copy the project files into the container
|
||||
COPY {{host_cymais_volume_dir_relative}} {{docker_app_dir}}
|
||||
|
||||
# Install Python packages via requirements.txt
|
||||
RUN cd {{docker_sphinx_dir}} && pip install --upgrade pip && pip install -r requirements.txt
|
||||
|
||||
# Build the HTML documentation using Sphinx with the defined directories
|
||||
RUN cd {{docker_sphinx_dir}} && make html
|
||||
|
||||
# Expose port 8000 where the HTTP server will run
|
||||
EXPOSE 8000
|
||||
|
||||
# Start a simple HTTP server to serve the built documentation
|
||||
CMD ["python", "-m", "http.server", "8000", "--directory", "${BUILD_DIR}"]
|
@ -1,15 +1,6 @@
|
||||
services:
|
||||
application:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
SPHINX_SOURCE_DIR: {{docker_source_dir}}
|
||||
SPHINX_BUILD_DIR: {{docker_output_dir}}
|
||||
SPHINX_EXEC_DIR: {{docker_exec_dir}}
|
||||
SPHINX_APP_DIR: {{docker_app_dir}}
|
||||
SPHINX_SOURCE_DIR_RELATIVE: {{host_sphinx_source_dir_relative}}
|
||||
DOCKER_PYTHON_VERSION: {{applications[application_id].version}}
|
||||
build: .
|
||||
ports:
|
||||
- "127.0.0.1:{{ports.localhost.http[application_id]}}:8000"
|
||||
healthcheck:
|
||||
@ -17,7 +8,6 @@ services:
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
|
||||
{% include 'templates/docker/container/networks.yml.j2' %}
|
||||
|
||||
{% include 'templates/docker/compose/networks.yml.j2' %}
|
||||
|
@ -0,0 +1,2 @@
|
||||
SOURCE_DIR={{docker_source_dir}}
|
||||
BUILD_DIR={{docker_output_dir}}
|
@ -1,11 +1,13 @@
|
||||
application_id: "sphinx"
|
||||
|
||||
host_sphinx_source_dir_relative: "volumes/source/" # Place where the sphinx source repository is stored on the host
|
||||
host_sphinx_source_dir_absolute: "{{docker_compose.directories.instance}}{{host_sphinx_source_dir_relative}}" # Place where the sphinx source repository is stored on the host
|
||||
repository_address_cymais: "https://github.com/kevinveenbirkenbach/cymais.git" # Repository address to pull cymais from
|
||||
|
||||
host_cymais_volume_dir_absolute: "{{docker_compose.directories.volumes}}cymais/" # Place where the cymais repository is stored on the host
|
||||
host_cymais_volume_dir_relative: "volumes/cymais/" # Place where the cymais repository is stored on the host
|
||||
|
||||
docker_app_dir: "/app/" # Folder in which the application is running
|
||||
docker_source_dir: "{{docker_app_dir}}" # Folder which is used to be screened
|
||||
docker_output_dir: "/docs/" # Folder to which the output is fuuuucking putted!
|
||||
docker_exec_dir: "{{docker_app_dir}}{{applications.sphinx.sphinx_exec_dir_relative}}" # Folder which contains the sphinxs makefile and logic
|
||||
docker_sphinx_dir: "{{docker_app_dir}}/sphinx/" # Folder which contains the sphinxs makefile and logic
|
||||
|
||||
sphinx_docker_file: "{{ docker_compose.directories.instance }}Dockerfile" # Path to the Dockerfile to build sphinx
|
||||
sphinx_docker_file: "{{ docker_compose.directories.instance }}/Dockerfile"
|
@ -1,5 +1,4 @@
|
||||
Application Glosar
|
||||
===================
|
||||
# Application Glosar
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
@ -605,21 +605,7 @@ html[native-dark-active] my-app button, button {
|
||||
--dropdown-item-hover-bg: var(--color-05); /* Hover background: very dark */
|
||||
--dropdown-item-hover-color: var(--color-60); /* Hover text: a bit lighter */
|
||||
--dropdown-item-color: var(--color-70); /* Regular dropdown item text */
|
||||
--dropdown-item-active-color: var(--color-99); /* Active state: very light (white) */
|
||||
}
|
||||
|
||||
/** Sphinx **/
|
||||
.bg-background\/95 {
|
||||
background-color: var(--color-96);
|
||||
}
|
||||
|
||||
.border-border {
|
||||
border-color: var(--color-85);
|
||||
}
|
||||
|
||||
{# Hide Toogle Button #}
|
||||
nav.flex.items-center.space-x-1{
|
||||
display:none;
|
||||
--dropdown-item-active-color: var(--color-99);/* Active state: very light (white) */
|
||||
}
|
||||
|
||||
/** Taiga **/
|
||||
|
@ -2,19 +2,19 @@
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?= -c .
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SPHINX_SOURCE_DIR ?= ../
|
||||
SPHINX_BUILD_DIR ?= ../docs
|
||||
SOURCE_DIR = ../
|
||||
BUILD_DIR = ../docs
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
@$(SPHINXBUILD) -M help "$(SOURCE_DIR)" "$(BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help install Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCE_DIR)" "$(BUILD_DIR)" $(SPHINXOPTS) $(O)
|
||||
|
@ -1,19 +1,25 @@
|
||||
{% macro render_headings(headings) %}
|
||||
<ul>
|
||||
{% for item in headings %}
|
||||
<li>
|
||||
<a href="{{ pathto(item.link).replace("#", "") + '#' + item.anchor }}">{{ item.text }}</a>
|
||||
{% if item.children %}
|
||||
{{ render_headings(item.children) }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endmacro %}
|
||||
|
||||
{% if local_md_headings %}
|
||||
<div class="local-md-headings">
|
||||
<h3>Overview</h3>
|
||||
{{ render_headings(local_md_headings) }}
|
||||
<h3>Page Headings</h3>
|
||||
{% set ns = namespace(current_level=0) %}
|
||||
{% for item in local_md_headings %}
|
||||
{# If the current heading level is greater than the previous, open new <ul> tags #}
|
||||
{% if item.level > ns.current_level %}
|
||||
{% for i in range(ns.current_level, item.level) %}
|
||||
<ul>
|
||||
{% endfor %}
|
||||
{# If the current heading level is less than the previous, close the open <ul> tags #}
|
||||
{% elif item.level < ns.current_level %}
|
||||
{% for i in range(item.level, ns.current_level) %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<li><a href="{{ pathto(item.link).replace("#","") + "#" + item.anchor}}">{{ item.text }}</a></li>
|
||||
{% set ns.current_level = item.level %}
|
||||
{% endfor %}
|
||||
{# Close any remaining open <ul> tags #}
|
||||
{% for i in range(ns.current_level) %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@ -25,25 +25,25 @@ exclude_patterns = ['docs', 'venv', 'venv/**']
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'sphinxawesome_theme'
|
||||
html_theme = 'alabaster'
|
||||
html_static_path = ['_static']
|
||||
|
||||
html_sidebars = {
|
||||
'**': [
|
||||
#'globaltoc.html',
|
||||
# 'relations.html',
|
||||
# 'sourcelink.html',
|
||||
'globaltoc.html',
|
||||
'relations.html',
|
||||
'sourcelink.html',
|
||||
'local_md_files.html', # Include your custom template
|
||||
# 'searchbox.html',
|
||||
'searchbox.html',
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
html_theme_options = {
|
||||
# 'fixed_sidebar': True,
|
||||
"show_prev_next": False,
|
||||
'fixed_sidebar': True,
|
||||
}
|
||||
|
||||
# Liste der Dateiendungen, die Sphinx verarbeiten soll:
|
||||
source_suffix = {
|
||||
'.rst': 'restructuredtext',
|
||||
'.md': 'markdown',
|
||||
@ -59,8 +59,10 @@ extensions = [
|
||||
]
|
||||
autosummary_generate = True
|
||||
|
||||
# Optional: Zusätzliche MyST-Konfigurationen
|
||||
myst_enable_extensions = [
|
||||
"colon_fence",
|
||||
"colon_fence", # Für erweiterte Syntax wie ::: Hinweisboxen etc.
|
||||
# weitere Erweiterungen nach Bedarf
|
||||
]
|
||||
|
||||
def setup(app):
|
||||
|
@ -4,9 +4,8 @@ from sphinx.util import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Set the maximum heading level for Markdown headings
|
||||
# Set the maximum heading level to include (e.g., include headings up to H3)
|
||||
MAX_HEADING_LEVEL = 3
|
||||
DEFAULT_MAX_NAV_DEPTH = 2 # Default maximum navigation depth; configurable via conf.py
|
||||
|
||||
def natural_sort_key(text):
|
||||
"""
|
||||
@ -17,38 +16,30 @@ def natural_sort_key(text):
|
||||
|
||||
def extract_headings_from_file(filepath, max_level=MAX_HEADING_LEVEL):
|
||||
"""
|
||||
Extract headings from a file.
|
||||
For Markdown files, look for lines starting with '#' (up to max_level).
|
||||
For reStructuredText files, look for a line immediately followed by an underline made of punctuation.
|
||||
Extract Markdown headings (up to max_level) from the file at filepath.
|
||||
Skips fenced code blocks.
|
||||
"""
|
||||
headings = []
|
||||
ext = os.path.splitext(filepath)[1].lower()
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
if ext == '.md':
|
||||
in_code_block = False
|
||||
for line in f:
|
||||
# Toggle code block state if a line starts with ```
|
||||
if line.strip().startswith("```"):
|
||||
in_code_block = not in_code_block
|
||||
continue
|
||||
if in_code_block:
|
||||
continue
|
||||
# Match Markdown headings: one or more '#' followed by a space and the title.
|
||||
match = re.match(r'^(#{1,})\s+(.*)$', line)
|
||||
if match:
|
||||
level = len(match.group(1))
|
||||
if level <= max_level:
|
||||
heading_text = match.group(2).strip()
|
||||
anchor = re.sub(r'\s+', '-', heading_text.lower())
|
||||
anchor = re.sub(r'[^a-z0-9\-]', '', anchor)
|
||||
headings.append({'level': level, 'text': heading_text, 'anchor': anchor})
|
||||
elif ext == '.rst':
|
||||
lines = f.readlines()
|
||||
for i in range(len(lines)-1):
|
||||
text_line = lines[i].rstrip("\n")
|
||||
underline = lines[i+1].rstrip("\n")
|
||||
if len(underline) >= 3 and re.fullmatch(r'[-=~\^\+"\'`]+', underline):
|
||||
level = 1 # default level; adjust if needed
|
||||
heading_text = text_line.strip()
|
||||
# Create a simple slug for the anchor:
|
||||
# - convert to lowercase
|
||||
# - replace spaces with hyphens
|
||||
# - remove non-alphanumeric characters (except hyphens)
|
||||
anchor = re.sub(r'\s+', '-', heading_text.lower())
|
||||
anchor = re.sub(r'[^a-z0-9\-]', '', anchor)
|
||||
headings.append({'level': level, 'text': heading_text, 'anchor': anchor})
|
||||
@ -56,72 +47,14 @@ def extract_headings_from_file(filepath, max_level=MAX_HEADING_LEVEL):
|
||||
logger.warning(f"Error reading {filepath}: {e}")
|
||||
return headings
|
||||
|
||||
def group_headings(headings):
|
||||
"""
|
||||
Converts a flat list of headings into a tree structure based on their level.
|
||||
Each heading gets a 'children' list.
|
||||
"""
|
||||
tree = []
|
||||
stack = []
|
||||
for heading in headings:
|
||||
heading['children'] = []
|
||||
while stack and stack[-1]['level'] >= heading['level']:
|
||||
stack.pop()
|
||||
if stack:
|
||||
stack[-1]['children'].append(heading)
|
||||
else:
|
||||
tree.append(heading)
|
||||
stack.append(heading)
|
||||
return tree
|
||||
|
||||
def sort_tree(tree):
|
||||
"""
|
||||
Sorts a list of headings (and their children) first by their 'priority' (default 1)
|
||||
and then by the natural sort key of their text.
|
||||
"""
|
||||
tree.sort(key=lambda x: (x.get('priority', 1), natural_sort_key(x['text'])))
|
||||
|
||||
def collect_nav_items(dir_path, base_url, current_depth, max_depth):
|
||||
"""
|
||||
Recursively collects navigation items from subdirectories.
|
||||
For each subdirectory, if an 'index.rst' exists (preferred) or a 'readme.md' exists,
|
||||
the first heading from that file is used as the title.
|
||||
"""
|
||||
nav_items = []
|
||||
# Look for candidate file in this subdirectory (prefer index.rst, then readme.md)
|
||||
candidate = None
|
||||
for cand in ['index.rst', 'readme.md']:
|
||||
candidate_path = os.path.join(dir_path, cand)
|
||||
if os.path.isfile(candidate_path):
|
||||
candidate = cand
|
||||
break
|
||||
if candidate:
|
||||
candidate_path = os.path.join(dir_path, candidate)
|
||||
headings = extract_headings_from_file(candidate_path)
|
||||
if headings:
|
||||
title = headings[0]['text']
|
||||
else:
|
||||
title = os.path.splitext(candidate)[0].capitalize()
|
||||
# Build link relative to base_url
|
||||
link = os.path.join(base_url, os.path.splitext(candidate)[0])
|
||||
nav_items.append({
|
||||
'level': 1,
|
||||
'text': title,
|
||||
'link': link,
|
||||
'anchor': '',
|
||||
'priority': 0
|
||||
})
|
||||
# Recurse into subdirectories if within max_depth
|
||||
if current_depth < max_depth:
|
||||
for item in os.listdir(dir_path):
|
||||
full_path = os.path.join(dir_path, item)
|
||||
if os.path.isdir(full_path):
|
||||
sub_base_url = os.path.join(base_url, item)
|
||||
nav_items.extend(collect_nav_items(full_path, sub_base_url, current_depth + 1, max_depth))
|
||||
return nav_items
|
||||
|
||||
def add_local_md_headings(app, pagename, templatename, context, doctree):
|
||||
"""
|
||||
For every Markdown file in the same directory as the current page,
|
||||
extract its headings, sort them in natural ascending order, and add them
|
||||
to the context.
|
||||
"""
|
||||
srcdir = app.srcdir
|
||||
# Determine the directory of the current page (e.g., "directory/file" -> "directory")
|
||||
directory = os.path.dirname(pagename)
|
||||
abs_dir = os.path.join(srcdir, directory)
|
||||
if not os.path.isdir(abs_dir):
|
||||
@ -129,49 +62,24 @@ def add_local_md_headings(app, pagename, templatename, context, doctree):
|
||||
context['local_md_headings'] = []
|
||||
return
|
||||
|
||||
max_nav_depth = getattr(app.config, 'local_nav_max_depth', DEFAULT_MAX_NAV_DEPTH)
|
||||
|
||||
# Collect navigation items from subdirectories only
|
||||
nav_items = []
|
||||
for item in os.listdir(abs_dir):
|
||||
full_path = os.path.join(abs_dir, item)
|
||||
if os.path.isdir(full_path):
|
||||
nav_items.extend(collect_nav_items(full_path, os.path.join(directory, item), current_depth=1, max_depth=max_nav_depth))
|
||||
|
||||
# Process files in the current directory.
|
||||
files = os.listdir(abs_dir)
|
||||
files_lower = [f.lower() for f in files]
|
||||
# If both index.rst and readme.md exist in the current directory, keep only index.rst.
|
||||
if "index.rst" in files_lower:
|
||||
files = [f for f in files if f.lower() != "readme.md"]
|
||||
local_md_headings = []
|
||||
for file in files:
|
||||
if file.endswith('.md') or file.endswith('.rst'):
|
||||
for file in os.listdir(abs_dir):
|
||||
if file.endswith('.md'):
|
||||
filepath = os.path.join(abs_dir, file)
|
||||
headings = extract_headings_from_file(filepath)
|
||||
basename, _ = os.path.splitext(file)
|
||||
# Set priority: index/readme files get priority 0.
|
||||
if basename.lower() in ['index', 'readme']:
|
||||
priority = 0
|
||||
else:
|
||||
priority = 1
|
||||
for heading in headings:
|
||||
file_link = os.path.join(directory, basename)
|
||||
# Build file link: zunächst Pfad + Dateiname, dann Ersetzen der .md-Endung durch .html
|
||||
file_link = os.path.join(directory, file).replace(".md","") if directory else file
|
||||
local_md_headings.append({
|
||||
'level': heading['level'],
|
||||
'text': heading['text'],
|
||||
'link': file_link,
|
||||
'anchor': heading['anchor'],
|
||||
'priority': priority
|
||||
'anchor': heading['anchor']
|
||||
})
|
||||
# Combine current directory items with subdirectory nav items.
|
||||
# If an index or readme from the current directory exists, it will be included only once.
|
||||
all_items = local_md_headings + nav_items
|
||||
tree = group_headings(all_items)
|
||||
sort_tree(tree)
|
||||
context['local_md_headings'] = tree
|
||||
# Sort headings in natural ascending order using natural_sort_key.
|
||||
local_md_headings.sort(key=lambda x: natural_sort_key(x['text']))
|
||||
context['local_md_headings'] = local_md_headings
|
||||
|
||||
def setup(app):
|
||||
app.add_config_value('local_nav_max_depth', DEFAULT_MAX_NAV_DEPTH, 'env')
|
||||
app.connect('html-page-context', add_local_md_headings)
|
||||
return {'version': '0.1', 'parallel_read_safe': True}
|
||||
|
@ -1,3 +1,3 @@
|
||||
myst-parser
|
||||
sphinx
|
||||
sphinxawesome-theme
|
||||
sphinx-rtd-theme
|
||||
|
Loading…
x
Reference in New Issue
Block a user