Skip to content

Commit

Permalink
Make NIST header/footer optional
Browse files Browse the repository at this point in the history
Conflicts with [sphinx_rtd_theme](https://sphinx-rtd-theme.readthedocs.io/).
  • Loading branch information
guyer committed Sep 12, 2023
1 parent d474c8c commit 5371a0d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/NISTtheDocs2Death.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
with:
docs-folder: docs/
pip-requirements: docs/requirements.txt
insert-header-footer: false
formats: |-
epub
pdf
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand Down
10 changes: 10 additions & 0 deletions ntd2d/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion ntd2d/ntd2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="https://pages.nist.gov/nist-header-footer/js/nist-header-footer.js" type="text/javascript" defer="defer"></script>
2 changes: 1 addition & 1 deletion ntd2d/ntd2d_action/files/templates/ntd2d/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<link rel="stylesheet" href="https://pages.nist.gov/nist-header-footer/css/nist-combined.css">
<script src="https://code.jquery.com/jquery-3.6.2.min.js" type="text/javascript" defer="defer"></script>
<script src="https://pages.nist.gov/nist-header-footer/js/nist-header-footer.js" type="text/javascript" defer="defer"></script>
{header_footer_script}
{{% endblock %}}


Expand Down
10 changes: 8 additions & 2 deletions ntd2d/ntd2d_action/sphinxdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5371a0d

Please sign in to comment.