diff --git a/.maintain/rustdocs-release.sh b/.maintain/rustdocs-release.sh index 2a1e141e63ad2..90202f2a821b2 100755 --- a/.maintain/rustdocs-release.sh +++ b/.maintain/rustdocs-release.sh @@ -91,6 +91,22 @@ build_rustdocs() { && echo "" > "${2}/index.html" } +inject_analytics_script() { + local path="$1" + local script_content="" + + # Define a function that injects our script into the head of an html file. + process_file() { + local file="$1" + echo "Adding Simple Analytics script to $file" + sed -i "s||$script_content|" "$file" + } + export -f process_file + + # Locate all .html files under the documentation root and use xargs to process in parallel. + find "$path" -name '*.html' | xargs -I {} -P "$(nproc)" bash -c 'process_file "$@"' _ {} +} + upsert_index_page() { # Check if `index-tpl-crud` exists which index-tpl-crud &> /dev/null || yarn global add @substrate/index-tpl-crud @@ -139,6 +155,7 @@ deploy_main() { git fetch --all git checkout -f ${BUILD_RUSTDOC_REF} || { echo "Checkout \`${BUILD_RUSTDOC_REF}\` error." && exit 1; } build_rustdocs "${BUILD_RUSTDOC_REF}" "${DOC_PATH}" + inject_analytics_script "${DOC_PATH}" # git checkout `gh-pages` branch git fetch "${GIT_REMOTE}" gh-pages