diff --git a/README.md b/README.md index 7069dee..2ffc7bd 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,5 @@ Features Non features (not planned) -------------------------- -- Comments. Would need a CAPTCHA or another antispam mechanism. Comments are handled through twitter, with a Twitter button Read the CHANGELOG section of the script header for more updates diff --git a/bb.sh b/bb.sh index 1c5b9fc..f126832 100755 --- a/bb.sh +++ b/bb.sh @@ -15,7 +15,7 @@ # Basically it asks the user to create a text file, then converts it into a .html file # and then rebuilds the index.html and feed.rss. # -# Comments are not supported. +# Comments are supported via external service (Disqus). # # This script is standalone, it doesn't require any other file to run # @@ -60,6 +60,8 @@ # ######################################################################################### # +# 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 # 1.5 Durad Radojicic refactored some code and added flexibility and i18n # 1.4.2 Now issues are handled at Github @@ -85,9 +87,15 @@ # 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 +global_config=".config" + global_variables() { + echo Loading inline configuration + global_software_name="BashBlog" - global_software_version="1.5.1" + global_software_version="1.6.1" # Blog title global_title="My fancy blog" @@ -118,6 +126,10 @@ global_variables() { global_twitter="true" global_twitter_username="example" + # Leave these empty if you don't want to use disqus for comments + global_disqus="true" + global_disqus_username="disqus_undefined" + # Blog generated files # index page of blog (it is usually good to use "index.html" here) @@ -169,6 +181,45 @@ google_analytics() { " } +# Prints the required code for disqus comments +disqus_body() { +if [ "$global_disqus" != "" ]; then + echo '
+ + + comments powered by Disqus' +fi + +} +# Prints the required code for disqus in the footer +disqus_footer() { +if [ "$global_disqus" != "" ]; then + echo '' + + fi +} + # Edit an existing, published .html file while keeping its original timestamp # Please note that this function does not automatically republish anything, as # it is usually called from 'main'. @@ -178,7 +229,7 @@ google_analytics() { # # $1 the file to edit edit() { - timestamp="$(date -r $1 +'%Y%m%d%k%M')" + timestamp="$(date -r $1 +'%Y%m%d%H%M')" $EDITOR "$1" touch -t $timestamp "$1" } @@ -187,8 +238,8 @@ edit() { # # $1 the post URL twitter() { - echo "

$template_comments  " - echo " $template_comments  " + echo "' >> "$filename" # content + + # Add disqus commments except for index and all_posts pages + if [[ ${filename%.*.*} != "index" && ${filename%.*.*} != "all_posts" ]]; then + disqus_body >> "$filename" + fi # page footer cat .footer.html >> "$filename" # close divs echo '' >> "$filename" # divbody and divbodyholder + disqus_footer >> "$filename" echo '' >> "$filename" } @@ -422,7 +479,7 @@ rebuild_index() { # Displays a list of the posts list_posts() { ls *.html &> /dev/null - if [[ $? -ne 0 ]]; then + if [[ $? -ne 0 ]]; then echo "No posts yet. Use 'bb.sh post' to create one" return fi @@ -568,7 +625,7 @@ rebuild_all_entries() { create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" # keep the original timestamp! - timestamp="$(date -r $i +'%Y%m%d%k%M')" + timestamp="$(date -r $i +'%Y%m%d%H%M')" mv "$i.rebuilt" "$i" chmod 644 "$i" touch -t $timestamp "$i" @@ -608,13 +665,35 @@ reset() { fi } +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. + else + echo ERROR: Not GNU date found. + echo Try installing gdate utility or coreutils. + echo Exiting... + exit + fi + fi +} + # Main function # Encapsulated on its own function for readability purposes # # $1 command to run # $2 file name of a draft to continue editing (optional) do_main() { - global_variables + # 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 # Check for $EDITOR if [[ -z "$EDITOR" ]]; then