docs: add Open in Colab badges to tutorial notebooks#391
Conversation
Greptile SummaryThis PR adds "Open in Colab" badges to all 6 tutorial notebooks under
|
| Filename | Overview |
|---|---|
| docs/scripts/generate_colab_notebooks.py | Added COLAB_BADGE_TEMPLATE constant and prepends a badge markdown cell as the first cell in process_notebook(). Logic is correct: source_path.stem correctly derives the output .ipynb filename, matching the output_path construction on line 126. |
| docs/colab_notebooks/1-the-basics.ipynb | Badge cell prepended as first cell with a correct Colab URL. All existing cell IDs were regenerated — expected behavior from the nbformat cell creation path in the script. |
| docs/colab_notebooks/2-structured-outputs-and-jinja-expressions.ipynb | Badge cell correctly added with matching filename in the Colab URL. Cell IDs regenerated as expected. |
| docs/colab_notebooks/3-seeding-with-a-dataset.ipynb | Badge cell correctly added with matching filename in the Colab URL. Cell IDs regenerated as expected. |
| docs/colab_notebooks/4-providing-images-as-context.ipynb | Badge cell correctly added with matching filename in the Colab URL. Cell IDs regenerated as expected. |
| docs/colab_notebooks/5-generating-images.ipynb | Badge cell correctly added with matching filename in the Colab URL. Cell IDs regenerated as expected. |
| docs/colab_notebooks/6-editing-images-with-image-context.ipynb | Badge cell correctly added with matching filename in the Colab URL. Cell IDs regenerated as expected. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[docs/notebook_source/*.py] --> B[jupytext.read]
B --> C[process_notebook]
C --> D{build badge cell}
D -->|COLAB_BADGE_TEMPLATE.format\nsource_path.stem + .ipynb| E[new_markdown_cell badge]
C --> F[find_import_section_index]
F --> G[create_colab_setup_cells]
G --> H[inject setup cells before imports]
E --> I[prepend badge as cell 0]
H --> I
I --> J[jupytext.write]
J --> K[docs/colab_notebooks/*.ipynb]
Last reviewed commit: 56d3c44
|
Hey @mvansegbroeck, cool idea with the Colab badges! One thing though - the notebooks in Also, we actually already have Colab badges on the docs site - see If you still want the badge inside the notebooks themselves (e.g. for people browsing them directly on GitHub), the right place to add it would be in |
|
Hey @mvansegbroeck, I went ahead and pushed a commit that moves the badge injection into
I also updated the PR title to The badge URLs and markup are identical to what you had - just generated automatically now so they survive future regenerations. |
|
Thanks @andreatgretel @johnnygreco any concerns here? Having the Colab banners on the notebooks would be nice for users who find them through GitHub. |
|
No concerns here! |
Move the "Open in Colab" badge injection into the notebook generation script so badges survive regeneration. The badge is prepended as the first markdown cell in process_notebook.
f547a17 to
fc1018f
Compare
Summary
Adds an "Open in Colab" badge as the first cell in all 6 tutorial notebooks under
docs/colab_notebooks/.Instead of editing the generated
.ipynbfiles directly (which would be overwritten on the next regeneration), the badge injection is done indocs/scripts/generate_colab_notebooks.py- the script that generates these notebooks from the source files indocs/notebook_source/. This ensures the badges persist across regenerations.Changes
COLAB_BADGE_TEMPLATEconstant togenerate_colab_notebooks.pyprocess_notebook()Notes
docs/overrides/main.html(injected on pages withpage.nb_url). This PR adds badges inside the notebooks themselves, which is useful for people browsing them directly on GitHub.