Skip to content

Commit

Permalink
Add GH button to example docs (#3214)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbvll authored Apr 4, 2024
1 parent 9826ad9 commit 38701e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
47 changes: 37 additions & 10 deletions dev/update-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,47 @@ echo "---" >> $INDEX
echo "maxdepth: 1" >> $INDEX
echo "---" >> $INDEX

rm -f "examples/doc/source/*.md"
rm -f examples/doc/source/*.md

cd examples/
for d in $(printf '%s\n' */ | sort -V); do
example=${d%/}
# For each example, copy the README into the source of the Example docs
[[ $example != doc ]] && cp $example/README.md $ROOT/examples/doc/source/$example.md 2>&1 >/dev/null
# For each example, copy all images of the _static folder into the examples
# docs static folder
[[ $example != doc ]] && [ -d "$example/_static" ] && {
cp $example/_static/**.{jpg,png,jpeg} $ROOT/examples/doc/source/_static/ 2>/dev/null || true
}
# For each example, insert the name of the example into the index file
[[ $example != doc ]] && (echo $INSERT_LINE; echo a; echo $example; echo .; echo wq) | ed $INDEX 2>&1 >/dev/null

if [[ $example != doc ]]; then

for file in $example/*.md; do
# For each example, copy the README into the source of the Example docs
if [[ $(basename "$file") = "README.md" ]]; then
cp $file $ROOT/examples/doc/source/$example.md 2>&1 >/dev/null
else
# If the example contains other markdown files, copy them to the source of the Example docs
cp $file $ROOT/examples/doc/source/$(basename "$file") 2>&1 >/dev/null
fi
done

gh_text="[<img src=\"_static/view-gh.png\" alt=\"View on GitHub\" width=\"200\"/>](https://github.com/adap/flower/blob/main/examples/$example)"
readme_file="$ROOT/examples/doc/source/$example.md"

if ! grep -Fq "$gh_text" "$readme_file"; then
awk -v text="$gh_text" '
/^# / && !found {
print $0 "\n" text;
found=1;
next;
}
{ print }
' "$readme_file" > tmpfile && mv tmpfile "$readme_file"
fi

# For each example, copy all images of the _static folder into the examples
# docs static folder
[ -d "$example/_static" ] && {
cp $example/_static/**.{jpg,png,jpeg} $ROOT/examples/doc/source/_static/ 2>/dev/null || true
}
# For each example, insert the name of the example into the index file
(echo $INSERT_LINE; echo a; echo $example; echo .; echo wq) | ed $INDEX 2>&1 >/dev/null

fi
done

echo "\`\`\`" >> $INDEX
Expand Down
1 change: 1 addition & 0 deletions examples/doc/source/_static/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
!favicon.ico
!flower-logo.png
!tmux_jtop_view.gif
!view-gh.png
Binary file added examples/doc/source/_static/view-gh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38701e3

Please sign in to comment.