Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Adding logo configuration along with simpler testing
Browse files Browse the repository at this point in the history
  • Loading branch information
costrouc committed Dec 11, 2020
1 parent 9be0dde commit 373b8ac
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 35 deletions.
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions templates/page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "templates/page.html" %} {% block stylesheet %}
<link rel="stylesheet" href="{{ static_url(" custom/css/style.css ") }}" type="text/css" />
<link rel="stylesheet" href="{{ static_url(" css/style.min.css ") }}" type="text/css" /> {% endblock %} {# requires jupyerhub > 0.9.4 https://github.com/jupyterhub/jupyterhub/pull/2296 #} {% block logo %}
<link rel="stylesheet" href="/hub/custom/css/style.css" type="text/css" />
<link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css" /> {% endblock %} {# requires jupyerhub > 0.9.4 https://github.com/jupyterhub/jupyterhub/pull/2296 #} {% block logo %}
<span id="jupyterhub-logo" class="pull-left">
<a href="{{logo_url or base_url}}"><img src="{{static_url("custom/images/jupyter_qhub_logo.svg") }}" alt='JupyterHub' class='jpy-logo' title='Home'/></a>
</span> {% endblock %}
<a href="{{logo_url or base_url}}"><img src="{{ logo }}" alt='JupyterHub' class='jpy-logo' title='Home'/></a>
</span> {% endblock %}
9 changes: 0 additions & 9 deletions test.sh

This file was deleted.

19 changes: 12 additions & 7 deletions test_jupyterhub_config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
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
c.JupyterHub.template_vars = {
'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',
}

0 comments on commit 373b8ac

Please sign in to comment.