Skip to content

Commit

Permalink
rust docs: add simple analytics (#1377)
Browse files Browse the repository at this point in the history
* inject simple analytics

* comments

* fix chown

* comments

* doc features
  • Loading branch information
liamaharon authored Sep 5, 2023
1 parent 076529e commit 7217a5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion .gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,30 @@ build-rustdoc:
script:
# FIXME: it fails with `RUSTDOCFLAGS="-Dwarnings"` and `--all-features`
# FIXME: return to stable when https://github.com/rust-lang/rust/issues/96937 gets into stable
- time cargo doc --workspace --no-deps
- time cargo doc --features try-runtime,experimental --workspace --no-deps
- rm -f ./target/doc/.lock
- mv ./target/doc ./crate-docs
# FIXME: remove me after CI image gets nonroot
- chown -R nonroot:nonroot ./crate-docs
# Inject Simple Analytics (https://www.simpleanalytics.com/) privacy preserving tracker into
# all .html files
- |
inject_simple_analytics() {
local path="$1"
local script_content="<script async defer src=\"https://apisa.parity.io/latest.js\"></script><noscript><img src=\"https://apisa.parity.io/latest.js\" alt=\"\" referrerpolicy=\"no-referrer-when-downgrade\" /></noscript>"
# Function that inject script into the head of an html file using sed.
process_file() {
local file="$1"
echo "Adding Simple Analytics script to $file"
sed -i "s|</head>|$script_content</head>|" "$file"
}
export -f process_file
# Modify .html files in parallel using xargs, otherwise it can take a long time.
find "$path" -name '*.html' | xargs -I {} -P "$(nproc)" bash -c 'process_file "$@"' _ {}
}
inject_simple_analytics "./crate-docs"
- echo "<meta http-equiv=refresh content=0;url=polkadot_service/index.html>" > ./crate-docs/index.html

build-implementers-guide:
Expand Down
3 changes: 2 additions & 1 deletion substrate/.maintain/rustdocs-release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
# set -x

# This script manages the deployment of Substrate rustdocs to https://paritytech.github.io/substrate/.
# This script used to manage the deployment of Substrate rustdocs to https://paritytech.github.io/substrate/.
# It is no longer used anywhere, and only here for historical/demonstration purposes.
# - With `deploy` sub-command, it will checkout the passed-in branch/tag ref, build the rustdocs
# locally (this takes some time), update the `index.html` index page, and push it to remote
# `gh-pages` branch. So users running this command need to have write access to the remote
Expand Down

0 comments on commit 7217a5d

Please sign in to comment.