Skip to content

Commit 848dc87

Browse files
author
Aoife
committed
grep...
1 parent f55de5c commit 848dc87

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

assets/scripts/add_notebook_links.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ find _site/tutorials _site/usage _site/developers -name "index.html" 2>/dev/null
1414
# Check if the corresponding .ipynb file exists
1515
if [ -f "$ipynb_file" ]; then
1616
# Check if link is already present
17-
if ! grep -q 'format-links.*ipynb' "$html_file"; then
18-
# Add download link near the top of the content
19-
# This uses sed to insert a link after the main article/content div opens
20-
sed -i '' '/<main class="content"/a\
21-
<div class="quarto-alternate-formats"><h2>Other Formats</h2><ul><li><a href="index.ipynb"><i class="bi bi-journal-code"></i>Jupyter</a></li></ul></div>
22-
' "$html_file"
17+
if ! grep -q 'quarto-alternate-formats' "$html_file"; then
18+
# Use perl for portable in-place editing (works on both Linux and macOS)
19+
perl -i -pe 'BEGIN{undef $/;} s/(<main class="content"[^>]*>)/$1\n<div class="quarto-alternate-formats"><h2>Other Formats<\/h2><ul><li><a href="index.ipynb"><i class="bi bi-journal-code"><\/i>Jupyter<\/a><\/li><\/ul><\/div>\n/sm' "$html_file"
2320
echo " ✓ Added notebook link to $html_file"
2421
fi
2522
fi

0 commit comments

Comments
 (0)