From d27d89fd344cf3ac8fe48a3e4dd2c4325f4e6aae Mon Sep 17 00:00:00 2001 From: David Garcia Date: Fri, 23 Feb 2024 09:19:04 +0000 Subject: [PATCH] docs: add collapsible for images Introduces collapsible dropdowns for images reference docs. With this update, only the latest version's details will be displayed open by default. Information about previous versions will be hidden under dropdowns, which users can expand as needed. This enhancement aims to make pages shorter and easier to navigate. Closes scylladb/scylladb#17492 --- docs/_ext/scylladb_common_images.py | 10 +++++++--- docs/_templates/aws_image.tmpl | 31 ++++++++++++++++------------- docs/_templates/azure_image.tmpl | 23 +++++++++++---------- docs/_templates/gcp_image.tmpl | 19 ++++++++++-------- docs/pyproject.toml | 1 + 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/docs/_ext/scylladb_common_images.py b/docs/_ext/scylladb_common_images.py index 010226074e..b71130d3c4 100644 --- a/docs/_ext/scylladb_common_images.py +++ b/docs/_ext/scylladb_common_images.py @@ -39,10 +39,12 @@ class FileDownloader: class BaseTemplateDirective(DataTemplateCSV): option_spec = DataTemplateCSV.option_spec.copy() option_spec["version"] = lambda x: x + option_spec["latest"] = lambda x: x def _make_context(self, data, config, env): context = super()._make_context(data, config, env) context["version"] = self.options.get("version") + context["latest"] = self.options.get("latest") return context def run(self): @@ -78,7 +80,7 @@ class BaseVersionsTemplateDirective(Directive): reverse=True ) - def _process_file(self, file, relative_path_from_current_rst): + def _process_file(self, file, relative_path_from_current_rst, is_latest=False): data_directive = BaseTemplateDirective( name=self.name, arguments=[os.path.join(relative_path_from_current_rst, file)], @@ -92,6 +94,7 @@ class BaseVersionsTemplateDirective(Directive): ) data_directive.options["template"] = self.TEMPLATE data_directive.options["version"] = self._extract_version_from_filename(file) + data_directive.options["latest"] = is_latest return data_directive.run() def _get_exclude_patterns(self): @@ -155,7 +158,8 @@ class BaseVersionsTemplateDirective(Directive): files = [files[0]] output = [] - for file in files: - output.extend(self._process_file(file, relative_path_from_current_rst)) + for i, file in enumerate(files): + is_latest = i == 0 + output.extend(self._process_file(file, relative_path_from_current_rst, is_latest)) return output diff --git a/docs/_templates/aws_image.tmpl b/docs/_templates/aws_image.tmpl index d3f39ce1e5..40f2bb0610 100644 --- a/docs/_templates/aws_image.tmpl +++ b/docs/_templates/aws_image.tmpl @@ -3,18 +3,21 @@ {{version}} {{ '-' * version|length }} -.. list-table:: - :header-rows: 1 +.. collapse:: View image details + {% if latest %}:open:{% endif %} + + .. list-table:: + :header-rows: 1 - * - Region - - x86 AMI ID - - Launch x86 - - ARM AMI ID - - Launch ARM -{% for row in data[1:] %} - * - {{ row[0] }} - - {{ row[2] }} - - `Node `__ {% if row|length > 4 %} / `Cluster `__{% endif %} - - {{ row[3] }} - - `Node `__ {% if row|length > 5 %} / `Cluster `__{% endif %} -{% endfor %} \ No newline at end of file + * - Region + - x86 AMI ID + - Launch x86 + - ARM AMI ID + - Launch ARM + {% for row in data[1:] %} + * - {{ row[0] }} + - {{ row[2] }} + - `Node `__ {% if row|length > 4 %} / `Cluster `__{% endif %} + - {{ row[3] }} + - `Node `__ {% if row|length > 5 %} / `Cluster `__{% endif %} + {% endfor %} \ No newline at end of file diff --git a/docs/_templates/azure_image.tmpl b/docs/_templates/azure_image.tmpl index 7d6beea787..b0c4d7e5a5 100644 --- a/docs/_templates/azure_image.tmpl +++ b/docs/_templates/azure_image.tmpl @@ -3,14 +3,17 @@ {{version}} {{ '-' * version|length }} -.. list-table:: - :header-rows: 1 +.. collapse:: View image details + {% if latest %}:open:{% endif %} - * - Gallery Image Definition - - Gallery Image Version - - Public Gallery Name -{% for row in data[1:] %} - * - {{ row[0] }} - - {{ row[1] }} - - {{ row[2] }} -{% endfor %} + .. list-table:: + :header-rows: 1 + + * - Gallery Image Definition + - Gallery Image Version + - Public Gallery Name + {% for row in data[1:] %} + * - {{ row[0] }} + - {{ row[1] }} + - {{ row[2] }} + {% endfor %} diff --git a/docs/_templates/gcp_image.tmpl b/docs/_templates/gcp_image.tmpl index 48fb0f7cb9..8f3c93fbbc 100644 --- a/docs/_templates/gcp_image.tmpl +++ b/docs/_templates/gcp_image.tmpl @@ -3,12 +3,15 @@ {{version}} {{ '-' * version|length }} -.. list-table:: - :header-rows: 1 +.. collapse:: View image details + {% if latest %}:open:{% endif %} - * - Image Name - - Image ID -{% for row in data[1:] %} - * - {{ row[0] }} - - {{ row[1] }} -{% endfor %} + .. list-table:: + :header-rows: 1 + + * - Image Name + - Image ID + {% for row in data[1:] %} + * - {{ row[0] }} + - {{ row[1] }} + {% endfor %} diff --git a/docs/pyproject.toml b/docs/pyproject.toml index d03a16f5e7..15335465ba 100644 --- a/docs/pyproject.toml +++ b/docs/pyproject.toml @@ -16,6 +16,7 @@ Sphinx = "7.2.6" sphinx-multiversion-scylla = "~0.3.1" sphinxcontrib-datatemplates = "^0.9.2" sphinx-scylladb-markdown = "^0.1.2" +sphinx_collapse ="^0.1.3" [build-system] requires = ["poetry>=0.12"]