summarylogtreecommitdiffstats
path: root/subldoc.sh
blob: fd25b6a16dbc95fbe644ca59c47983c1c1432a89 (plain)
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
#!/bin/sh
dom=${1:-https://www.sublimetext.com}
url=$dom/docs
mkdir -p images
curl -- "$url/" | tee ./index.html | grep -oe 'href *= *"[^"]*"' -e 'src *= *"[^"]*"' | cut -d\" -f2 | grep -ve^http -e^# -eindex.html\$ | 
while read -r i; do
	case $i in
		(/images/*) { curl -- "$url$i">."$i" || rm -- ."$i";}& ;;
		(/download|/support)true&;;
		(/*) { curl -- "$dom$i">./"${i##*/}" || rm -- ./"${i##*/}";}&  ;;
		(*) { curl -- "$url/$i">./"${i##*/}" || rm -- ./"${i##*/}";}& ;;
	esac
	printf %s\\n $! >> wait.pids
done
while read pid; do
	while kill -0 "$pid" 2>/dev/null; do
		sleep 1.5
	done
done < wait.pids
rm wait.pids
for f in *\?v=*; do
	mv -- "$f" "${f%\?v=*}"
done
rm blog download support 2>/dev/null
sed -i -e'
s|href="/"|href="index.html"|
/href="\//s|href="[^"/]*/|href="|
/src="\//s|src="[^"/]*/|src="|
/href=/s|\?v=[0-9a-f]*"|"|
s|href="https://www\.sublimemerge\.com"|href="../sublime-merge/index.html"|
s|href="blog|href="'"$dom"'/blog|
s|href="download|href="'"$dom"'/download|
s|href="support|href="'"$dom"'/support|
' ./*.html