From 70be620ebb5b1f57f9cf9d6393e6625f5c6f4269 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 4 Oct 2019 08:09:21 -0700 Subject: [PATCH] Remove the sidebar from pages in the Dash docset --- build.py | 30 +++++++++++++++++++++++++++-- docs/sphinx/_static/css/phoenix.css | 8 ++++++++ sphinxtools/postprocess.py | 5 ++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/build.py b/build.py index e74c539f..fa44ec5a 100755 --- a/build.py +++ b/build.py @@ -989,12 +989,13 @@ def cmd_docset_wx(options, args): def cmd_docset_py(options, args): cmdTimer = CommandTimer('docset_py') + cfg = Config(noWxConfig=True) if not os.path.isdir('docs/html'): - msg('ERROR: No docs/html, has the sphinx build command been run?') + msg('ERROR: No docs/html dir found, has the sphinx build command been run?') sys.exit(1) # clear out any old docset build - name = 'wxPython-{}'.format(version3) + name = 'wxPython-{}'.format(cfg.VERSION) docset = posixjoin('dist', '{}.docset'.format(name)) if os.path.isdir(docset): shutil.rmtree(docset) @@ -1010,6 +1011,31 @@ def cmd_docset_py(options, args): '--destination dist docs/html'] runcmd(' '.join(cmd)) + # Remove the sidebar from the pages in the docset + msg('Removing sidebar from docset pages...') + _removeSidebar(opj('dist', name+'.docset', 'Contents', 'Resources', 'Documents')) + + +def _removeSidebar(path): + """ + Remove the sidebar
from the pages going into the docset + """ + from bs4 import BeautifulSoup + for filename in glob.glob(opj(path, '*.html')): + with textfile_open(filename, 'rt') as f: + text = f.read() + text = text.replace('', '') + soup = BeautifulSoup(text, 'html.parser') + tag = soup.find('div', 'sphinxsidebar') + if tag: + tag.extract() + tag = soup.find('div', 'document') + if tag: + tag.attrs['class'] = ['document-no-sidebar'] + text = unicode(soup) if PY2 else str(soup) + with textfile_open(filename, 'wt') as f: + f.write(text) + def cmd_docset(options, args): cmd_docset_wx(options, args) diff --git a/docs/sphinx/_static/css/phoenix.css b/docs/sphinx/_static/css/phoenix.css index 5932dea6..e652f67c 100644 --- a/docs/sphinx/_static/css/phoenix.css +++ b/docs/sphinx/_static/css/phoenix.css @@ -114,6 +114,14 @@ div.document { top: 30px; } +div.document-no-sidebar { + background-color: rgb(230,230,230); + position: relative; + margin-left: 0px; + z-index: 0; + top: 30px; +} + div.sphinxsidebar { background-color: rgb(230,230,230); margin-left: 0; diff --git a/sphinxtools/postprocess.py b/sphinxtools/postprocess.py index f8a9a37a..03738af4 100644 --- a/sphinxtools/postprocess.py +++ b/sphinxtools/postprocess.py @@ -25,6 +25,9 @@ from .constants import HTML_REPLACE, TODAY, SPHINXROOT, SECTIONS_EXCLUDE from .constants import CONSTANT_INSTANCES, WIDGETS_IMAGES_ROOT, SPHINX_IMAGES_ROOT from .constants import DOCSTRING_KEY +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 + # ----------------------------------------------------------------------- # @@ -765,7 +768,7 @@ def removeHeaderImage(text, options): tag = soup.find('div', 'headerimage') if tag: tag.extract() - text = unicode(soup) if sys.version_info < (3,) else str(soup) + text = unicode(soup) if PY2 else str(soup) #text = text.replace('class="headerimage"', 'class="headerimage-noshow"') return text