@ -23,6 +23,7 @@
set -e
unset SKIP_FOOTER
unset SKIP_HEADER
unset SKIP_META
unset SKIP_LIST
unset VERBOSE
unset PRINT_HELP
@ -30,7 +31,7 @@ unset SKIP_SITEMAP
unset SKIP_FEED
usage( ) {
printf "Usage: rivet [-hvelfsu] [-p string] [-o destdir] srcdir domain\n"
printf "Usage: rivet [-hvelfsurdt ] [-p string] [-o destdir] [-m number] [-n string ] srcdir domain\n"
printf "\t-h: prints this message\n"
printf "\t-o [destdir]: specifies the output direcotory to be [destdir]\n"
printf "\t-p [string]: Rename the \"Pages\" section to [string]\n"
@ -40,11 +41,12 @@ usage() {
0 to include all files\n "
printf "\t-v: Makes the script verbose\n"
printf "\t-e: Do not prepend _header.html to .html files\n"
printf "\t-f: Do not prepend _footer.html to .html files\n"
printf "\t-l: Do not generate \"Pages\" section in index.html\n"
printf "\t-f: Do not prepend _footer.html to .html files\n"
printf "\t-s: Do not generate sitemap.xml\n"
printf "\t-r: Do not generate an atom feed\n"
printf "\t-u: Makes all references to the url 'http' instead of 'https'\n"
printf "\t-r: Do not generate an atom feed\n"
printf "\t-t: Do not insert contents of _metadata.html"
exit 2
}
@ -55,7 +57,8 @@ convert() {
tmpfile = "tmpconvfile.tmp"
outfile = " ${ infile %md } html "
cp " $infile " " $tmpfile "
lowdown -s -Thtml -o " $outfile " " $tmpfile "
lowdown --html-no-skiphtml --html-no-escapehtml -s -Thtml \
-o " $outfile " " $tmpfile "
rm -f " $tmpfile " " $infile "
fi
# TODO: convert links to .md to .html
@ -64,7 +67,7 @@ convert() {
# Check dependencies
if ! command -v lowdown > /dev/null; then
echo "lowdown is not installed"
exit
exit 1
fi
destdir = 'dst'
@ -73,7 +76,7 @@ linksec='Pages'
blog_title = 'Atom feed'
blog_desc = ''
blog_nmax = '0'
while getopts 'o:vhelfsrup:n:d:m:' c
while getopts 'o:vhelfsrup:n:d:m:t ' c
do
case " $c " in
o) destdir = ${ OPTARG %% \/ } ; ;
@ -89,6 +92,7 @@ do
n) blog_title = " $OPTARG " ; ;
d) blog_desc = " $OPTARG " ; ;
m) blog_nmax = " $OPTARG " ; ;
t) SKIP_META = true ; ;
*) ; ;
esac
done
@ -103,6 +107,7 @@ srcdir=${src%%\/}
unset src
headerfile = $srcdir /_header.html
footerfile = $srcdir /_footer.html
metafile = $srcdir /_metadata.html
objlist = objlist.tmp
objdate = objdate.tmp
@ -135,6 +140,7 @@ url="$prefix"'://'"$domain"
if [ " $PRINT_HELP " ] ; then
usage
exit 0
fi
if [ " $VERBOSE " ] ; then
set -x
@ -143,6 +149,7 @@ fi
if ! [ -d " $srcdir " ] ; then
echo "Error: missing source direcotry"
usage
exit 1
fi
rm -rf " $destdir "
@ -159,7 +166,7 @@ while IFS="" read -r file; do
done < " $objlist "
sed -i -e " s,^\/*[^\/]*\/, $destdir /, " " $objlist "
# Convert markdown files
# Convert convertible files
while IFS = "" read -r file; do
convert " $file "
done < " $objlist "
@ -172,25 +179,13 @@ linklist=linklist.tmp
cp -f " $objlist " " $linklist "
sed -i -e " s/^ $destdir // " -e " s/^/ $prefix :\/\/ $domain / " " $linklist "
# Prepare the header
if ! [ " $SKIP_HEADER " ] ; then
# Insert metadata into <head>
if ! [ " $SKIP_META " ] ; then
find " $destdir " -name "*.html" |
while IFS = "" read -r file; do
sed -i " /<head>/r $header file " " $file "
sed -i " /<head>/r $meta file " " $file "
done
fi
# Prepate the footer
if ! [ " $SKIP_FOOTER " ] ; then
tmpfoot = "tmpfootfile.tmp"
cp " $footerfile " " $tmpfoot "
sed -i '1s/^/<footer>/' " $tmpfoot "
echo '</footer>' >> " $tmpfoot "
find " $destdir " -name "*.html" |
while IFS = "" read -r file; do
sed -i " /<\/body>/r $tmpfoot " " $file "
done
rm -f " $tmpfoot "
fi
# Prepare index file list
if ! [ " $SKIP_LIST " ] ; then
@ -221,6 +216,40 @@ EOF
rm -f " $tmpfile "
fi
# enclose article inside <article></article>
find " $destdir " -name "*.html" |
while IFS = "" read -r file; do
sed -i -e '/<body>/a <article>' -e '/<\/body>/i </article>' " $file "
done
# Prepate the header
if ! [ " $SKIP_HEADER " ] ; then
tmphead = "tmpheadfile.tmp"
cp " $headerfile " " $tmphead "
sed -i '1s/^/<header>/' " $tmphead "
echo '</header>' >> " $tmphead "
find " $destdir " -name "*.html" |
while IFS = "" read -r file; do
sed -i " /<body>/r $tmphead " " $file "
done
rm -f " $tmphead "
fi
# Prepare the footer
if ! [ " $SKIP_FOOTER " ] ; then
tmpfoot = "tmpfootfile.tmp"
cp " $footerfile " " $tmpfoot "
sed -i '1s/^/<footer>/' " $tmpfoot "
echo '</footer>' >> " $tmpfoot "
find " $destdir " -name "*.html" |
while IFS = "" read -r file; do
sed -i '/<\/body>/i REPLACE' " $file "
sed -i " /^REPLACE/r $tmpfoot " " $file "
sed -i 's/^REPLACE//' " $file "
done
rm -f " $tmpfoot "
fi
# Generate sitemap
if ! [ " $SKIP_SITEMAP " ] ; then
cat << EOF >> " $destdir " /sitemap.xml
@ -277,4 +306,4 @@ fi
rm -f " $objlist " " $linklist " " $objdate "
exit
exit 0