From 373b8acf2517b901e05b3767bc114fb8b153bafc Mon Sep 17 00:00:00 2001 From: Chris Ostrouchov Date: Thu, 10 Dec 2020 19:45:38 -0500 Subject: [PATCH] Adding logo configuration along with simpler testing --- README.md | 43 ++++++++++++------ .../css/panton.black-caps.otf | Bin .../css/panton.light-caps.otf | Bin {extra-assets => custom}/css/style.css | 0 .../images/jupyter_qhub_logo.svg | 0 .../images/jupyter_qhub_logo_small.png | Bin templates/page.html | 8 ++-- test.sh | 9 ---- test_jupyterhub_config.py | 19 +++++--- 9 files changed, 44 insertions(+), 35 deletions(-) rename {extra-assets => custom}/css/panton.black-caps.otf (100%) rename {extra-assets => custom}/css/panton.light-caps.otf (100%) rename {extra-assets => custom}/css/style.css (100%) rename {extra-assets => custom}/images/jupyter_qhub_logo.svg (100%) rename {extra-assets => custom}/images/jupyter_qhub_logo_small.png (100%) delete mode 100755 test.sh diff --git a/README.md b/README.md index 4c22e24..7b6f2c6 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,37 @@ -# Custom JupyterHub Templates for QHub +# Custom JupyterHub Template for QHub -This repo contains html jinja2 templates for customising the appearance of JupyterHub. Each HTML file here will override the files in `https://github.com/jupyterhub/jupyterhub/tree/master/share/jupyter/hub/templates`. +This repo contains html jinja2 templates for customising the +appearance of JupyterHub. Each HTML file here will override the files +in https://github.com/jupyterhub/jupyterhub/tree/master/share/jupyter/hub/templates. ## Usage -To use this repo ensure it is checked out and available somewhere that JupyterHub can find it. In thie example we will assume we have cloned it somewhere and created the following symlinks +To use this repo ensure it is checked out and available somewhere that +JupyterHub can find it. Add to the jupyterhub configuration to pickups +the new jinja2 templates directory and static files. -`/path/to/repo/templates` -> `/usr/local/share/jupyter/hub/custom_templates` -`/path/to/repo/assets` -> `/usr/local/share/jupyter/hub/static/custom` +```python +import tornado.web -Add the following to your JupyterHub config +c.JupyterHub.extra_handlers = [ + (r'/custom/(.*)', tornado.web.StaticFileHandler, {"path": "custom"}), +] -```python -c.JupyterHub.logo_file = '/usr/local/share/jupyter/hub/static/custom/images/logo.png' -c.JupyterHub.template_paths = ['/usr/local/share/jupyter/hub/custom_templates/', - '/usr/local/share/jupyter/hub/templates/'] +c.JupyterHub.template_paths = [ + './templates', +] ``` +Finally customize the templates via the `template_vars`. Current +options are: + - `hub_title` + - `hub_subtitle` + - `welcome` + - `logo` + +Inspiration is in the test jupyterhub configuration +`test_jupyterhub_config.py`. + ## Testing Install the development environment @@ -25,11 +40,9 @@ Install the development environment conda env install -f environment.yaml ``` -Anytime you make changes to `extra-assets` you will need to restart -jupyterhub but any changes to `templates` will not require a restart. - -Run jupyterhub via the test script +You do not need to restart jupyterhub to see changes in `custom` and +`templates`. Run jupyterhub via the test script ```shell -./test.sh +jupyterhub --config test_jupyterhub_config.py ``` diff --git a/extra-assets/css/panton.black-caps.otf b/custom/css/panton.black-caps.otf similarity index 100% rename from extra-assets/css/panton.black-caps.otf rename to custom/css/panton.black-caps.otf diff --git a/extra-assets/css/panton.light-caps.otf b/custom/css/panton.light-caps.otf similarity index 100% rename from extra-assets/css/panton.light-caps.otf rename to custom/css/panton.light-caps.otf diff --git a/extra-assets/css/style.css b/custom/css/style.css similarity index 100% rename from extra-assets/css/style.css rename to custom/css/style.css diff --git a/extra-assets/images/jupyter_qhub_logo.svg b/custom/images/jupyter_qhub_logo.svg similarity index 100% rename from extra-assets/images/jupyter_qhub_logo.svg rename to custom/images/jupyter_qhub_logo.svg diff --git a/extra-assets/images/jupyter_qhub_logo_small.png b/custom/images/jupyter_qhub_logo_small.png similarity index 100% rename from extra-assets/images/jupyter_qhub_logo_small.png rename to custom/images/jupyter_qhub_logo_small.png diff --git a/templates/page.html b/templates/page.html index 7921a29..de13cf9 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,6 +1,6 @@ {% extends "templates/page.html" %} {% block stylesheet %} - - {% endblock %} {# requires jupyerhub > 0.9.4 https://github.com/jupyterhub/jupyterhub/pull/2296 #} {% block logo %} + + {% endblock %} {# requires jupyerhub > 0.9.4 https://github.com/jupyterhub/jupyterhub/pull/2296 #} {% block logo %} {% endblock %} \ No newline at end of file + + {% endblock %} diff --git a/test.sh b/test.sh deleted file mode 100755 index 4511279..0000000 --- a/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -mkdir -p share -cp -r $(python -c "import jupyterhub.app; print(jupyterhub.app.DATA_FILES_PATH)") share -chmod -R 755 share -# we have to copy assets since jupyterhub does not have an easy way to add static paths... -cp -r extra-assets/css extra-assets/images share/jupyterhub/static/custom - -jupyterhub --config test_jupyterhub_config.py diff --git a/test_jupyterhub_config.py b/test_jupyterhub_config.py index d3a6c38..0e7a234 100644 --- a/test_jupyterhub_config.py +++ b/test_jupyterhub_config.py @@ -1,15 +1,19 @@ -c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator' +from jupyterhub.auth import DummyAuthenticator +from jupyterhub.spawner import SimpleLocalProcessSpawner + +import tornado.web + +c.JupyterHub.authenticator_class = DummyAuthenticator c.DummyAuthenticator.password = 'test' +c.JupyterHub.spawner_class = SimpleLocalProcessSpawner -# since we accept any username for launching we cannot use the default pam spawner -c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner' +# Link static files along with templates +c.JupyterHub.extra_handlers = [ + (r'/custom/(.*)', tornado.web.StaticFileHandler, {"path": "custom"}), +] -c.JupyterHub.logo_file = 'share/jupyterhub/static/custom/images/jupyter_qhub_logo_small.png' -# we have to manually set the data file path to include custom assets... -c.JupyterHub.data_files_path = './share/jupyterhub' c.JupyterHub.template_paths = [ './templates', - './share/jupyterhub/templates/' ] # QHUB will control these as ways to customize the template @@ -17,4 +21,5 @@ 'hub_title': 'This is QHub', 'hub_subtitle': 'your scalable open source data science laboratory.', 'welcome': 'have fun.', + 'logo': '/hub/custom/images/jupyter_qhub_logo.svg', }