Link to Google Colab button in Notebooks #501
Closed
hollandjg
started this conversation in
Show and Tell
Replies: 1 comment
-
Closing as this is now implemented, well done! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to highlight a feature of the documentation – the "Open in Google Colab" button.
The code builds on mkdocs-jupyter:
autora/mkdocs.yml
Line 115 in e20b651
It is configured using the following lines (as of autora 3.1.0):
autora/mkdocs.yml
Lines 8 to 9 in e20b651
This block specifies where the notebook can be found.
The feature needs two "hooks" which convert strings, loaded here:
autora/mkdocs.yml
Lines 136 to 137 in e20b651
... and implemented here:
autora/mkdocs/hooks.py
Lines 5 to 12 in e20b651
The actual link and its appearance are specified here:
autora/mkdocs/overrides/main.html
Lines 9 to 12 in e20b651
This block of HTML uses the two hooks in the snippet
src_uri
of thefile
which generated thepage
basename
: get the notebook's filenamequote
: convert any special characters (like spaces) into allowable values for a URL.The button shown is specified here:
autora/mkdocs/overrides/main.html
Line 11 in e20b651
The "Download notebook" button is very similar, but doesn't need to use a special starting URL – it can use the "canonical_url":
autora/mkdocs/overrides/main.html
Lines 5 to 8 in e20b651
Note that this requires the
site_url
to be set properly:autora/mkdocs.yml
Line 5 in e20b651
(Note here: we noticed that we could have made the code for the Colab link a little simpler if we'd have left the
/autora
part off the end of thesite_url
, and we were tempted to do that. However, that misuse of thesite_url
configuration parameter could have caused more problems down the line – then thecanonical_url
would have been set wrong in the rest of the site, and any plugins which rely on it would also have broken.)Potential for development
Beta Was this translation helpful? Give feedback.
All reactions