Skip to content

Instantly share code, notes, and snippets.

@wseaton
Last active March 16, 2021 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wseaton/653f8d87b1c3d7bdf12cec4a82946df4 to your computer and use it in GitHub Desktop.
Save wseaton/653f8d87b1c3d7bdf12cec4a82946df4 to your computer and use it in GitHub Desktop.
add nbviewer button to jupyterhub
diff --git a/notebook/templates/page.html b/notebook/templates/page.html
index 9e68da1b2..a5539711b 100644
--- a/notebook/templates/page.html
+++ b/notebook/templates/page.html
@@ -133,7 +133,13 @@ dir="ltr">
{% endblock %}
{% block header_buttons %}
-
+
+ {% block nbviewer_button %}
+ <span id="nbviewer_widget">
+ <button onclick="createLink()" id="logout" class="btn btn-sm navbar-btn">Nbviewer</button>
+ </span>
+ {% endblock %}
+
{% block login_widget %}
<span id="login_widget">
@@ -189,6 +195,13 @@ dir="ltr">
}
}
}
+ function createLink() {
+ var p1 = /\/notebooks/
+ var p2 = /\/user\/|tree/g
+ var pathname = window.location.pathname.replace(p1, '').replace(p2, '')
+ url = 'https://your.host.here.com:8000/services/nbviewer/localfile/' + pathname
+ window.open(url, '_blank');
+ }
_remove_token_from_url();
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment