]> Dogcows Code - chaz/yoink/blob - doc/man2html.sh
49f6c7244c5b227d9612da28a3997a8cef45e250
[chaz/yoink] / doc / man2html.sh
1 #!/bin/sh
2
3 #
4 # Yoink
5 # Run this script to convert the manual page to html.
6 #
7 # Requires groff.
8 # Have fun!
9 #
10
11 function showhelp()
12 {
13 echo "Create an html manual page."
14 echo "Usage: $0 [-Hfh] [-i manpage] [-o htmlfile]"
15 echo ""
16 echo " -H Hide email addresses in the manual page."
17 echo " -f Force overwrite of output file."
18 echo " -h Show this help an exit."
19 echo " -i Specify the manual page to convert."
20 echo " -o Specify output path of html file."
21 }
22
23 INFILE="doc/yoink.6"
24 OUTFILE="yoink.html"
25
26 while getopts ":Hfhi:o:" opt
27 do
28 case $opt in
29 H)
30 HIDE_EMAIL=yes
31 ;;
32 f)
33 FORCE=yes
34 ;;
35 h)
36 showhelp
37 exit 0
38 ;;
39 i)
40 INFILE="$OPTARG"
41 ;;
42 o)
43 OUTFILE="$OPTARG"
44 ;;
45 \?)
46 echo "Invalid option: -$OPTARG" >&2
47 showhelp
48 exit 1
49 ;;
50 esac
51 done
52
53 if test x$FORCE != xyes && test -e "$OUTFILE"
54 then
55 echo "Refusing to overwrite file: $OUTFILE. Use -f to override." >&2
56 exit 1
57 fi
58
59 if test ! -f "$INFILE"
60 then
61 echo "Can't open file: $INFILE" >&2
62 exit 1
63 fi
64
65 DATE=$(date +"%d %b %Y")
66
67 # 1. Remove first two lines (comments about groff).
68 # 2. Edit page title.
69 # 3. Insert a footer before </body>.
70 HTML=$(groff -t -e -mandoc -Thtml "$INFILE" | sed -e "1,2d" \
71 -e "s|<title>.*</title>|<title>Yoink Manual</title>|" -e "s|</body>|\
72 <p style=\"font-size: 9px; text-align: center;\">\\
73 This manual page was generated on $DATE.\\
74 For more information, go to the\\
75 <a href=\"http://www.dogcows.com/yoink/\">Yoink website</a>.\\
76 </p>\\
77 </body>|")
78
79 if test x$HIDE_EMAIL = xyes
80 then
81 # 4. Replace email addresses with a placeholder.
82 echo "$HTML" \
83 | sed -e "s|&lt;.*@.*&gt;|\&lt;email address not shown\&gt;|g" \
84 >"$OUTFILE"
85 else
86 echo "$HTML" >"$OUTFILE"
87 fi
88
This page took 0.031498 seconds and 3 git commands to generate.