From cbe33ccced13af6c0c3b1e74f32b7a45f925e85d Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 21 May 2018 13:00:13 -0700 Subject: [PATCH 1/4] Add GA tracking modifier --- tools/doc/addga.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 tools/doc/addga.sh diff --git a/tools/doc/addga.sh b/tools/doc/addga.sh new file mode 100755 index 00000000000..0ff55f3fb73 --- /dev/null +++ b/tools/doc/addga.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Copyright 2018 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -exu -o pipefail + +# This script finds all html files in the current directory, and adds the +# GA tracking snippet to them. + +read -r -d '' SNIPPET << EOF + +EOF + +S="$(echo -n $SNIPPET | tr '\n' ' ')" + +for M in $(find -name \*.html); +do + grep -q "i,s,o,g,r,a,m" "$M" + if [[ $? -ne 0 ]]; then + sed -i "s__${S}_" "$M" + fi +done; From 7de5cdb3416a9a870485feca8412437c6aa1de1d Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 21 May 2018 13:19:05 -0700 Subject: [PATCH 2/4] make ga adder less stingy --- tools/doc/addga.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/doc/addga.sh b/tools/doc/addga.sh index 0ff55f3fb73..ecff7196048 100755 --- a/tools/doc/addga.sh +++ b/tools/doc/addga.sh @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -exu -o pipefail - # This script finds all html files in the current directory, and adds the # GA tracking snippet to them. From a613f2f53763f469335209c16e54551f7a20d92f Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 21 May 2018 16:59:35 -0700 Subject: [PATCH 3/4] Move script --- tools/{doc/addga.sh => api_reference/add_google_analytics.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/{doc/addga.sh => api_reference/add_google_analytics.sh} (100%) diff --git a/tools/doc/addga.sh b/tools/api_reference/add_google_analytics.sh similarity index 100% rename from tools/doc/addga.sh rename to tools/api_reference/add_google_analytics.sh From a5433ddcfbc533debf34085181a840dd7d15f89b Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 21 May 2018 18:23:09 -0700 Subject: [PATCH 4/4] shellcheck --- tools/api_reference/add_google_analytics.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/api_reference/add_google_analytics.sh b/tools/api_reference/add_google_analytics.sh index ecff7196048..14549b79c9a 100755 --- a/tools/api_reference/add_google_analytics.sh +++ b/tools/api_reference/add_google_analytics.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright 2018 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,12 +28,13 @@ read -r -d '' SNIPPET << EOF EOF -S="$(echo -n $SNIPPET | tr '\n' ' ')" +S=$(echo -n "$SNIPPET" | tr '\n' ' ') -for M in $(find -name \*.html); +while IFS= read -r -d '' M do - grep -q "i,s,o,g,r,a,m" "$M" - if [[ $? -ne 0 ]]; then + if grep -q "i,s,o,g,r,a,m" "$M"; then + : + else sed -i "s__${S}_" "$M" fi -done; +done < <(find . -name \*.html -print0)