diff --git a/.github/workflows/gh-deploy.yml b/.github/workflows/gh-deploy.yml index 2af48ea7..57406185 100644 --- a/.github/workflows/gh-deploy.yml +++ b/.github/workflows/gh-deploy.yml @@ -74,6 +74,12 @@ jobs: done cd .. + # Adjust index.html files + files=$(find google-colab -name "index.html") + for file in $files; do + ./scripts/adjust-index.sh $file + done + # Checkout on branch gh-pages-* depending on branch git checkout ${{ steps.branch_check.outputs.env_name }} diff --git a/scripts/adjust-index.sh b/scripts/adjust-index.sh new file mode 100644 index 00000000..b9053a42 --- /dev/null +++ b/scripts/adjust-index.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Define the file +file=$1 +if [ -z "$file" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Define the new code to be inserted +new_code=' + +' + +# Create a temporary file +temp_file=$(mktemp) + +# Delete the code exacly: +sed '/<\/google-codelab-analytics>/d' "$file" > "$temp_file" + +# Delete the attributes codelab-ga4id and codelab-gaid from google-codelab tag +sed -i 's/codelab-ga4id="[^"]*"//g' "$temp_file" +sed -i 's/codelab-gaid="[^"]*"//g' "$temp_file" + +# Insert the new code after the tag +awk -v ncode="$new_code" '// {print; print ncode; next} 1' "$temp_file" > "$file" + +# Remove the temporary file +rm "$temp_file" \ No newline at end of file