diff --git a/bb.sh b/bb.sh index eacf90b..dbeb198 100755 --- a/bb.sh +++ b/bb.sh @@ -143,16 +143,16 @@ global_variables() { # Markdown location. Trying to autodetect by default. # The invocation must support the signature 'markdown_bin in.md > out.html' - markdown_bin="$(which Markdown.pl || which markdown)" + markdown_bin=$(which Markdown.pl || which markdown) } # Check for the validity of some variables # DO NOT EDIT THIS FUNCTION unless you know what you're doing global_variables_check() { - [[ "$header_file" == ".header.html" ]] && + [[ $header_file == .header.html ]] && echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" && exit - [[ "$footer_file" == ".footer.html" ]] && + [[ $footer_file == .footer.html ]] && echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" && exit } @@ -160,17 +160,17 @@ global_variables_check() { # Test if the markdown script is working correctly test_markdown() { - [[ -z "$markdown_bin" ]] && return 1 - [[ -z "$(which diff)" ]] && return 1 + [[ -z $markdown_bin ]] && return 1 + [[ -z $(which diff) ]] && return 1 - in="/tmp/md-in-${RANDOM}.md" - out="/tmp/md-out-${RANDOM}.html" - good="/tmp/md-good-${RANDOM}.html" + in=/tmp/md-in-${RANDOM}.md + out=/tmp/md-out-${RANDOM}.html + good=/tmp/md-good-${RANDOM}.html echo -e "line 1\n\nline 2" > "$in" echo -e "
line 1
\n\nline 2
" > "$good" - $markdown_bin $in > $out 2> /dev/null + "$markdown_bin" "$in" > "$out" 2> /dev/null diff $good $out &> /dev/null # output is irrelevant, we'll check $? - if [[ $? -ne 0 ]]; then + if (($? != 0)); then rm -f "$in" "$good" "$out" return 1 fi @@ -182,8 +182,8 @@ test_markdown() { # Parse a Markdown file into HTML and return the generated file markdown() { - out="$(echo $1 | sed 's/md$/html/g')" - while [ -f "$out" ]; do out="$(echo $out | sed 's/\.html$/\.'$RANDOM'\.html/')"; done + out=${1%.md}.html + while [[ -f $out ]]; do out=${out%.html}.$RANDOM.html; done $markdown_bin "$1" > "$out" echo "$out" } @@ -191,9 +191,9 @@ markdown() { # Prints the required google analytics code google_analytics() { - [[ -z "$global_analytics" ]] && [[ -z "$global_analytics_file" ]] && return + [[ -z $global_analytics && -z $global_analytics_file ]] && return - if [[ -z "$global_analytics_file" ]]; then + if [[ -z $global_analytics_file ]]; then echo "' + echo "" return; else echo "$template_comments "; @@ -387,14 +387,16 @@ twitter() { # Return 0 (bash return value 'true') if the input file is an index, feed, etc # or 1 (bash return value 'false') if it is a blogpost is_boilerplate_file() { - name="`clean_filename $1`" - if [[ "$name" == "$index_file" ]] || [[ "$name" == "$archive_index" ]] || [[ "$name" == "$tags_index" ]] || [[ "$name" == "$footer_file" ]] || [[ "$name" == "$header_file" ]] || [[ "$name" == "$global_analytics_file" ]] || [[ "$name" = "$prefix_tags"* ]] ; then return 0 - else # Check for exclded - for excl in ${html_exclude[*]}; do - [[ "$name" == "$excl" ]] && return 0 + name=$(clean_filename "$1") + case $name in + ( "$index_file" | "$archive_index" | "$tags_index" | "$footer_file" | "$header_file" | "$global_analytics_file" | "$prefix_tags"* ) + return 0 ;; + ( * ) # Check for excluded + for excl in "${html_exclude[@]}"; do + [[ $name == "$excl" ]] && return 0 done - return 1 - fi + return 1 ;; + esac } # Filenames sometimes have leading './' or other oddities which need to be cleaned @@ -402,9 +404,7 @@ is_boilerplate_file() { # $1 the file name # returns the clean file name clean_filename() { - name="$1" - [[ "${name:0:2}" == "./" ]] && name=${name:2} # Delete leading './' - echo $name + echo "${1#./}" # Delete leading './' } # Adds all the bells and whistles to format the html page @@ -419,67 +419,69 @@ clean_filename() { # $4 title for the html header # $5 original blog timestamp create_html_page() { - content="$1" - filename="$2" - index="$3" - title="$4" - timestamp="$5" + content=$1 + filename=$2 + index=$3 + title=$4 + timestamp=$5 # Create the actual blog post # html, head - cat ".header.html" > "$filename" - echo "
's on the title because of markdown conversion - echo "$(echo "$title" | sed 's/<\/*p>//g')" >> "$filename" - echo '
's on the title because of markdown conversion + echo "$title" | sed 's/<\/*p>//g' + echo '