-
Notifications
You must be signed in to change notification settings - Fork 105
Add notebooks to docs download #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
…into add_notebook_dl
…into add_notebook_dl
Preview the changes: https://turinglang.org/docs/pr-previews/652 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds notebook generation and download functionality to the documentation site by creating Jupyter notebooks from Quarto .qmd files and providing download links in the rendered HTML pages.
- Introduces a Python script to convert .qmd files to .ipynb format with proper cell structure
- Adds shell scripts to generate notebooks and inject download links into HTML pages
- Integrates notebook generation into both publish and preview GitHub workflows
Reviewed Changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
assets/scripts/qmd_to_ipynb.py | Python converter that parses .qmd files and creates Jupyter notebooks with appropriate cell types |
assets/scripts/generate_notebooks.sh | Shell script that finds .qmd files and converts them to notebooks in the _site directory |
assets/scripts/add_notebook_links.sh | Shell script that adds download links to HTML pages using Perl regex replacement |
.github/workflows/publish.yml | Adds notebook generation and link injection steps to the publish workflow |
.github/workflows/preview.yml | Adds notebook generation and link injection steps to the preview workflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
"display_name": "Julia 1.11", | ||
"language": "julia", | ||
"name": self.kernel_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded display name 'Julia 1.11' doesn't match the dynamic kernel name when using Python. Consider making the display name dynamic based on the kernel.
Copilot uses AI. Check for mistakes.
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.11.0" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The language_info is hardcoded for Julia even when the kernel is Python. This should be conditional based on the detected engine/kernel type.
Copilot uses AI. Check for mistakes.
# Insert the notebook link AFTER the "Report an issue" link | ||
# This ensures it goes in the right place in the sidebar toc-actions | ||
# The download="index.ipynb" attribute forces browser to download instead of navigate | ||
perl -i -pe 's/(<a href="[^"]*issues\/new"[^>]*><i class="bi[^"]*"><\/i>Report an issue<\/a><\/li>)/$1<li><a href="index.ipynb" class="toc-action" download="index.ipynb"><i class="bi bi-journal-code"><\/i>Download notebook<\/a><\/li>/g' "$html_file" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This complex regex replacement is brittle and hard to maintain. Consider using a more robust HTML parsing approach or breaking this into multiple steps for better readability.
perl -i -pe 's/(<a href="[^"]*issues\/new"[^>]*><i class="bi[^"]*"><\/i>Report an issue<\/a><\/li>)/$1<li><a href="index.ipynb" class="toc-action" download="index.ipynb"><i class="bi bi-journal-code"><\/i>Download notebook<\/a><\/li>/g' "$html_file" | |
python3 - <<EOF | |
import sys | |
from bs4 import BeautifulSoup | |
html_file = "$html_file" | |
with open(html_file, "r", encoding="utf-8") as f: | |
soup = BeautifulSoup(f, "html.parser") | |
# Find the "Report an issue" link | |
report_link = None | |
for a in soup.find_all("a"): | |
if a.get_text(strip=True) == "Report an issue": | |
report_link = a | |
break | |
if report_link is not None: | |
# Insert the new link after the parent <li> of the report_link | |
parent_li = report_link.find_parent("li") | |
if parent_li is not None and parent_li.parent is not None: | |
new_li = soup.new_tag("li") | |
new_a = soup.new_tag("a", href="index.ipynb", **{"class": "toc-action", "download": "index.ipynb"}) | |
new_i = soup.new_tag("i", **{"class": "bi bi-journal-code"}) | |
new_a.append(new_i) | |
new_a.append("Download notebook") | |
new_li.append(new_a) | |
parent_li.insert_after(new_li) | |
with open(html_file, "w", encoding="utf-8") as f: | |
f.write(str(soup)) | |
EOF |
Copilot uses AI. Check for mistakes.
echo "Generating Jupyter notebooks from .qmd files..." | ||
|
||
# Find all .qmd files in tutorials, usage, and developers directories | ||
find tutorials usage developers -name "index.qmd" | while read qmd_file; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'while read' with 'find' can fail with filenames containing spaces or special characters. Use 'find ... -print0 | while IFS= read -r -d "" qmd_file; do' for safer file handling.
find tutorials usage developers -name "index.qmd" | while read qmd_file; do | |
find tutorials usage developers -name "index.qmd" -print0 | while IFS= read -r -d '' qmd_file; do |
Copilot uses AI. Check for mistakes.
![]() This PR adds a download button to get jupyter notebooks from the docs. Some notes:
@shravanngoswamii if you'd have some time to check these out, I'd appreciate it. |
I should also mention, I had a few issues with the CI versions of bash/posix vs deploying on my mac, so some of the scripting is done to appease github actions moreso than how users may run locally. |
I think this partially satisfies some of the points from #641 ~ it might be worth adding some note about these being available in the docs / have a quick way to export into online systems, as discussed in that issue. |
This was to try and fix #642 as I was afraid of a caching issue, please see that PR for previous discussions