From 8285873bc78af3323ec7356344376f61a4010221 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Thu, 9 Jan 2014 19:50:27 +0100 Subject: [PATCH] Allow personalized header/footer files --- bb.sh | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/bb.sh b/bb.sh index 3125ecf..989ac76 100755 --- a/bb.sh +++ b/bb.sh @@ -64,6 +64,7 @@ # ######################################################################################### # +# 2.0.1 Allow personalized header/footer files # 2.0 Added Markdown support # Fully support BSD date # 1.6.4 Fixed bug in localized dates @@ -106,7 +107,7 @@ global_config=".config" # by the 'global_config' file contents global_variables() { global_software_name="BashBlog" - global_software_version="2.0" + global_software_version="2.0.1" # Blog title global_title="My fancy blog" @@ -149,6 +150,11 @@ global_variables() { # feed file (rss in this case) blog_feed="feed.rss" number_of_feed_articles="10" + # personalized header and footer (only if you know what you're doing) + # DO NOT name them .header.html, .footer.html or they will be overwritten + # leave blank to generate them, recommended + header_file="" + footer_file="" # Localization and i18n # "Comments?" (used in twitter link after every post) @@ -175,6 +181,18 @@ global_variables() { markdown_bin="$(which Markdown.pl)" } +# 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" ]] && + echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" && + exit + [[ "$footer_file" == ".footer.html" ]] && + echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" && + exit +} + + # Test if the markdown script is working correctly test_markdown() { [[ -z "$markdown_bin" ]] && return 1 @@ -606,22 +624,28 @@ make_rss() { # generate headers, footers, etc create_includes() { - echo '

'$global_title'

' > ".title.html" - echo '
'$global_description'
' >> ".title.html" + if [[ -f "$header_file" ]]; then cp "$header_file" .header.html + else + echo '

'$global_title'

' > ".title.html" + echo '
'$global_description'
' >> ".title.html" - echo '' > ".header.html" - echo '' >> ".header.html" - echo '' >> ".header.html" - echo '' >> ".header.html" - echo '' >> ".header.html" - if [[ "$global_feedburner" == "" ]]; then - echo '' >> ".header.html" - else - echo '' >> ".header.html" + echo '' > ".header.html" + echo '' >> ".header.html" + echo '' >> ".header.html" + echo '' >> ".header.html" + echo '' >> ".header.html" + if [[ "$global_feedburner" == "" ]]; then + echo '' >> ".header.html" + else + echo '' >> ".header.html" + fi fi - protected_mail="$(echo "$global_email" | sed 's/@/\@/g' | sed 's/\./\./g')" - echo '' >> ".footer.html" + if [[ -f "$footer_file" ]]; then cp "$footer_file" .footer.html + else + protected_mail="$(echo "$global_email" | sed 's/@/\@/g' | sed 's/\./\./g')" + echo '' >> ".footer.html" + fi } # Delete the temporarily generated include files @@ -774,6 +798,7 @@ do_main() { # Load default configuration, then override settings with the config file global_variables [[ -f "$global_config" ]] && source "$global_config" &> /dev/null + global_variables_check # Check for $EDITOR [[ -z "$EDITOR" ]] &&