From f5ed53ea86b037adf20a62c08ce6718d1f8c2d1f Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 23 Apr 2022 14:32:26 +0100 Subject: [PATCH 1/2] Main page footer can be overridden This allows the footer on the main (index) page to be replaced with custom HTML. Related to https://github.com/jupyterhub/mybinder.org-deploy/issues/2156 --- binderhub/app.py | 11 +++++++++++ binderhub/main.py | 1 + binderhub/templates/index.html | 8 ++++++++ testing/local-binder-local-hub/binderhub_config.py | 1 + 4 files changed, 21 insertions(+) diff --git a/binderhub/app.py b/binderhub/app.py index 47198e60c..e13002bc7 100644 --- a/binderhub/app.py +++ b/binderhub/app.py @@ -145,6 +145,16 @@ def _log_level(self): config=True, ) + main_footer_message = Unicode( + "", + help=""" + Override the footer on the main page. + + The value will be inserted "as is". Raw HTML is supported. + """, + config=True, + ) + extra_footer_scripts = Dict( {}, help=""" @@ -822,6 +832,7 @@ def initialize(self, *args, **kwargs): "google_analytics_domain": self.google_analytics_domain, "about_message": self.about_message, "banner_message": self.banner_message, + "main_footer_message": self.main_footer_message, "extra_footer_scripts": self.extra_footer_scripts, "jinja2_env": jinja_env, "build_memory_limit": self.build_memory_limit, diff --git a/binderhub/main.py b/binderhub/main.py index 6d302972e..c5361f253 100644 --- a/binderhub/main.py +++ b/binderhub/main.py @@ -36,6 +36,7 @@ def get(self): submit=False, google_analytics_code=self.settings["google_analytics_code"], google_analytics_domain=self.settings["google_analytics_domain"], + main_footer_message=self.settings["main_footer_message"], extra_footer_scripts=self.settings["extra_footer_scripts"], repo_providers=self.settings["repo_providers"], ) diff --git a/binderhub/templates/index.html b/binderhub/templates/index.html index 0e9b5134c..02bffabee 100644 --- a/binderhub/templates/index.html +++ b/binderhub/templates/index.html @@ -195,7 +195,15 @@

How it works

{% endblock main %} {% block footer %} + +{% if main_footer_message %} +
+ {{ main_footer_message | safe }} +
+{% else %} {{ super () }} +{% endif %} + diff --git a/testing/local-binder-local-hub/binderhub_config.py b/testing/local-binder-local-hub/binderhub_config.py index 54d7395b7..04ef56e0f 100644 --- a/testing/local-binder-local-hub/binderhub_config.py +++ b/testing/local-binder-local-hub/binderhub_config.py @@ -29,6 +29,7 @@ c.BinderHub.banner_message = ( 'See BinderHub on GitHub' ) +c.BinderHub.main_footer_message = '

This is a custom footer message.

' c.BinderHub.hub_url_local = "http://localhost:8000" From d7577f2fe76b07e43632a2bd790f8c9e136f56de Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 24 Apr 2022 23:16:47 +0100 Subject: [PATCH 2/2] Instead of replacing the footer add a new `block about_summary` above footer If `about_summary_message` is set it is used when rendering `index.html` and `loading.html` --- binderhub/app.py | 6 +++--- binderhub/main.py | 3 ++- binderhub/templates/index.html | 8 -------- binderhub/templates/page.html | 8 ++++++++ testing/local-binder-local-hub/binderhub_config.py | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/binderhub/app.py b/binderhub/app.py index e13002bc7..3922d09c9 100644 --- a/binderhub/app.py +++ b/binderhub/app.py @@ -145,10 +145,10 @@ def _log_level(self): config=True, ) - main_footer_message = Unicode( + about_summary_message = Unicode( "", help=""" - Override the footer on the main page. + An optional summary that appears on all pages apart from the about page. The value will be inserted "as is". Raw HTML is supported. """, @@ -832,7 +832,7 @@ def initialize(self, *args, **kwargs): "google_analytics_domain": self.google_analytics_domain, "about_message": self.about_message, "banner_message": self.banner_message, - "main_footer_message": self.main_footer_message, + "about_summary_message": self.about_summary_message, "extra_footer_scripts": self.extra_footer_scripts, "jinja2_env": jinja_env, "build_memory_limit": self.build_memory_limit, diff --git a/binderhub/main.py b/binderhub/main.py index c5361f253..156d3ab46 100644 --- a/binderhub/main.py +++ b/binderhub/main.py @@ -36,7 +36,7 @@ def get(self): submit=False, google_analytics_code=self.settings["google_analytics_code"], google_analytics_domain=self.settings["google_analytics_domain"], - main_footer_message=self.settings["main_footer_message"], + about_summary_message=self.settings["about_summary_message"], extra_footer_scripts=self.settings["extra_footer_scripts"], repo_providers=self.settings["repo_providers"], ) @@ -123,6 +123,7 @@ async def get(self, provider_prefix, _unescaped_spec): submit=True, google_analytics_code=self.settings["google_analytics_code"], google_analytics_domain=self.settings["google_analytics_domain"], + about_summary_message=self.settings["about_summary_message"], extra_footer_scripts=self.settings["extra_footer_scripts"], ) diff --git a/binderhub/templates/index.html b/binderhub/templates/index.html index 02bffabee..0e9b5134c 100644 --- a/binderhub/templates/index.html +++ b/binderhub/templates/index.html @@ -195,15 +195,7 @@

How it works

{% endblock main %} {% block footer %} - -{% if main_footer_message %} -
- {{ main_footer_message | safe }} -
-{% else %} {{ super () }} -{% endif %} - diff --git a/binderhub/templates/page.html b/binderhub/templates/page.html index 222f3dcd3..21b506ae6 100644 --- a/binderhub/templates/page.html +++ b/binderhub/templates/page.html @@ -39,6 +39,14 @@ {% block main %} {% endblock main %} + {% block about_summary %} + {% if about_summary_message %} +
+ {{ about_summary_message | safe }} +
+ {% endif %} + {% endblock about_summary %} + {% block footer %}
diff --git a/testing/local-binder-local-hub/binderhub_config.py b/testing/local-binder-local-hub/binderhub_config.py index 04ef56e0f..5cc98e9d5 100644 --- a/testing/local-binder-local-hub/binderhub_config.py +++ b/testing/local-binder-local-hub/binderhub_config.py @@ -29,7 +29,7 @@ c.BinderHub.banner_message = ( 'See BinderHub on GitHub' ) -c.BinderHub.main_footer_message = '

This is a custom footer message.

' +c.BinderHub.about_summary_message = '

This is a summary of the about message.

' c.BinderHub.hub_url_local = "http://localhost:8000"