Skip to content

Add extra_css for custom css injection #1950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions binderhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ def _google_analytics_deprecation(self, change):
config=True,
)

extra_css = Unicode(
"",
help="""
Extra bits of CSS that should be loaded in each page.

Omit the <style> tag.
""",
config=True,
)

base_url = Unicode("/", help="The base URL of the entire application", config=True)

@validate("base_url")
Expand Down Expand Up @@ -959,6 +969,7 @@ def initialize(self, *args, **kwargs):
"about_message": self.about_message,
"banner_message": self.banner_message,
"extra_footer_scripts": self.extra_footer_scripts,
"extra_css": self.extra_css,
"jinja2_env": jinja_env,
"build_docker_config": self.build_docker_config,
"base_url": self.base_url,
Expand Down
1 change: 1 addition & 0 deletions binderhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get(self):
self.render_template(
"page.html",
page_config=self.page_config,
extra_css=self.settings["extra_css"],
extra_footer_scripts=self.settings["extra_footer_scripts"],
opengraph_title=self.opengraph_title,
)
Expand Down
5 changes: 5 additions & 0 deletions binderhub/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<link id="favicon" rel="shortcut icon" type="image/png" href="{{static_url("favicon.ico")}}" />
<link href="{{static_url("dist/styles.css")}}" rel="stylesheet"></link>

{% if extra_css %}
<style>
{{ extra_css }}
</style>
{% endif %}
<script>
window.pageConfig = {{page_config|tojson}};
</script>
Expand Down
Loading