Add sphinx extension to use non-underscore names in built html, so GH pages doesn't exclude them.
This commit is contained in:
parent
622dd47c58
commit
f0b3f79a32
@ -16,7 +16,8 @@ import sys, os
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path.insert(0, os.path.abspath('..')) # Folder containing mceditlib
|
||||
sys.path.insert(0, os.path.abspath('..')) # Folder containing mceditlib
|
||||
sys.path.insert(0, os.path.abspath('extensions')) # extensions
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
@ -25,7 +26,7 @@ sys.path.insert(0, os.path.abspath('..')) # Folder containing mceditlib
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx_nounderscore']
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
37
doc/extensions/sphinx_nounderscore.py
Normal file
37
doc/extensions/sphinx_nounderscore.py
Normal file
@ -0,0 +1,37 @@
|
||||
"""
|
||||
:Description: Sphinx extension to remove leading under-scores from directories names in the html build output directory.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
def setup(app):
|
||||
"""
|
||||
Add a html-page-context and a build-finished event handlers
|
||||
"""
|
||||
app.connect('html-page-context', change_pathto)
|
||||
app.connect('build-finished', move_private_folders)
|
||||
|
||||
def change_pathto(app, pagename, templatename, context, doctree):
|
||||
"""
|
||||
Replace pathto helper to change paths to folders with a leading underscore.
|
||||
"""
|
||||
pathto = context.get('pathto')
|
||||
def gh_pathto(otheruri, *args, **kw):
|
||||
if otheruri.startswith('_'):
|
||||
otheruri = otheruri[1:]
|
||||
return pathto(otheruri, *args, **kw)
|
||||
context['pathto'] = gh_pathto
|
||||
|
||||
def move_private_folders(app, e):
|
||||
"""
|
||||
remove leading underscore from folders in in the output folder.
|
||||
|
||||
:todo: should only affect html built
|
||||
"""
|
||||
def join(dir):
|
||||
return os.path.join(app.builder.outdir, dir)
|
||||
|
||||
for item in os.listdir(app.builder.outdir):
|
||||
if item.startswith('_') and os.path.isdir(join(item)):
|
||||
shutil.move(join(item), join(item[1:]))
|
Reference in New Issue
Block a user