mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Add ga-beacon analytics to gendocs scripts
hack/run-gendocs.sh puts ga-beacon analytics link into all md files, hack/verify-gendocs.sh verifies presence of link.
This commit is contained in:
@@ -136,14 +136,21 @@ kube::util::gen-doc() {
|
||||
# create the list of generated files
|
||||
ls "${tmpdir}" | LC_ALL=C sort > "${tmpdir}/.files_generated"
|
||||
|
||||
# remove all old generated file from the destination
|
||||
while read file; do
|
||||
# Add analytics link to generated .md files
|
||||
if [[ "${file}" == *.md ]]; then
|
||||
local link path
|
||||
path=$(basename "$dest")/${file}
|
||||
link=$(kube::util::analytics-link "${path}")
|
||||
echo -e "\n${link}" >> "${tmpdir}/${file}"
|
||||
fi
|
||||
# remove all old generated files from the destination
|
||||
if [[ -e "${tmpdir}/${file}" && -n "${skipprefix}" ]]; then
|
||||
local original generated
|
||||
original=$(grep -v "^${skipprefix}" "${dest}/${file}") || :
|
||||
generated=$(grep -v "^${skipprefix}" "${tmpdir}/${file}") || :
|
||||
if [[ "${original}" == "${generated}" ]]; then
|
||||
# overwrite generated with original.
|
||||
# actual contents same, overwrite generated with original.
|
||||
mv "${dest}/${file}" "${tmpdir}/${file}"
|
||||
fi
|
||||
else
|
||||
@@ -157,4 +164,44 @@ kube::util::gen-doc() {
|
||||
rm -rf "${tmpdir}"
|
||||
}
|
||||
|
||||
# Takes a path $1 to traverse for md files to append the ga-beacon tracking
|
||||
# link to, if needed. If $2 is set, just print files that are missing
|
||||
# the link.
|
||||
kube::util::gen-analytics() {
|
||||
local path="$1"
|
||||
local dryrun="${2:-}"
|
||||
local mdfiles dir link
|
||||
# find has some strange inconsistencies between darwin/linux. The
|
||||
# path to search must end in '/' for linux, but darwin will put an extra
|
||||
# slash in results if there is a trailing '/'.
|
||||
if [[ $( uname ) == 'Linux' ]]; then
|
||||
dir="${path}/"
|
||||
else
|
||||
dir="${path}"
|
||||
fi
|
||||
# We don't touch files in Godeps|third_party, and the kubectl
|
||||
# docs are autogenerated by gendocs.
|
||||
mdfiles=($( find "${dir}" -name "*.md" -type f \
|
||||
-not -path "${path}/Godeps/*" \
|
||||
-not -path "${path}/third_party/*" \
|
||||
-not -path "${path}/_output/*" \
|
||||
-not -path "${path}/docs/kubectl*" ))
|
||||
for f in "${mdfiles[@]}"; do
|
||||
link=$(kube::util::analytics-link "${f#${path}/}")
|
||||
if grep -q -F -x "${link}" "${f}"; then
|
||||
continue
|
||||
elif [[ -z "${dryrun}" ]]; then
|
||||
echo -e "\n\n${link}" >> "${f}"
|
||||
else
|
||||
echo "$f"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Prints analytics link to append to a file at path $1.
|
||||
kube::util::analytics-link() {
|
||||
local path="$1"
|
||||
echo "[]()"
|
||||
}
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
||||
|
Reference in New Issue
Block a user