From 5371a0da275578cda842629b7c7568a8b1017c5b Mon Sep 17 00:00:00 2001 From: Jonathan Guyer Date: Tue, 12 Sep 2023 12:25:32 -0400 Subject: [PATCH] Make NIST header/footer optional Conflicts with [sphinx_rtd_theme](https://sphinx-rtd-theme.readthedocs.io/). --- .github/workflows/NISTtheDocs2Death.yml | 1 + action.yml | 11 +++++++++++ ntd2d/action.yml | 10 ++++++++++ ntd2d/ntd2d.py | 4 +++- .../files/templates/header_footer_script.html | 1 + ntd2d/ntd2d_action/files/templates/ntd2d/layout.html | 2 +- ntd2d/ntd2d_action/sphinxdocs.py | 10 ++++++++-- 7 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 ntd2d/ntd2d_action/files/templates/header_footer_script.html diff --git a/.github/workflows/NISTtheDocs2Death.yml b/.github/workflows/NISTtheDocs2Death.yml index 0353245..7255e55 100644 --- a/.github/workflows/NISTtheDocs2Death.yml +++ b/.github/workflows/NISTtheDocs2Death.yml @@ -10,6 +10,7 @@ jobs: with: docs-folder: docs/ pip-requirements: docs/requirements.txt + insert-header-footer: false formats: |- epub pdf diff --git a/action.yml b/action.yml index 5f46aaa..fce59b7 100644 --- a/action.yml +++ b/action.yml @@ -73,6 +73,16 @@ inputs: options: - true - false + insert-header-footer: + description: + Whether to insert the NIST branding headers and footers + (which are incompatible with sphinx_rtd_theme). + # Idiot GitHub Actions inputs doesn't support 'type'. + # https://stackoverflow.com/questions/76292948/github-action-boolean-input-with-default-value + default: 'true' + options: + - true + - false runs: using: "composite" steps: @@ -121,6 +131,7 @@ runs: apt-packages: ${{ inputs.apt-packages }} pip-requirements: ${{ inputs.pip-requirements }} conda-environment: ${{ inputs.conda-environment }} + insert-header-footer: ${{ inputs.insert-header-footer }} - name: Change ownership shell: bash run: | diff --git a/ntd2d/action.yml b/ntd2d/action.yml index 2c9a69d..3621224 100644 --- a/ntd2d/action.yml +++ b/ntd2d/action.yml @@ -63,6 +63,16 @@ inputs: The path to the Conda environment file, relative to the root of the project. required: false + insert-header-footer: + description: + Whether to insert the NIST branding headers and footers + (which are incompatible with sphinx_rtd_theme). + # Idiot GitHub Actions inputs doesn't support 'type'. + # https://stackoverflow.com/questions/76292948/github-action-boolean-input-with-default-value + default: 'true' + options: + - true + - false outputs: borged-docs-folder: description: 'The folder containing modified Sphinx configuration' diff --git a/ntd2d/ntd2d.py b/ntd2d/ntd2d.py index 344f4bc..474ba19 100755 --- a/ntd2d/ntd2d.py +++ b/ntd2d/ntd2d.py @@ -13,7 +13,9 @@ def main(): with gha_utils.group("Borg the Docs", use_subprocess=True): original_docs = SphinxDocs(docs_dir=os.environ['INPUT_DOCS-FOLDER']) docs = BorgedSphinxDocs(original_docs=original_docs) - docs.assimilate_theme(name="ntd2d") + insert_header_footer = (os.environ['INPUT_INSERT-HEADER-FOOTER'] == "true") + docs.assimilate_theme(name="ntd2d", + insert_header_footer=insert_header_footer) gha_utils.set_output("borged-build-folder", docs.build_dir.as_posix()) diff --git a/ntd2d/ntd2d_action/files/templates/header_footer_script.html b/ntd2d/ntd2d_action/files/templates/header_footer_script.html new file mode 100644 index 0000000..1e9e211 --- /dev/null +++ b/ntd2d/ntd2d_action/files/templates/header_footer_script.html @@ -0,0 +1 @@ + diff --git a/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html b/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html index f2bf688..7b9a64f 100644 --- a/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html +++ b/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html @@ -5,7 +5,7 @@ - + {header_footer_script} {{% endblock %}} diff --git a/ntd2d/ntd2d_action/sphinxdocs.py b/ntd2d/ntd2d_action/sphinxdocs.py index 7aee5c9..8c6525a 100644 --- a/ntd2d/ntd2d_action/sphinxdocs.py +++ b/ntd2d/ntd2d_action/sphinxdocs.py @@ -138,13 +138,19 @@ def make_conf_file(self): def inherited_theme(self): return self.original_docs.conf.html_theme - def assimilate_theme(self, name): + def assimilate_theme(self, name, insert_header_footer=True): """Replace configuration directory with customized html theme.""" + if insert_header_footer: + header_footer = FileTemplate(name="header_footer_script.html").read() + else: + header_footer = "" + self.theme = TemplateHierarchy(name=name, destination_dir=self.conf.theme_path, inherited_theme=self.inherited_theme, - inherited_css=self.stylesheet) + inherited_css=self.stylesheet, + header_footer_script=header_footer) self.theme.write() self.conf.set_html_theme(name=name)