| 1 |
#!/bin/bash |
| 2 |
# Copyright 2018 The gRPC Authors |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
# This script finds all html files in the current directory, and adds the |
| 17 |
# GA tracking snippet to them. |
| 18 |
|
| 19 |
read -r -d '' SNIPPET << EOF |
| 20 |
<script type="text/javascript"> |
| 21 |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| 22 |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
| 23 |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| 24 |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
| 25 |
|
| 26 |
ga('create', 'UA-60127042-1', 'auto'); |
| 27 |
ga('send', 'pageview'); |
| 28 |
</script> |
| 29 |
EOF |
| 30 |
|
| 31 |
S=$(echo -n "$SNIPPET" | tr '\n' ' ') |
| 32 |
|
| 33 |
while IFS= read -r -d '' M |
| 34 |
do |
| 35 |
if grep -q "i,s,o,g,r,a,m" "$M"; then |
| 36 |
: |
| 37 |
else |
| 38 |
sed -i "s_</head>_${S}</head>_" "$M" |
| 39 |
fi |
| 40 |
done < <(find . -name \*.html -print0) |