-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup_html.sh
executable file
·90 lines (78 loc) · 2.4 KB
/
cleanup_html.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Dedicated to the public domain under the CC0 1.0 Universal (CC0 1.0) Public
# Domain Dedication: https://creativecommons.org/publicdomain/zero/1.0/
set -o errexit
set -o errtrace
set -o nounset
if command -v gsed >/dev/null
then
SED=gsed
elif sed --version >/dev/null
then
SED=sed
else
echo 'GNU sed is required. If on macOS install `gnu-sed` via brew.' 1>&2
exit 1
fi
function _remove_deprecated_links_meta_from_html_files {
printf "\e[1m\e[7m %-80s\e[0m\n" \
'Remove deprected links and meta from HTML files'
for _file in $(find docs -type f -name '*.html')
do
# 1. Remove link: WordPress Edit URI
# 2. Remove link: WordPress JSON API
# 3. Remove link: WordPress xmlrpc.php
# 4. Remove link: WordPress shortlink
# 5. Remove link: WordPress Windows Live Writer Manifest link
# 6. Remove meta: generator
${SED} \
-e'/^<link rel="EditURI"/d' \
-e'/^<link .*\/wp-json\//d' \
-e'/^<link .*"\/xmlrpc.php/d' \
-e"/^<link rel='shortlink'/d" \
-e'/^<link rel="wlwmanifest"/d' \
-e'/^<meta name="generator"/d' \
--in-place "${_file}"
done
echo
}
function _remove_google_analytics {
printf "\e[1m\e[7m %-80s\e[0m\n" \
'Remove Google Analytics'
for _file in $(find docs -type f -name '*.html')
do
${SED} \
--null-data \
-e's#<!-- Begin Google.*<!-- End Google Analytics -->##' \
--in-place "${_file}"
done
echo
}
function _cleanup_site_urls {
printf "\e[1m\e[7m %-80s\e[0m\n" \
'Clean-up site URLs (remove protocol and domain)'
for _file in $(find docs -type f -name '*.html')
do
${SED} \
-e's#https\?://open4us.org/#/#g' \
--in-place "${_file}"
done
echo
}
function _cleanup_plaintext_whitespace {
printf "\e[1m\e[7m %-80s\e[0m\n" 'Clean-up whitespace in plaintext files'
# plaintext files with trailing whitespace
for _file in $(find docs -type f \
\( -name '*.css' -o -name '*.html' -o -name '*.js' \))
do
${SED} -e's#[ \t]\+$##' --in-place "${_file}"
done
echo
}
# Change directory to repository root
cd "${0%/*}/.." >/dev/null
# Run clean-up functions
_remove_deprecated_links_meta_from_html_files
_remove_google_analytics
_cleanup_site_urls
_cleanup_plaintext_whitespace