mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-11-04 12:18:17 +00:00 
			
		
		
		
	Implemented all mds on same level in sidebar
This commit is contained in:
		
							
								
								
									
										10
									
								
								sphinx/_templates/local_md_files.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								sphinx/_templates/local_md_files.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					{% if local_md_files %}
 | 
				
			||||||
 | 
					<div class="local-md-files">
 | 
				
			||||||
 | 
					  <h3>Local Markdown Files</h3>
 | 
				
			||||||
 | 
					  <ul>
 | 
				
			||||||
 | 
					  {% for item in local_md_files %}
 | 
				
			||||||
 | 
					    <li><a href="{{ pathto(item.link) }}">{{ item.name }}</a></li>
 | 
				
			||||||
 | 
					  {% endfor %}
 | 
				
			||||||
 | 
					  </ul>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
@@ -7,6 +7,8 @@
 | 
				
			|||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
 | 
					# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					sys.path.insert(0, os.path.abspath('.'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
project = 'CyMaIS - Cyber Master Infrastructure Solution'
 | 
					project = 'CyMaIS - Cyber Master Infrastructure Solution'
 | 
				
			||||||
copyright = '2025, Kevin Veen-Birkenbach'
 | 
					copyright = '2025, Kevin Veen-Birkenbach'
 | 
				
			||||||
@@ -15,8 +17,6 @@ author = 'Kevin Veen-Birkenbach'
 | 
				
			|||||||
# -- General configuration ---------------------------------------------------
 | 
					# -- General configuration ---------------------------------------------------
 | 
				
			||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
 | 
					# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extensions = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
templates_path = ['_templates']
 | 
					templates_path = ['_templates']
 | 
				
			||||||
exclude_patterns = ['docs', 'venv', 'venv/**']
 | 
					exclude_patterns = ['docs', 'venv', 'venv/**']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,14 +27,18 @@ exclude_patterns = ['docs', 'venv', 'venv/**']
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
html_theme = 'alabaster'
 | 
					html_theme = 'alabaster'
 | 
				
			||||||
html_static_path = ['_static']
 | 
					html_static_path = ['_static']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
html_sidebars = {
 | 
					html_sidebars = {
 | 
				
			||||||
    '**': [
 | 
					    '**': [
 | 
				
			||||||
        'localtoc.html',  # Zeigt die lokale Navigation an
 | 
					        'globaltoc.html',
 | 
				
			||||||
        'relations.html',  # Vorherige/Nächste Seite
 | 
					        'relations.html',
 | 
				
			||||||
        'searchbox.html',  # Suchfeld
 | 
					        'sourcelink.html',
 | 
				
			||||||
 | 
					        'local_md_files.html',  # Include your custom template
 | 
				
			||||||
 | 
					        'searchbox.html',
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
html_theme_options = {
 | 
					html_theme_options = {
 | 
				
			||||||
    'fixed_sidebar': True,
 | 
					    'fixed_sidebar': True,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -49,6 +53,7 @@ extensions = [
 | 
				
			|||||||
    "sphinx.ext.autosummary",
 | 
					    "sphinx.ext.autosummary",
 | 
				
			||||||
    "sphinx.ext.autodoc",
 | 
					    "sphinx.ext.autodoc",
 | 
				
			||||||
    "myst_parser",
 | 
					    "myst_parser",
 | 
				
			||||||
 | 
					    'local_md_files',
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
autosummary_generate = True
 | 
					autosummary_generate = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								sphinx/local_md_files.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								sphinx/local_md_files.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					import os
 | 
				
			||||||
 | 
					from sphinx.util import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					logger = logging.getLogger(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def add_local_md_files(app, pagename, templatename, context, doctree):
 | 
				
			||||||
 | 
					    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):
 | 
				
			||||||
 | 
					        logger.warning(f"Directory {abs_dir} not found for page {pagename}.")
 | 
				
			||||||
 | 
					        context['local_md_files'] = []
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    md_files = []
 | 
				
			||||||
 | 
					    for file in os.listdir(abs_dir):
 | 
				
			||||||
 | 
					        if file.endswith('.md'):
 | 
				
			||||||
 | 
					            # Optionally: Skip the current file in the list
 | 
				
			||||||
 | 
					            if file == os.path.basename(pagename):
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            # Create a link relative to the source directory
 | 
				
			||||||
 | 
					            link = os.path.join(directory, file) if directory else file
 | 
				
			||||||
 | 
					            md_files.append({'name': file, 'link': link})
 | 
				
			||||||
 | 
					    context['local_md_files'] = md_files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def setup(app):
 | 
				
			||||||
 | 
					    # Connect the handler to the "html-page-context" event
 | 
				
			||||||
 | 
					    app.connect('html-page-context', add_local_md_files)
 | 
				
			||||||
 | 
					    return {'version': '0.1', 'parallel_read_safe': True}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user