You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2020/12/09 13:24:27 UTC

[airflow-site] branch master updated: Add theme options to theme.conf (#339)

This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b38a18  Add theme options to theme.conf (#339)
7b38a18 is described below

commit 7b38a18ce49db8ff183471a37a9e797c6e792500
Author: Ash Berlin-Taylor <as...@firemirror.com>
AuthorDate: Wed Dec 9 13:24:18 2020 +0000

    Add theme options to theme.conf (#339)
    
    Rather than using custom config properties, and then putting them in to
    the theme context, this uses Sphinx's built in mechanism that
    automatically exposes every option in `theme.conf` with a `theme_`
    prefix.
---
 sphinx_airflow_theme/README.md                     | 24 ++++++++++++++--------
 .../sphinx_airflow_theme/__init__.py               | 24 ++++------------------
 .../sphinx_airflow_theme/header.html               |  6 +++---
 .../sphinx_airflow_theme/theme.conf                |  3 +++
 4 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/sphinx_airflow_theme/README.md b/sphinx_airflow_theme/README.md
index 1380d89..c8ac182 100644
--- a/sphinx_airflow_theme/README.md
+++ b/sphinx_airflow_theme/README.md
@@ -57,25 +57,31 @@ the CI builds your PR.
 
 # Configuration
 
-A theme that supports the following configuration options:
+A theme that supports the following configuration options under the `html_theme_options` dict in your projects `conf.py`:
 
-## `sphinx_airflow_theme_navbar_links`
+## `navbar_links`
 
 The list of links that should be available in the navigation bar at the top of the pages. The order of items will not be changed.
 
 **Example values:**
+```python
+html_theme_options = {
+    'navbar_links': [
+        {'href': '/docs/', 'text': 'Documentation'}
+    ]
 ```
-[
-    {'href': '/docs/', 'text': 'Documentation'}
-]
-```
 
-## `sphinx_airflow_theme_hide_website_buttons`
+(This is the default)
+
+## `hide_website_buttons`
+
 If ``True``, all links on the same domain but not pointing to this theme's page (e.g. `/community/`) will be hidden.
 
 **Example values:**
-```
-False
+```python
+html_theme_options = {
+  'hide_website_buttons': False,
+}
 ```
 
 # Theme's source files
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
index 11cb41b..5630a7e 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
@@ -28,29 +28,13 @@ def get_html_theme_path():
     return cur_dir
 
 
-def setup_my_func(app, pagename, templatename, context, doctree):
-    context["navbar_links"] = app.config.sphinx_airflow_theme_navbar_links
-    context["hide_website_buttons"] = (
-        app.config.sphinx_airflow_theme_hide_website_buttons
-    )
+def setup_my_func(app, config):
+    # We can't set this in the theme.conf, cos we want it to be a non-string type
+    config.html_theme_options.setdefault('navbar_links', [{'href': '/index.html', 'text': 'Documentation'}])
 
 
 # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
 def setup(app: Sphinx):
-    app.add_config_value(
-        'sphinx_airflow_theme_navbar_links',
-        default=[
-            {'href': '/docs/', 'text': 'Documentation'}
-        ],
-        rebuild='html'
-    )
-    app.add_config_value(
-        'sphinx_airflow_theme_hide_website_buttons',
-        default=False,
-        rebuild='html',
-        types=[bool]
-    )
-
     app.add_html_theme('sphinx_airflow_theme', path.abspath(path.dirname(__file__)))
     app.add_stylesheet('_gen/css/main-custom.min.css')
-    app.connect("html-page-context", setup_my_func)
+    app.connect("config-inited", setup_my_func)
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/header.html b/sphinx_airflow_theme/sphinx_airflow_theme/header.html
index cd533ab..ad89d7b 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/header.html
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/header.html
@@ -55,14 +55,14 @@
             <div class="navbar__menu-content" id="main_navbar">
 
                 <div class="navbar__links-container">
-                    {% for link in navbar_links %}
+                    {% for link in theme_navbar_links %}
                         <a class="navbar__text-link" href="{{ link.href }}">
                             {{ link.text }}
                         </a>
                     {% endfor %}
                 </div>
 
-                {% if not hide_website_buttons %}
+                {% if not theme_hide_website_buttons %}
                 <a href="/docs/stable/start.html">
                     <button class="btn-filled bodytext__medium--white">Install</button>
                 </a>
@@ -117,7 +117,7 @@
                         {% endfor %}
 
                     </div>
-                    {% if not hide_website_buttons %}
+                    {% if not theme_hide_website_buttons %}
                     <a href="/install/">
 
                         <button id="" class="btn-filled bodytext__medium--white ">Install</button>
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/theme.conf b/sphinx_airflow_theme/sphinx_airflow_theme/theme.conf
index 577040e..d0009f6 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/theme.conf
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/theme.conf
@@ -6,3 +6,6 @@ pygments_style = default
 [options]
 canonical_url =
 analytics_id =
+# Default set by python code, need to list this here to avoid warning from Sphinx
+navbar_links =
+hide_website_buttons = false