version 0.3

fixes:
	- fixed the mess of options and general inconsistencies between program
	  man page and help message
	- fixed some cases where rivet should fail but didn't and specified
	  return values for all exit conditions
	- fixed the header system, before the header would have been added
	  inside of <head></head> which is incorrect, browsers would fix it
	  on the fly but still it is not correct.
	  Now _header.html contents are put inside <header></header> at the
	  beginning of <body>
	- fixed <footer> outside of <body>
	- some fixes in the man page

additions:
	- added the requirement for _metadata.html, this file contains tags
	  and html metadata that is put inside <head>
	- the main article is now enclosed inside <article></article> tags for
	  better styling
pull/1/head
Alessandro Mauri 3 years ago
parent 5ac9e2ae5f
commit 280d0946db
  1. 2
      makefile
  2. 22
      rivet.1
  3. 75
      rivet.sh

@ -1,4 +1,4 @@
VERSION = 0.2 VERSION = 0.3
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man MANPREFIX = ${PREFIX}/share/man

@ -5,10 +5,12 @@ rivet \- simple static site generator
.SH SYNOPSIS .SH SYNOPSIS
.SY rivet .SY rivet
.OP \-vhelfsu .OP \-hvelfsurdt
.OP \-o destdir .OP \-o destdir
.OP \-p string .OP \-p string
.I srcdir/ .OP \-m number
.OP \-n string
.I srcdir
.I domain .I domain
.YS .YS
@ -16,7 +18,7 @@ rivet \- simple static site generator
.PP .PP
Rivet is a POSIX shell script that relies on Rivet is a POSIX shell script that relies on
.BR lowdown(1) .BR lowdown(1)
to convert markdown ( refer to to convert markdown (refer to
.BR lowdown(5) .BR lowdown(5)
for more info on the dialect of markdown used and metadata) files to html and for more info on the dialect of markdown used and metadata) files to html and
build an output directory which can be uploaded to an http server. build an output directory which can be uploaded to an http server.
@ -48,7 +50,7 @@ Set the title of the atom feed to
.IP "\-d string" .IP "\-d string"
Set the description of the atom feed to Set the description of the atom feed to
.I string .I string
.IP "\-n number" .IP "\-m number"
Set the maximum number of elements in the atom feed to Set the maximum number of elements in the atom feed to
.I number .I number
setting it to '0' includes all files setting it to '0' includes all files
@ -62,6 +64,9 @@ Disables the application of the user-supplied header in
.IP \-f .IP \-f
Disables the application of the user-supplied footer in Disables the application of the user-supplied footer in
.I _footer.html .I _footer.html
.IP \-t
Disables the insertion of the user-supplied metadata in
.I _metadata.html
.IP \-l .IP \-l
Disables the generation of the "Pages" section in index.html Disables the generation of the "Pages" section in index.html
.IP \-s .IP \-s
@ -95,6 +100,7 @@ src/
- index.md - index.md
- _header.html - _header.html
- _footer.html - _footer.html
- _metadata.html
.EE .EE
.PP .PP
@ -110,6 +116,8 @@ contains
.EX .EX
<p> Header </p> <p> Header </p>
.EE .EE
.I _metadata.html
can be empty
.PP .PP
Note that since the contents of Note that since the contents of
@ -119,6 +127,12 @@ and
will be placed inside the correct tags, the files themselves do not need to will be placed inside the correct tags, the files themselves do not need to
contain <header> and <footer> tags (the script removes them) contain <header> and <footer> tags (the script removes them)
.PP
The contents of
.I _metadata.html
are placed inside the <head> tags, so it can contain stylesheets, icons and
other valid entries for the head of an html document
.PP .PP
To generate the site from the folder run the command To generate the site from the folder run the command
.EX .EX

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

Loading…
Cancel
Save