Merge pull request #13 from carlosbm/master
Disqus and other enhancements
This commit is contained in:
commit
1f1ca64990
2 changed files with 87 additions and 9 deletions
|
@ -50,6 +50,5 @@ Features
|
||||||
Non features (not planned)
|
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
|
Read the CHANGELOG section of the script header for more updates
|
||||||
|
|
95
bb.sh
95
bb.sh
|
@ -15,7 +15,7 @@
|
||||||
# Basically it asks the user to create a text file, then converts it into a .html file
|
# 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.
|
# 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
|
# 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.1 Misc bugfixes and parameter checks
|
||||||
# 1.5 Durad Radojicic refactored some code and added flexibility and i18n
|
# 1.5 Durad Radojicic refactored some code and added flexibility and i18n
|
||||||
# 1.4.2 Now issues are handled at Github
|
# 1.4.2 Now issues are handled at Github
|
||||||
|
@ -85,9 +87,15 @@
|
||||||
|
|
||||||
# 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
|
||||||
|
global_config=".config"
|
||||||
|
|
||||||
global_variables() {
|
global_variables() {
|
||||||
|
echo Loading inline configuration
|
||||||
|
|
||||||
global_software_name="BashBlog"
|
global_software_name="BashBlog"
|
||||||
global_software_version="1.5.1"
|
global_software_version="1.6.1"
|
||||||
|
|
||||||
# Blog title
|
# Blog title
|
||||||
global_title="My fancy blog"
|
global_title="My fancy blog"
|
||||||
|
@ -118,6 +126,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)
|
||||||
|
@ -169,6 +181,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'.
|
||||||
|
@ -178,7 +229,7 @@ google_analytics() {
|
||||||
#
|
#
|
||||||
# $1 the file to edit
|
# $1 the file to edit
|
||||||
edit() {
|
edit() {
|
||||||
timestamp="$(date -r $1 +'%Y%m%d%k%M')"
|
timestamp="$(date -r $1 +'%Y%m%d%H%M')"
|
||||||
$EDITOR "$1"
|
$EDITOR "$1"
|
||||||
touch -t $timestamp "$1"
|
touch -t $timestamp "$1"
|
||||||
}
|
}
|
||||||
|
@ -187,8 +238,8 @@ edit() {
|
||||||
#
|
#
|
||||||
# $1 the post URL
|
# $1 the post URL
|
||||||
twitter() {
|
twitter() {
|
||||||
echo "<p id='twitter'>$template_comments "
|
echo "<p id='twitter'> <a href=\"$1#disqus_thread\">$template_comments</a> "
|
||||||
echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"$template_twitter_comment\" data-url=\"$1\""
|
echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"<Type your comment here but please leave the URL so that other people can follow the comments>\" data-url=\"$1\""
|
||||||
|
|
||||||
if [ "$global_twitter_username" != "" ]; then
|
if [ "$global_twitter_username" != "" ]; then
|
||||||
echo " data-via=\"$global_twitter_username\""
|
echo " data-via=\"$global_twitter_username\""
|
||||||
|
@ -258,10 +309,16 @@ create_html_page() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo '</div>' >> "$filename" # content
|
echo '</div>' >> "$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
|
# 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
|
||||||
|
disqus_footer >> "$filename"
|
||||||
echo '</body></html>' >> "$filename"
|
echo '</body></html>' >> "$filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +479,7 @@ rebuild_index() {
|
||||||
# Displays a list of the posts
|
# Displays a list of the posts
|
||||||
list_posts() {
|
list_posts() {
|
||||||
ls *.html &> /dev/null
|
ls *.html &> /dev/null
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
echo "No posts yet. Use 'bb.sh post' to create one"
|
echo "No posts yet. Use 'bb.sh post' to create one"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -568,7 +625,7 @@ rebuild_all_entries() {
|
||||||
|
|
||||||
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp"
|
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp"
|
||||||
# keep the original 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"
|
mv "$i.rebuilt" "$i"
|
||||||
chmod 644 "$i"
|
chmod 644 "$i"
|
||||||
touch -t $timestamp "$i"
|
touch -t $timestamp "$i"
|
||||||
|
@ -608,13 +665,35 @@ reset() {
|
||||||
fi
|
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
|
# Main function
|
||||||
# Encapsulated on its own function for readability purposes
|
# Encapsulated on its own function for readability purposes
|
||||||
#
|
#
|
||||||
# $1 command to run
|
# $1 command to run
|
||||||
# $2 file name of a draft to continue editing (optional)
|
# $2 file name of a draft to continue editing (optional)
|
||||||
do_main() {
|
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
|
# Check for $EDITOR
|
||||||
if [[ -z "$EDITOR" ]]; then
|
if [[ -z "$EDITOR" ]]; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue