blob: 14549b79c9ab1a79b8e9d853694b37f2a22d4153 [file] [log] [blame]
Carl Mastrangeloa5433dd2018-05-21 18:23:09 -07001#!/bin/bash
Carl Mastrangelocbe33cc2018-05-21 13:00:13 -07002# 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 Mastrangelocbe33cc2018-05-21 13:00:13 -070016# This script finds all html files in the current directory, and adds the
17# GA tracking snippet to them.
18
19read -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>
29EOF
30
Carl Mastrangeloa5433dd2018-05-21 18:23:09 -070031S=$(echo -n "$SNIPPET" | tr '\n' ' ')
Carl Mastrangelocbe33cc2018-05-21 13:00:13 -070032
Carl Mastrangeloa5433dd2018-05-21 18:23:09 -070033while IFS= read -r -d '' M
Carl Mastrangelocbe33cc2018-05-21 13:00:13 -070034do
Carl Mastrangeloa5433dd2018-05-21 18:23:09 -070035 if grep -q "i,s,o,g,r,a,m" "$M"; then
36 :
37 else
Carl Mastrangelocbe33cc2018-05-21 13:00:13 -070038 sed -i "s_</head>_${S}</head>_" "$M"
39 fi
Carl Mastrangeloa5433dd2018-05-21 18:23:09 -070040done < <(find . -name \*.html -print0)