From 2b8b2cce89bc3c28d33791bedb656987c895ed3c Mon Sep 17 00:00:00 2001 From: Carles Fenollosa Date: Wed, 5 Jun 2013 12:36:47 +0200 Subject: [PATCH] Modified some functions to adjust to the default code style Configuration in bb.sh is loaded and then overriden by .config --- bb.sh | 69 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/bb.sh b/bb.sh index f126832..f32c0b4 100755 --- a/bb.sh +++ b/bb.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash # BashBlog, a simple blog system written in a single bash script -# Author: Carles Fenollosa , 2011-2012 +# Author: Carles Fenollosa , 2011-2013 +# With contributions from many others: +# https://github.com/carlesfe/bashblog/commits/master ######################################################################################### @@ -60,6 +62,7 @@ # ######################################################################################### # +# 1.6.2 Simplified some functions and variables to avoid duplicated information # 1.6.1 'date' fix when hours are 1 digit. # 1.6.0 Disqus comments. External configuration file. Check of 'date' command version. # 1.5.1 Misc bugfixes and parameter checks @@ -88,14 +91,16 @@ # Global variables # It is recommended to perform a 'rebuild' after changing any of this in the code -# Config file. Use instead of this function if you want to avoid merges in VCS +# Config file. Any settings "key=value" written there will override the +# global_variables defaults. Useful to avoid editing bb.sh and having to deal +# with merges in VCS global_config=".config" +# This function will load all the variables defined here. They might be overriden +# by the 'global_config' file contents global_variables() { - echo Loading inline configuration - global_software_name="BashBlog" - global_software_version="1.6.1" + global_software_version="1.6.2" # Blog title global_title="My fancy blog" @@ -122,13 +127,11 @@ global_variables() { # or change it to your own URL global_feedburner="" - # Leave these empty if you don't want to use twitter for comments - global_twitter="true" - global_twitter_username="example" + # Change this to your username if you want to use twitter for comments + global_twitter_username="" - # Leave these empty if you don't want to use disqus for comments - global_disqus="true" - global_disqus_username="disqus_undefined" + # Change this to your disqus username to use disqus for comments + global_disqus_username="" # Blog generated files @@ -183,7 +186,8 @@ google_analytics() { # Prints the required code for disqus comments disqus_body() { -if [ "$global_disqus" != "" ]; then + if [ "$global_disqus_username" == "" ]; then return; fi + echo '
comments powered by Disqus' -fi - } + # Prints the required code for disqus in the footer disqus_footer() { -if [ "$global_disqus" != "" ]; then + if [ "$global_disqus_username" == "" ]; then return; fi echo '' - - fi } # Edit an existing, published .html file while keeping its original timestamp @@ -238,12 +239,17 @@ edit() { # # $1 the post URL twitter() { - echo "

$template_comments  " + if [[ "$global_twitter_username" == "" ]]; then return; fi + + if [[ "$global_disqus_username" == "" ]]; then + echo "

$template_comments " + else + echo "

$template_comments  " + fi + echo "$template_twitter_button " echo "

" @@ -301,9 +307,7 @@ create_html_page() { if [ "$index" == "no" ]; then echo '' >> "$filename" - if [ "$global_twitter" == "true" ]; then - twitter "$global_url/$file_url" >> "$filename" - fi + twitter "$global_url/$file_url" >> "$filename" echo '' >> "$filename" # absolute end of the post fi @@ -665,19 +669,18 @@ reset() { fi } +# Detects if GNU date is installed date_version_detect() { date --version >/dev/null 2>&1 if [ $? -ne 0 ]; then # date utility is BSD. Test if gdate is installed if gdate --version >/dev/null 2>&1 ; then - date() { - gdate "$@" - } - echo Using gdate. + date() { + gdate "$@" + } else - echo ERROR: Not GNU date found. + echo ERROR: GNU date not found. echo Try installing gdate utility or coreutils. - echo Exiting... exit fi fi @@ -691,9 +694,9 @@ date_version_detect() { do_main() { # Detect if using BSD date or GNU date date_version_detect - # Use config file or fallback to inline configuration - echo Loading configuration - source "$global_config" &> /dev/null || global_variables + # Load default configuration, then override settings with the config file + global_variables + [[ -f "$global_config" ]] && source "$global_config" &> /dev/null # Check for $EDITOR if [[ -z "$EDITOR" ]]; then