-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinksq.sh
executable file
·122 lines (91 loc) · 2.5 KB
/
linksq.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/zsh
# vim:ft=sh
# linksq.sh -- automatically add newest links and quotes to the main page
# v0.1.1 by mountaineerbr
# __ _ ___ __ _____ / /____ _(_)__ ___ ___ ____/ / ____
# / ' \/ _ \/ // / _ \/ __/ _ `/ / _ \/ -_) -_) __/ _ \/ __/
# /_/_/_/\___/\_,_/_//_/\__/\_,_/_/_//_/\__/\__/_/ /_.__/_/
#script name
SN="${0##*/}"
#home page root
ROOT="$HOME/www/mountaineerbr.github.io"
#website root
ROOTW="https://mountaineerbr.github.io"
#blog root
ROOTB="$ROOT/blog"
#website blog root
ROOTBW="$ROOTW/blog"
#links file
LINKSF="$ROOT/links.html"
#quotes file
QUOTESF="$ROOT/quotes.html"
#main file
MAINF="$ROOT/index.html"
#clear everything on the line
CLR='\033[2K'
#tidy up markup
#unwrap html lines
unwrapf()
{
tidy --quiet yes \
--show-warnings no \
--show-info no \
--wrap 0 \
--wrap-attributes no \
--fix-uri yes \
--vertical-space no \
--hide-comments yes \
--tidy-mark no \
--write-back no \
--show-body-only yes \
--preserve-entities yes \
--quote-ampersand yes \
--quote-marks yes \
--quote-nbsp yes \
-- "$@" || true
}
#start
#check for pkgs
for pkg in tidy
do
if ! command -v "$pkg" &>/dev/null
then echo "$SN: err: package missing -- $pkg" >&2 ;exit 1
fi
done
unset pkg
#exit on error
set -e
#cd into webpage $ROOT
cd "$ROOT"
#PART ONE
#add links to main page
print "$SN: add newest links to main page.." >&2
#unwrap links.html
unwrapped="$( unwrapf "$LINKSF")"
#map [tr]s
trmaps=( $(grep -n '^\s*<tr' <<<"$unwrapped" | cut -d: -f1) )
trmape=( $(grep -nF '</tr' <<<"$unwrapped" | cut -d: -f1) )
#remove older items
sed -i '/<!-- linklistX -->/,/<!-- linklistX -->/ d' "$MAINF"
#inject newest items
injection="<!-- linklistX -->
$(sed -n "${trmaps[1]},${trmape[3]} p" <<<"$unwrapped" )
<!-- linklistX -->"
sed -i '/<!-- linklist -->/ r /dev/stdin' "$MAINF" <<<"$injection"
unset unwrapped trmaps trmape injection
#PART TWO
#add quotes to main page
print "$SN: add newest quotes to main page.." >&2
#unwrap quotes.html
unwrapped="$( unwrapf "$QUOTESF")"
#map [dt]s and [dd]s
dtmap=( $(grep -n '^\s*<dt' <<<"$unwrapped" | cut -d: -f1) )
ddmap=( $(grep -nF '</dd' <<<"$unwrapped" | cut -d: -f1) )
#remove older items
sed -i '/<!-- quotelistX -->/,/<!-- quotelistX -->/ d' "$MAINF"
#inject newest items
injection="<!-- quotelistX -->
$(sed -n "${dtmap[1]},${ddmap[4]} p" <<<"$unwrapped" )
<!-- quotelistX -->"
sed -i '/<!-- quotelist -->/ r /dev/stdin' "$MAINF" <<<"$injection"
unset unwrapped dtmap ddmap injection