-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc-man.sh
executable file
·95 lines (69 loc) · 2.18 KB
/
doc-man.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
#!/usr/bin/env bash
# doc.sh
#
main() {
lookupList=$@
docPath="${HOME}/Projects/Docs/man/html"
mkdir -p $docPath
cd $docPath
for anLookup in $lookupList; do
for i in `seq 0 9`; do
thisLookup=`man -w $i $anLookup`
if [[ -n $thisLookup ]]; then
anFileLookup=`echo $anLookup | tr [:upper:] [:lower:]`
mandoc -T html $thisLookup > ${docPath}/${anLookup}_$i.html
fi
done
done
cd ..
# find ./html/ -name "*.html"
pageSignatureFile="man.md5.txt"
echo > $pageSignatureFile
pageSignatures=""
for anFile in `find ./html/ -name "*.html"`; do
md5 -r $anFile >> $pageSignatureFile
pageSignatures="$pageSignatures `md5 -q $anFile`"
done
sort -o $pageSignatureFile $pageSignatureFile
if [[ `echo $pageSignatures | tr " " "\n" | wc -l` -eq `echo $pageSignatures | tr " " "\n" | sort | uniq | wc -l` ]]; then
echo "I don't see any dupes"
# pwd
washCode ${docPath}/../washed/ `find ./html -iname '*.html' `
else
echo "Oops, is there a dupe?"
sleep 2
subl $pageSignatureFile
fi
}
washCode(){
washDir=$1 && shift
fileList=$@
rm -rf $washDir
mkdir -p $washDir
echo "washing"
for someFile in $fileList; do
someFileTitle=`cat $someFile | grep "<title>" | perl -pe 's/<title>(.*?)<\/title>/$1/gi'`
titleAddString='s/(<body>)/$1<h2>'$someFileTitle'<\/h2>/gmi'
letterPage $washDir $someFileTitle
# echo $someFile
cat $someFile \
| perl -pe 's/(<\/?)h4/$1h6/gi' \
| perl -pe 's/(<\/?)h3/$1h5/gi' \
| perl -pe 's/(<\/?)h2/$1h4/gi' \
| perl -pe 's/(<\/?)h1/$1h3/gi' \
| perl -pe "$titleAddString" \
| perl -pe 's/(<a[^>]+)class="[^>"]+"/$1/gi' \
| perl -pe 's/(class="?)([^<>]+)\1([^<>]+\b)"?/$1$3 $2/gi' \
> ${washDir}/${someFile/.*\//}
done
echo "<!DOCTYPE html><html><head><title>man Pages</title></head><body><h1>man Pages</h1> <p>Various Authors</p></body><hr></html>" > $washDir/zzzzzzzzzzzzzzzzzzzzzzzz.html
}
letterPage(){
washDir=$1 && shift
inputString=$1 && shift
letterUC=`echo ${inputString:0:1} | tr [:lower:] [:upper:]`
letter=`echo ${inputString:0:1} | tr [:upper:] [:lower:]`
# echo $letter
echo "<!DOCTYPE html><html><head><title>$letterUC</title></head><body><h1>$letterUC</h1><hr></body></html>" > $washDir/$letter.html
}
main $@