diff --git a/docs/docsite/.templates/banner.html b/docs/docsite/.templates/banner.html index d4ece6636da..f20bdd8ee2d 100644 --- a/docs/docsite/.templates/banner.html +++ b/docs/docsite/.templates/banner.html @@ -1,10 +1,4 @@ -{% if is_eol %} -{# Creates a banner at the top of the page for EOL versions. #} - -{% else %} - -{% endif %} + diff --git a/docs/docsite/.templates/eol_banner.html b/docs/docsite/.templates/eol_banner.html new file mode 100644 index 00000000000..f28df49da7b --- /dev/null +++ b/docs/docsite/.templates/eol_banner.html @@ -0,0 +1,6 @@ +{# Creates a banner at the top of the page for EOL versions. #} + diff --git a/docs/docsite/rst/_ext/__init__.py b/docs/docsite/rst/_ext/__init__.py new file mode 100644 index 00000000000..bb3b751bbe9 --- /dev/null +++ b/docs/docsite/rst/_ext/__init__.py @@ -0,0 +1,5 @@ +from .eol_version import setup + +__version__ = '1.0.0' + +__all__ = ['setup'] diff --git a/docs/docsite/rst/_ext/eol_version.py b/docs/docsite/rst/_ext/eol_version.py new file mode 100644 index 00000000000..673d2eae0ed --- /dev/null +++ b/docs/docsite/rst/_ext/eol_version.py @@ -0,0 +1,55 @@ +import subprocess +from pathlib import Path +from typing import Any, Dict + +import yaml +from docutils import nodes +from jinja2 import Template +from sphinx.transforms import Transform + + +class EOLVersionCheck(Transform): + # pylint: disable=too-few-public-methods + default_priority = 999 + + def apply(self) -> None: + env = self.document.settings.env + app = env.app + + if app.tags.has("core"): + build_type = "core" + elif app.tags.has("ansible"): + build_type = "package" + else: + return + + try: + branch = subprocess.check_output( + ["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True + ).strip() + except subprocess.CalledProcessError as e: + print(f"Git error: {e}") + return + + yaml_path = Path(env.srcdir).parent / "versions.yaml" + template_path = Path(env.srcdir).parent / ".templates" / "eol_banner.html" + + with open(yaml_path, "r", encoding="utf-8") as f: + versions = yaml.safe_load(f) + + with open(template_path, "r", encoding="utf-8") as f: + template = Template(f.read()) + + if branch in versions[build_type]["eol"]: + banner_html = template.render() + banner = nodes.raw("", banner_html, format="html") + self.document.insert(0, banner) + + +def setup(app) -> Dict[str, Any]: + app.add_transform(EOLVersionCheck) + return { + "version": "1.0", + "parallel_read_safe": True, + "parallel_write_safe": True, + } diff --git a/docs/docsite/rst/conf.py b/docs/docsite/rst/conf.py index 011ab32baea..f3465fcef5e 100644 --- a/docs/docsite/rst/conf.py +++ b/docs/docsite/rst/conf.py @@ -25,6 +25,7 @@ # sys.path.append(os.path.abspath('some/directory')) # sys.path.insert(0, os.path.join('ansible', 'lib')) +sys.path.insert(0, os.path.abspath('.')) # We want sphinx to document the ansible modules contained in this repository, # not those that may happen to be installed in the version @@ -65,6 +66,7 @@ 'notfound.extension', 'sphinx_antsibull_ext', # provides CSS for the plugin/module docs generated by antsibull 'sphinx_copybutton', + '_ext.eol_version', ] # Later on, add 'sphinx.ext.viewcode' to the list if you want to have @@ -227,7 +229,6 @@ html_context = { 'display_github': 'True', 'show_sphinx': False, - 'is_eol': False, 'github_user': 'ansible', 'github_repo': 'ansible-documentation', 'github_version': 'devel', diff --git a/docs/docsite/versions.yaml b/docs/docsite/versions.yaml new file mode 100644 index 00000000000..29f9fe4681e --- /dev/null +++ b/docs/docsite/versions.yaml @@ -0,0 +1,20 @@ +package: + active: + - devel + - stable-2.18 + - stable-2.17 + - stable-2.16 + eol: + - stable-2.15 + - stable-2.14 + - stable-2.13 +core: + active: + - devel + - stable-2.18 + - stable-2.17 + - stable-2.16 + eol: + - stable-2.15 + - stable-2.14 + - stable-2.13