diff --git a/rivet.sh b/rivet.sh index 2495da5..8206920 100755 --- a/rivet.sh +++ b/rivet.sh @@ -12,12 +12,13 @@ usage() { printf "Usage: rivet [-o destdir] [-hovelf] srcdir domain\n" printf "\t-h: prints this message\n" printf "\t-o [destdir]: specifies the output direcotory to be [destdir]\n" - printf "\t-v: makes the script verbose\n" - printf "\t-e: skips prepending _header.html to .html files\n" - printf "\t-f: skips appending _footer.html to .html files\n" - printf "\t-l: skips the generation of .html file list\n" - printf "\t-s: skips sitemap.xml creation\n" - printf "\t-u: makes all references to the url 'http' instead of 'https'\n" + printf "\t-p: [string]: Rename the \"Pages\" section to [string]\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-s: Do not generate sitemap.xml\n" + printf "\t-u: Makes all references to the url 'http' instead of 'https'\n" exit 2 } @@ -39,16 +40,8 @@ fi destdir='dst' prefix='https' -# Get arguments using getopts -# rivet [src] [-vhelf] [-o dir] -# -o [dir]: set the destination directory, defaults to "dst" -# -v: verbose, sets x so it prints every line -# -h: prints usage -# -e: skip prepend header -# -l: skip article list -# -f: skip append footer -# -s: skip sitemap creation -while getopts 'o:vhelfsu' c +linksec='Pages' +while getopts 'o:vhelfsup:' c do case "$c" in o) destdir=${OPTARG%%\/} ;; @@ -59,6 +52,7 @@ do f) SKIP_FOOTER=true ;; s) SKIP_SITEMAP=true ;; u) prefix='http' ;; + p) linksec="$OPTARG" ;; *) ;; esac done @@ -72,6 +66,27 @@ src="$1" srcdir=${src%%\/} unset src +# Check if index.md is present +if ! [ -e "$srcdir"/index.md ]; then + echo "Missing index.md in $srcdir" + exit 1 +fi + +# Check header and footer files +if ! [ -e "$headerfile" ]; then + echo "Missing _header.html in $srcdir" + exit 1 +fi +if ! [ -e "$footerfile" ]; then + echo "Missing _footer.html in $srcdir" + exit 1 +fi +# Remove junk from {header,footer} files +sed -i 's///' "$headerfile" +sed -i 's/<\/header>//' "$headerfile" +sed -i 's///' "$footerfile" +sed -i 's/<\/footer>//' "$footerfile" + # Remove any junk from the domain eg. [https://]domain.com[/] url="$(echo "$2" | sed -e 's/^https*:\/\///' | @@ -138,7 +153,7 @@ if ! [ "$SKIP_SITEMAP" ] || ! [ "$SKIP_LIST" ]; then rm -f "$tmpfile" cat << EOF >> "$tmpfile"
-

Pages

+

"$linksec"

EOF while IFS="" read -r line; do if echo "$line" | grep -q 'index\.html'; then