-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubweb.sh
executable file
·50 lines (49 loc) · 1.66 KB
/
pubweb.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
#!/bin/bash
# publish to web
gsed=gsed #GNU sed
git=git
src_parent="c19bg/plots"
#rdir="/c/Users/Stan/Documents/webc19/C19_BG"
rdir="/Users/stan/webc19/c19bg"
copy_dir="${rdir}/cur_svg"
git_push="${git} push"
git_fetch="${git} fetch"
git_pull="${git} pull"
git_stage="${git} add ."
git_stage_docs="${git} add ../docs"
git_commit="${git} commit -m"
git_cur_time="${git} log --date iso-local -n 1 ."
tday=$(date +%b%d)
#yday=$(date -d "${tday}-1day" +%b%d) #not sup on macOS
c_date=$(date "+%b%d %T")
tday="${src_parent}/${tday}"
# yday="${src_parent}/${yday}"
# if [[ -d "${tday}" ]]; then
# src_dir="${tday}"
# elif [[ -d "${yday}" ]]; then
# src_dir="${yday}"
# else
# echo "can't find suitable source dir (tried ${tday}, ${yday})" >&2
# exit 1
# fi
if [[ -d "${tday}" ]]; then
src_dir="${tday}"
else
echo "can't find suitable source dir (tried ${tday})" >&2
exit 1
fi
pub_files="${src_dir}/svg/C*.svg ${src_dir}/svg/D00*.svg ${src_dir}/svg/D*BG.svg ${src_dir}/png/C*heat*.png"
cp -a ${pub_files} "${copy_dir}"
cd "${copy_dir}" || exit 1
# macOS svglite output contains top-level height and width attribs
# which prevent auto-scaling in browsers, so we remove them
find *.svg | xargs -n 1 ${gsed} -i -re "s/(class='svglite') width='.*?pt' height='.*?pt'/\1/"
${git_stage_docs}
${git_fetch} && ${git_pull} && ${git_stage} && ${git_commit} "auto upload ${src_dir} (${c_date})"
# also update index.md with the last update time
mdate=$(${git_cur_time} | grep Date: | ${gsed} -e 's/Date: *//')
cd ..
regpre='s/(<!-- up -->).*?(<!-- date -->)/'
${gsed} -i -re "${regpre}\1${mdate}\2/" index.md
${git_stage} && ${git_commit} "auto update ${src_dir} (${c_date})"
${git_push} "$@"