keithpeter
August 29th, 2011, 02:44 PM
Hello All
I write my Web pages using markdown format. I use three bash scripts to publish the Web pages to a hosted Web server. These scripts are horrible hacks I've cobbled together out of bits found on Web pages. Typically, I find a single command in Bash that does what I want then wrap that in some echo line or backticks.
Any improvements you can suggest to the scripts, or better commands to use, would be appreciated. Or suggestions for functions to read up on.
makepage.sh is called from within the 'pages' directory, runs the markdown script and adds a header and footer, saving the result as an html file
makeindex.sh builds an index of all the html files in the 'pages' directory and writes an index.html file. This command is run from the directory above the pages directory and index.html ends up in the 'top' of the Web server public_html directory
publish.sh calls lftp and mirrors the pages directory to the remote server, and then separately copies up the index and style sheet as that's all I want in the top level.
makepage.sh
#!/bin/bash
TEXTFILE=${1}
TITLE=`head -1 $TEXTFILE`
echo "<!DOCTYPE gunge cut to save space">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />
<title>
$TITLE
</title>
<link rel=\"stylesheet\" href=\"../style.css\" type=\"text/css\" media=\"screen\" />
</head>
<body>
<p>[ <a href=\"../index.html\">home</a> ]</p> " | tee $TEXTFILE.html
markdown $TEXTFILE | tee --append $TEXTFILE.html
DATETEXT=$(date '+%a %b %d %Y')
echo "<hr /><p><small>Keith Burnett, Last update: $DATETEXT</small></p>
</body>
</html>" | tee --append $TEXTFILE.html
chmod 777 $TEXTFILE.html
exit 0
makeindex.sh
The html title of the page is always on line 6 of the converted html file when converted using makepage.sh. The ls -lt command produces a list of files with the most recently modified listed first.
#!/bin/sh
echo "<h2>Recently modified pages</h2>" # html header
echo "<ul>"
for name in `ls -lt pages/*.html | awk '{print $9}'`
do
echo "<li><a href="$name">`head -6 $name | tail -1`</a></li>"
done
echo "</ul>"
DATETEXT=$(date '+%a %b %d %Y')
echo "<hr /><p><small>Last updated: $DATETEXT</small></p>
</body>
</html>"
chmod 777 index.html
exit 0
publish.sh
I need to exclude the makepage.sh script from the mirror.
#!/bin/sh
HOST=web.server.com
USER=usernameonserver
PASS=secret
./makeindex.sh > index.html
echo "Starting to sftp..."
lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd public_html_folder
put index.html
put style.css
mirror -e -n -R pages
bye
EOF
echo "done"
exit 0
Thanks very much
I write my Web pages using markdown format. I use three bash scripts to publish the Web pages to a hosted Web server. These scripts are horrible hacks I've cobbled together out of bits found on Web pages. Typically, I find a single command in Bash that does what I want then wrap that in some echo line or backticks.
Any improvements you can suggest to the scripts, or better commands to use, would be appreciated. Or suggestions for functions to read up on.
makepage.sh is called from within the 'pages' directory, runs the markdown script and adds a header and footer, saving the result as an html file
makeindex.sh builds an index of all the html files in the 'pages' directory and writes an index.html file. This command is run from the directory above the pages directory and index.html ends up in the 'top' of the Web server public_html directory
publish.sh calls lftp and mirrors the pages directory to the remote server, and then separately copies up the index and style sheet as that's all I want in the top level.
makepage.sh
#!/bin/bash
TEXTFILE=${1}
TITLE=`head -1 $TEXTFILE`
echo "<!DOCTYPE gunge cut to save space">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />
<title>
$TITLE
</title>
<link rel=\"stylesheet\" href=\"../style.css\" type=\"text/css\" media=\"screen\" />
</head>
<body>
<p>[ <a href=\"../index.html\">home</a> ]</p> " | tee $TEXTFILE.html
markdown $TEXTFILE | tee --append $TEXTFILE.html
DATETEXT=$(date '+%a %b %d %Y')
echo "<hr /><p><small>Keith Burnett, Last update: $DATETEXT</small></p>
</body>
</html>" | tee --append $TEXTFILE.html
chmod 777 $TEXTFILE.html
exit 0
makeindex.sh
The html title of the page is always on line 6 of the converted html file when converted using makepage.sh. The ls -lt command produces a list of files with the most recently modified listed first.
#!/bin/sh
echo "<h2>Recently modified pages</h2>" # html header
echo "<ul>"
for name in `ls -lt pages/*.html | awk '{print $9}'`
do
echo "<li><a href="$name">`head -6 $name | tail -1`</a></li>"
done
echo "</ul>"
DATETEXT=$(date '+%a %b %d %Y')
echo "<hr /><p><small>Last updated: $DATETEXT</small></p>
</body>
</html>"
chmod 777 index.html
exit 0
publish.sh
I need to exclude the makepage.sh script from the mirror.
#!/bin/sh
HOST=web.server.com
USER=usernameonserver
PASS=secret
./makeindex.sh > index.html
echo "Starting to sftp..."
lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd public_html_folder
put index.html
put style.css
mirror -e -n -R pages
bye
EOF
echo "done"
exit 0
Thanks very much