Browse Source

Configuration settings for disqus variables

Carlos Bautista 12 years ago
parent
commit
2ca8e59bd0
1 changed files with 55 additions and 6 deletions
  1. 55 6
      bb.sh

+ 55 - 6
bb.sh

@@ -90,10 +90,10 @@
 global_config=".config"
 global_config=".config"
 
 
 global_variables() {
 global_variables() {
-	if [[ -z $EDITOR ]]; then EDITOR=vim; fi
+    echo Loading inline configuration
 
 
     global_software_name="BashBlog"
     global_software_name="BashBlog"
-    global_software_version="1.5.1"
+    global_software_version="1.6.0"
 
 
     # Blog title
     # Blog title
     global_title="My fancy blog"
     global_title="My fancy blog"
@@ -124,6 +124,10 @@ global_variables() {
     global_twitter="true"
     global_twitter="true"
     global_twitter_username="example"
     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
     # Blog generated files
     # index page of blog (it is usually good to use "index.html" here)
     # index page of blog (it is usually good to use "index.html" here)
@@ -175,6 +179,45 @@ google_analytics() {
 </script>"
 </script>"
 }
 }
 
 
+# Prints the required code for disqus comments
+disqus_body() {
+if [ "$global_disqus" != "" ]; then
+    echo '<div id="disqus_thread"></div>
+            <script type="text/javascript">
+            /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+               var disqus_shortname = '\'$global_disqus_username\''; // required: replace example with your forum shortname
+
+            /* * * DONT EDIT BELOW THIS LINE * * */
+            (function() {
+            var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
+            dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js";
+            (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
+            })();
+            </script>
+            <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>'
+fi
+
+}
+# Prints the required code for disqus in the footer
+disqus_footer() {
+if [ "$global_disqus" != "" ]; then
+       echo '<script type="text/javascript">
+               /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+               var disqus_shortname = '\'$global_disqus_username\''; // required: replace example with your forum shortname
+
+               /* * * DONT EDIT BELOW THIS LINE * * */
+               (function () {
+               var s = document.createElement("script"); s.async = true;
+               s.type = "text/javascript";
+               s.src = "//" + disqus_shortname + ".disqus.com/count.js";
+               (document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s);
+               }());
+               </script>'
+
+    fi
+}
+
 # Edit an existing, published .html file while keeping its original timestamp
 # Edit an existing, published .html file while keeping its original timestamp
 # Please note that this function does not automatically republish anything, as
 # Please note that this function does not automatically republish anything, as
 # it is usually called from 'main'.
 # it is usually called from 'main'.
@@ -266,13 +309,13 @@ create_html_page() {
     echo '</div>' >> "$filename" # content
     echo '</div>' >> "$filename" # content
     echo ${filename%.*.*}
     echo ${filename%.*.*}
     if [[ ${filename%.*.*} !=  "index" && ${filename%.*.*} != "all_posts" ]]; then
     if [[ ${filename%.*.*} !=  "index" && ${filename%.*.*} != "all_posts" ]]; then
-    	cat disqus >> "$filename"
+    	disqus_body >> "$filename"
     fi
     fi
     # page footer
     # page footer
     cat .footer.html >> "$filename"
     cat .footer.html >> "$filename"
     # close divs
     # close divs
     echo '</div></div>' >> "$filename" # divbody and divbodyholder 
     echo '</div></div>' >> "$filename" # divbody and divbodyholder 
-    cat disqus_footer >> "$filename"
+    disqus_footer >> "$filename"
     echo '</body></html>' >> "$filename"
     echo '</body></html>' >> "$filename"
 }
 }
 
 
@@ -623,7 +666,7 @@ date_version_detect() {
 	if !(date --version >/dev/null 2>&1)  ; then
 	if !(date --version >/dev/null 2>&1)  ; 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
-                   alias date=gdate
+                   DATE_COMMAND=gdate
 		   echo Using gdate.
 		   echo Using gdate.
 		else
 		else
 		   echo ERROR: Not GNU date found.
 		   echo ERROR: Not GNU date found.
@@ -631,9 +674,14 @@ date_version_detect() {
 		   echo Exiting...
 		   echo Exiting...
 		   exit
 		   exit
 		fi
 		fi
+
+	else
+		DATE_COMMAND=date
 	fi    
 	fi    
 }
 }
-
+date() {
+$DATE_COMMAND "$@"
+} 
 # Main function
 # Main function
 # Encapsulated on its own function for readability purposes
 # Encapsulated on its own function for readability purposes
 #
 #
@@ -643,6 +691,7 @@ 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
     # Use config file or fallback to inline configuration
+    echo Loading configuration
     source "$global_config" &> /dev/null ||  global_variables
     source "$global_config" &> /dev/null ||  global_variables
 
 
     # Check for $EDITOR
     # Check for $EDITOR