Carl Mastrangelo | a5433dd | 2018-05-21 18:23:09 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Carl Mastrangelo | cbe33cc | 2018-05-21 13:00:13 -0700 | [diff] [blame] | 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 | |
Carl Mastrangelo | cbe33cc | 2018-05-21 13:00:13 -0700 | [diff] [blame] | 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 | |
Carl Mastrangelo | a5433dd | 2018-05-21 18:23:09 -0700 | [diff] [blame] | 31 | S=$(echo -n "$SNIPPET" | tr '\n' ' ') |
Carl Mastrangelo | cbe33cc | 2018-05-21 13:00:13 -0700 | [diff] [blame] | 32 | |
Carl Mastrangelo | a5433dd | 2018-05-21 18:23:09 -0700 | [diff] [blame] | 33 | while IFS= read -r -d '' M |
Carl Mastrangelo | cbe33cc | 2018-05-21 13:00:13 -0700 | [diff] [blame] | 34 | do |
Carl Mastrangelo | a5433dd | 2018-05-21 18:23:09 -0700 | [diff] [blame] | 35 | if grep -q "i,s,o,g,r,a,m" "$M"; then |
| 36 | : |
| 37 | else |
Carl Mastrangelo | cbe33cc | 2018-05-21 13:00:13 -0700 | [diff] [blame] | 38 | sed -i "s_</head>_${S}</head>_" "$M" |
| 39 | fi |
Carl Mastrangelo | a5433dd | 2018-05-21 18:23:09 -0700 | [diff] [blame] | 40 | done < <(find . -name \*.html -print0) |