Skip to content

Commit d07ab29

Browse files
author
AoifeHughes
committed
made variable thingy in script.
1 parent e7979d9 commit d07ab29

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

assets/scripts/add_notebook_links.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ set -e
66

77
echo "Adding notebook download links to HTML pages..."
88

9+
# Link text variable
10+
LINK_TEXT="Download notebook"
11+
912
# Find all HTML files that have corresponding .ipynb files
1013
find _site/tutorials _site/usage _site/developers -name "index.html" 2>/dev/null | while read html_file; do
1114
dir=$(dirname "$html_file")
@@ -14,11 +17,11 @@ find _site/tutorials _site/usage _site/developers -name "index.html" 2>/dev/null
1417
# Check if the corresponding .ipynb file exists
1518
if [ -f "$ipynb_file" ]; then
1619
# Check if link is already present
17-
if ! grep -q 'Download notebook' "$html_file"; then
20+
if ! grep -q "$LINK_TEXT" "$html_file"; then
1821
# Insert the notebook link AFTER the "Report an issue" link
1922
# This ensures it goes in the right place in the sidebar toc-actions
2023
# The download="index.ipynb" attribute forces browser to download instead of navigate
21-
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"
24+
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>$LINK_TEXT<\/a><\/li>/g" "$html_file"
2225
echo " ✓ Added notebook link to $html_file"
2326
fi
2427
fi

0 commit comments

Comments
 (0)