1
0
mirror of https://git.envs.net/envs/bashblog.git synced 2024-06-18 23:27:09 +00:00

Modified some functions to adjust to the default code style

Configuration in bb.sh is loaded and then overriden by .config
This commit is contained in:
Carles Fenollosa 2013-06-05 12:36:47 +02:00
parent 1f1ca64990
commit 2b8b2cce89

69
bb.sh
View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# BashBlog, a simple blog system written in a single bash script # BashBlog, a simple blog system written in a single bash script
# Author: Carles Fenollosa <carles.fenollosa@bsc.es>, 2011-2012 # Author: Carles Fenollosa <carles.fenollosa@bsc.es>, 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.1 'date' fix when hours are 1 digit.
# 1.6.0 Disqus comments. External configuration file. Check of 'date' command version. # 1.6.0 Disqus comments. External configuration file. Check of 'date' command version.
# 1.5.1 Misc bugfixes and parameter checks # 1.5.1 Misc bugfixes and parameter checks
@ -88,14 +91,16 @@
# Global variables # Global variables
# It is recommended to perform a 'rebuild' after changing any of this in the code # 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" global_config=".config"
# This function will load all the variables defined here. They might be overriden
# by the 'global_config' file contents
global_variables() { global_variables() {
echo Loading inline configuration
global_software_name="BashBlog" global_software_name="BashBlog"
global_software_version="1.6.1" global_software_version="1.6.2"
# Blog title # Blog title
global_title="My fancy blog" global_title="My fancy blog"
@ -122,13 +127,11 @@ global_variables() {
# or change it to your own URL # or change it to your own URL
global_feedburner="" global_feedburner=""
# Leave these empty if you don't want to use twitter for comments # Change this to your username if you want to use twitter for comments
global_twitter="true" global_twitter_username=""
global_twitter_username="example"
# Leave these empty if you don't want to use disqus for comments # Change this to your disqus username to use disqus for comments
global_disqus="true" global_disqus_username=""
global_disqus_username="disqus_undefined"
# Blog generated files # Blog generated files
@ -183,7 +186,8 @@ google_analytics() {
# Prints the required code for disqus comments # Prints the required code for disqus comments
disqus_body() { disqus_body() {
if [ "$global_disqus" != "" ]; then if [ "$global_disqus_username" == "" ]; then return; fi
echo '<div id="disqus_thread"></div> echo '<div id="disqus_thread"></div>
<script type="text/javascript"> <script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
@ -198,12 +202,11 @@ if [ "$global_disqus" != "" ]; then
</script> </script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>' <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>'
fi
} }
# Prints the required code for disqus in the footer # Prints the required code for disqus in the footer
disqus_footer() { disqus_footer() {
if [ "$global_disqus" != "" ]; then if [ "$global_disqus_username" == "" ]; then return; fi
echo '<script type="text/javascript"> echo '<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '\'$global_disqus_username\''; // required: replace example with your forum shortname var disqus_shortname = '\'$global_disqus_username\''; // required: replace example with your forum shortname
@ -216,8 +219,6 @@ if [ "$global_disqus" != "" ]; then
(document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s); (document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s);
}()); }());
</script>' </script>'
fi
} }
# Edit an existing, published .html file while keeping its original timestamp # Edit an existing, published .html file while keeping its original timestamp
@ -238,12 +239,17 @@ edit() {
# #
# $1 the post URL # $1 the post URL
twitter() { twitter() {
echo "<p id='twitter'> <a href=\"$1#disqus_thread\">$template_comments</a> &nbsp;" if [[ "$global_twitter_username" == "" ]]; then return; fi
if [[ "$global_disqus_username" == "" ]]; then
echo "<p id='twitter'>$template_comments&nbsp;"
else
echo "<p id='twitter'><a href=\"$1#disqus_thread\">$template_comments</a> &nbsp;"
fi
echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"&lt;Type your comment here but please leave the URL so that other people can follow the comments&gt;\" data-url=\"$1\"" echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"&lt;Type your comment here but please leave the URL so that other people can follow the comments&gt;\" data-url=\"$1\""
if [ "$global_twitter_username" != "" ]; then echo " data-via=\"$global_twitter_username\""
echo " data-via=\"$global_twitter_username\""
fi
echo ">$template_twitter_button</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>" echo ">$template_twitter_button</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>"
echo "</p>" echo "</p>"
@ -301,9 +307,7 @@ create_html_page() {
if [ "$index" == "no" ]; then if [ "$index" == "no" ]; then
echo '<!-- text end -->' >> "$filename" echo '<!-- text end -->' >> "$filename"
if [ "$global_twitter" == "true" ]; then twitter "$global_url/$file_url" >> "$filename"
twitter "$global_url/$file_url" >> "$filename"
fi
echo '<!-- entry end -->' >> "$filename" # absolute end of the post echo '<!-- entry end -->' >> "$filename" # absolute end of the post
fi fi
@ -665,19 +669,18 @@ reset() {
fi fi
} }
# Detects if GNU date is installed
date_version_detect() { date_version_detect() {
date --version >/dev/null 2>&1 date --version >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# date utility is BSD. Test if gdate is installed # date utility is BSD. Test if gdate is installed
if gdate --version >/dev/null 2>&1 ; then if gdate --version >/dev/null 2>&1 ; then
date() { date() {
gdate "$@" gdate "$@"
} }
echo Using gdate.
else else
echo ERROR: Not GNU date found. echo ERROR: GNU date not found.
echo Try installing gdate utility or coreutils. echo Try installing gdate utility or coreutils.
echo Exiting...
exit exit
fi fi
fi fi
@ -691,9 +694,9 @@ date_version_detect() {
do_main() { do_main() {
# Detect if using BSD date or GNU date # Detect if using BSD date or GNU date
date_version_detect date_version_detect
# Use config file or fallback to inline configuration # Load default configuration, then override settings with the config file
echo Loading configuration global_variables
source "$global_config" &> /dev/null || global_variables [[ -f "$global_config" ]] && source "$global_config" &> /dev/null
# Check for $EDITOR # Check for $EDITOR
if [[ -z "$EDITOR" ]]; then if [[ -z "$EDITOR" ]]; then