mkpage

1 HTML page generator

This small script is used to generate a HTML page and table of contents from a Worgle literate program via Sorg. It is specifically built to utilize the CSS rules on my website.

<<top>>=

#!/bin/sh
<<setup>>
<<full_html_page>>
<<table_of_contents>>

1.1 Check for arguments

First, check and make sure a filename is given. If not, print the proper use and exit.

<<setup>>=

if [ "$#" -eq 0 ]
then
    echo "Usage: $0 file.org"
    exit 1
fi

The org extension is stripped from the filename to get the name of the file. These will be used to generate the filenames for the full HTML, as well as the table of contents.

<<setup>>=

NAME=${1%.*}
NAME_TOC="$NAME""_toc"

1.2 Full HTML page generation

<<full_html_page>>=

cat > $NAME.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>$NAME</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="main">
EOF
sorg -s $1 >> $NAME.html
cat >> $NAME.html <<EOF
</div>
</body>
</html>
EOF

1.3 Table of Contents HTML page generation

<<table_of_contents>>=

cat > $NAME_TOC.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>$NAME</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="main">
EOF
sorg -t $NAME.html -s $1 >> $NAME_TOC.html
cat >> $NAME_TOC.html <<EOF
</div>
</body>
</html>
EOF