Added Durad version. Modified README

This commit is contained in:
Carlos Fenollosa 2013-02-21 16:37:55 +01:00
parent f0ba1beba6
commit a34c879cac
2 changed files with 419 additions and 526 deletions

View File

@ -14,6 +14,8 @@ Download bb.sh into a public folder of yours and run it:
This will show the available commands This will show the available commands
Before creating a blog post, edit bb.sh and modify the variables in the global_variables() function
To create your first post, just do: To create your first post, just do:
./bb.sh post ./bb.sh post

533
bb.sh
View File

@ -32,10 +32,6 @@
# There are many loops which iterate on '*.html' so make sure that the only html files # There are many loops which iterate on '*.html' so make sure that the only html files
# on this folder are the blog entries and index.html and all_posts.html. Drafts must go # on this folder are the blog entries and index.html and all_posts.html. Drafts must go
# into drafts/ and any other *.html file should be moved out of the way # into drafts/ and any other *.html file should be moved out of the way
#
# TODO instead of using a file for $content, use a variable to avoid disk writes
# TODO enclose all variables with quotes (thanks Durad)
# TODO use a tag for dates, and keep them in sync with the html files (thanks Durad)
######################################################################################### #########################################################################################
@ -64,6 +60,8 @@
# #
######################################################################################### #########################################################################################
# #
# 1.5 Durad Radojicic refactored some code and added flexibility
# 1.4.2 Now issues are handled at Github
# 1.4.1 Some code refactoring # 1.4.1 Some code refactoring
# 1.4 Using twitter for comments, improved 'rebuild' command # 1.4 Using twitter for comments, improved 'rebuild' command
# 1.3 'edit' command # 1.3 'edit' command
@ -90,36 +88,60 @@ global_variables() {
# If you want to fork the project please contact me first, I wouldn't mind opening a git # If you want to fork the project please contact me first, I wouldn't mind opening a git
# or some shared code base and collaborate with other people. # or some shared code base and collaborate with other people.
global_software_name="BashBlog" global_software_name="BashBlog"
global_software_version="1.4.1" global_software_version="1.5"
# Blog title # Blog title
global_title="Waiting for the jobs to finish" global_title="My blog"
# The typical subtitle for each blog # The typical subtitle for each blog
global_description="Thoughts on science and tips for researchers who use computers" global_description="A blog where I talk about stuff"
# The public base URL for this blog # The public base URL for this blog
global_url="http://mmb.pcb.ub.es/~carlesfe/blog" global_url="http://example.com/blog"
# blog generated files
# index page of blog (it is usually good to use "index.html" here)
index_file="index.html"
number_of_index_articles="8"
# global archive
archive_index="all_posts.html"
# feed file (rss in this case)
blog_feed="test.rss"
number_of_feed_articles="10"
# template elements that can be translated
# "Comments?" (used in twitter link after every post)
template_comments="Comments?"
# "View more posts" (used on bottom of index page as link to archive)
template_archive="View more posts"
# "Back to the index page" (used on archive page, it is link to blog index)
template_archive_index_page="Back to the index page"
# "Subscribe" (used on bottom of index page, it is link to RSS feed)
template_subscribe="Subscribe"
# "Subscribe to this page..." (used as text for browser feed button that is embedded to html)
template_subscribe_browser_button="Subscribe to this page..."
# "Tweet" (used as twitter text button for posting to twitter)
template_twitter_button="Tweet"
# Your name # Your name
global_author="Carles Fenollosa" global_author="John Smith"
# You can use twitter or facebook or anything for global_author_url # You can use twitter or facebook or anything for global_author_url
global_author_url="http://mmb.pcb.ub.es/~carlesfe" global_author_url="http://johnsmith.com/about-me"
# Your email # Your email
global_email="carles.fenollosa@bsc.es" global_email="johnsmith@example.com"
# CC by-nc-nd is a good starting point, you can change this to "©" for Copyright # CC by-nc-nd is a good starting point, you can change this to "©" for Copyright
global_license="CC by-nc-nd" global_license="CC by-nc-nd"
# If you have a Google Analytics ID, put it here. # If you have a Google Analytics ID, put it here.
# If left empty (i.e. "") Analytics will be disabled # If left empty (i.e. "") Analytics will be disabled
global_analytics="UA-752819-13" global_analytics=""
# Leave this empty (i.e. "") if you don't want to use feedburner, # Leave this empty (i.e. "") if you don't want to use feedburner,
# or change it to your own URL # or change it to your own URL
global_feedburner="http://feeds.feedburner.com/WaitingForTheJobsToFinish" global_feedburner="http://feeds.feedburner.example.com/MyBlog"
# Leave these empty if you don't want to use twitter for comments # Leave these empty if you don't want to use twitter for comments
global_twitter="true" global_twitter="true"
global_twitter_username="cfenollosa" global_twitter_username="examplecom"
} }
@ -151,23 +173,23 @@ 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%k%M')"
$EDITOR $1 $EDITOR "$1"
touch -t $timestamp $1 touch -t $timestamp "$1"
} }
# Adds the code needed by the twitter button # Adds the code needed by the twitter button
# #
# $1 the post URL # $1 the post URL
twitter() { twitter() {
echo "<p id='twitter'>Comments? &nbsp;" echo "<p id='twitter'>$template_comments &nbsp;"
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 if [ "$global_twitter_username" != "" ]; then
echo " data-via=\"$global_twitter_username\"" echo " data-via=\"$global_twitter_username\""
fi fi
echo ">Tweet</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>"
} }
@ -183,59 +205,59 @@ twitter() {
# $4 title for the html header # $4 title for the html header
# $5 original blog timestamp # $5 original blog timestamp
create_html_page() { create_html_page() {
content=$1 content="$1"
filename=$2 filename="$2"
index=$3 index="$3"
title=$4 title="$4"
timestamp=$5 timestamp="$5"
# Create the actual blog post # Create the actual blog post
# html, head # html, head
cat .header.html > $filename cat ".header.html" > "$filename"
echo "<title>$title</title>" >> $filename echo "<title>$title</title>" >> "$filename"
google_analytics >> $filename google_analytics >> "$filename"
echo "</head><body>" >> $filename echo "</head><body>" >> "$filename"
# body divs # body divs
echo '<div id="divbodyholder">' >> $filename echo '<div id="divbodyholder">' >> "$filename"
echo '<div class="headerholder"><div class="header">' >> $filename echo '<div class="headerholder"><div class="header">' >> "$filename"
# blog title # blog title
echo '<div id="title">' >> $filename echo '<div id="title">' >> "$filename"
cat .title.html >> $filename cat .title.html >> "$filename"
echo '</div></div></div>' >> $filename # title, header, headerholder echo '</div></div></div>' >> "$filename" # title, header, headerholder
echo '<div id="divbody"><div class="content">' >> $filename echo '<div id="divbody"><div class="content">' >> "$filename"
file_url="`sed 's/.rebuilt//g' <<< $filename`" # Get the correct URL when rebuilding file_url="$(sed 's/.rebuilt//g' <<< $filename)" # Get the correct URL when rebuilding
# one blog entry # one blog entry
if [ "$index" == "no" ]; then if [ "$index" == "no" ]; then
echo '<!-- entry begin -->' >> $filename # marks the beginning of the whole post echo '<!-- entry begin -->' >> "$filename" # marks the beginning of the whole post
echo '<h3><a class="ablack" href="'$global_url/$file_url'">' >> $filename echo '<h3><a class="ablack" href="'$global_url/$file_url'">' >> "$filename"
echo $title >> $filename echo "$title" >> "$filename"
echo '</a></h3>' >> $filename echo '</a></h3>' >> "$filename"
if [ "$timestamp" == "" ]; then if [ "$timestamp" == "" ]; then
echo '<div class="subtitle">'`date +"%B %d, %Y"`' &mdash; ' >> $filename echo '<div class="subtitle">'$(date +"%B %d, %Y")' &mdash; ' >> "$filename"
else else
echo '<div class="subtitle">'`date +"%B %d, %Y" --date="$timestamp"` ' &mdash; ' >> $filename echo '<div class="subtitle">'$(date +"%B %d, %Y" --date="$timestamp") ' &mdash; ' >> "$filename"
fi fi
echo "$global_author</div>" >> $filename echo "$global_author</div>" >> "$filename"
echo '<!-- text begin -->' >> $filename # This marks the text body, after the title, date... echo '<!-- text begin -->' >> "$filename" # This marks the text body, after the title, date...
fi fi
cat $content >> $filename # Actual content cat "$content" >> "$filename" # Actual content
if [ "$index" == "no" ]; then if [ "$index" == "no" ]; then
echo '<!-- text end -->' >> $filename echo '<!-- text end -->' >> "$filename"
if [ "$global_twitter" == "true" ]; then if [ "$global_twitter" == "true" ]; then
twitter "$global_url/$file_url" >> $filename twitter "$global_url/$file_url" >> "$filename"
fi fi
echo '<!-- entry end -->' >> $filename # absolute end of the post echo '<!-- entry end -->' >> "$filename" # absolute end of the post
fi fi
echo '</div>' >> $filename # content echo '</div>' >> "$filename" # content
# 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
echo '</body></html>' >> $filename echo '</body></html>' >> "$filename"
} }
# Parse the plain text file into an html file # Parse the plain text file into an html file
@ -244,26 +266,26 @@ parse_file() {
title="" title=""
while read line; do while read line; do
if [ "$title" == "" ]; then if [ "$title" == "" ]; then
title=$line title="$line"
filename="`echo $title | tr [:upper:] [:lower:]`" filename="$(echo $title | tr [:upper:] [:lower:])"
filename="`echo $filename | sed 's/\ /-/g'`" filename="$(echo $filename | sed 's/\ /-/g')"
filename="`echo $filename | tr -dc '[:alnum:]-'`" # html likes alphanumeric filename="$(echo $filename | tr -dc '[:alnum:]-')" # html likes alphanumeric
filename="$filename.html" filename="$filename.html"
content=$filename.tmp content="$filename.tmp"
# Check for duplicate file names # Check for duplicate file names
while [ -f "$filename" ]; do while [ -f "$filename" ]; do
suffix=$RANDOM suffix="$RANDOM"
filename="`echo $filename | sed 's/\.html/'$suffix'\.html/g'`" filename="$(echo $filename | sed 's/\.html/'$suffix'\.html/g')"
done done
else else
echo $line >> $content echo "$line" >> "$content"
fi fi
done < "$TMPFILE" done < "$TMPFILE"
# Create the actual html page # Create the actual html page
create_html_page $content $filename no "$title" create_html_page "$content" "$filename" no "$title"
rm $content rm "$content"
} }
# Manages the creation of the text file and the parsing to html file # Manages the creation of the text file and the parsing to html file
@ -277,37 +299,37 @@ write_entry() {
exit exit
fi fi
else else
TMPFILE=.entry-$RANDOM.html TMPFILE=".entry-$RANDOM.html"
echo "Title on this line" >> $TMPFILE echo "Title on this line" >> "$TMPFILE"
echo "" >> $TMPFILE echo "" >> "$TMPFILE"
echo "<p>The rest of the text file is an <b>html</b> blog post. The process" >> $TMPFILE echo "<p>The rest of the text file is an <b>html</b> blog post. The process" >> "$TMPFILE"
echo "will continue as soon as you exit your editor</p>" >> $TMPFILE echo "will continue as soon as you exit your editor</p>" >> "$TMPFILE"
fi fi
chmod 600 $TMPFILE chmod 600 "$TMPFILE"
post_status="E" post_status="E"
while [ "$post_status" != "p" ] && [ "$post_status" != "P" ]; do while [ "$post_status" != "p" ] && [ "$post_status" != "P" ]; do
$EDITOR $TMPFILE $EDITOR "$TMPFILE"
parse_file "$TMPFILE" # this command sets $filename as the html processed file parse_file "$TMPFILE" # this command sets $filename as the html processed file
chmod 600 $filename chmod 600 "$filename"
echo -n "Preview? (Y/n) " echo -n "Preview? (Y/n) "
read p read p
if [ "$p" != "n" ] && [ "$p" != "N" ]; then if [ "$p" != "n" ] && [ "$p" != "N" ]; then
chmod 644 $filename chmod 644 "$filename"
echo "Open $global_url/$filename in your browser" echo "Open $global_url/$filename in your browser"
fi fi
echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) " echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) "
read post_status read post_status
if [ "$post_status" == "d" ] || [ "$post_status" == "D" ]; then if [ "$post_status" == "d" ] || [ "$post_status" == "D" ]; then
mkdir -p drafts/ mkdir -p "drafts/"
chmod 700 drafts/ chmod 700 "drafts/"
title="`head -n 1 $TMPFILE`" title="$(head -n 1 $TMPFILE)"
title="`echo $title | tr [:upper:] [:lower:]`" title="$(echo $title | tr [:upper:] [:lower:])"
title="`echo $title | sed 's/\ /-/g'`" title="$(echo $title | sed 's/\ /-/g')"
title="`echo $title | tr -dc '[:alnum:]-'`" title="$(echo $title | tr -dc '[:alnum:]-')"
draft="drafts/$title.html" draft="drafts/$title.html"
while [ -f "$draft" ]; do draft="drafts/$title-$RANDOM.html"; done while [ -f "$draft" ]; do draft="drafts/$title-$RANDOM.html"; done
@ -319,156 +341,156 @@ write_entry() {
exit exit
fi fi
if [ "$post_status" == "e" ] || [ "$post_status" == "E" ]; then if [ "$post_status" == "e" ] || [ "$post_status" == "E" ]; then
rm $filename # Delete the html file as it will be generated again rm "$filename" # Delete the html file as it will be generated again
fi fi
done done
rm $TMPFILE rm "$TMPFILE"
chmod 644 $filename chmod 644 "$filename"
echo "Posted $filename" echo "Posted $filename"
} }
# Create an index page with all the posts # Create an index page with all the posts
all_posts() { all_posts() {
echo -n "Creating an index page with all the posts " echo -n "Creating an index page with all the posts "
contentfile="all_posts.html.$RANDOM" contentfile="$archive_index.$RANDOM"
while [ -f "$contentfile" ]; do while [ -f "$contentfile" ]; do
contentfile="all_posts.html.$RANDOM" contentfile="$archive_index.$RANDOM"
done done
echo "<h3>All posts</h3>" >> $contentfile echo "<h3>All posts</h3>" >> "$contentfile"
echo "<ul>" >> $contentfile echo "<ul>" >> "$contentfile"
for i in `ls -t *.html`; do for i in $(ls -t *.html); do
if [ "$i" == "index.html" ] || [ "$i" == "all_posts.html" ]; then continue; fi if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
echo -n "." echo -n "."
# Title # Title
title="`awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i`" title="$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)"
echo -n '<li><a href="'$global_url/$i'">'$title'</a> &mdash;' >> $contentfile echo -n '<li><a href="'$global_url/$i'">'$title'</a> &mdash;' >> "$contentfile"
# Date # Date
date="`date -r $i +%B\ %d\,\ %Y`" date="$(date -r "$i" +%B\ %d\,\ %Y)"
echo " $date</li>" >> $contentfile echo " $date</li>" >> "$contentfile"
done done
echo "" echo ""
echo "</ul>" >> $contentfile echo "</ul>" >> "$contentfile"
echo '<div id="all_posts"><a href="'$global_url'">Back to the blog index</a></div>' >> $contentfile echo '<div id="all_posts"><a href="'$global_url'">'$template_archive_index_page'</a></div>' >> "$contentfile"
create_html_page $contentfile all_posts.html.tmp yes "$global_title &mdash; All posts" create_html_page "$contentfile" "$archive_index.tmp" yes "$global_title &mdash; All posts"
mv all_posts.html.tmp all_posts.html mv "$archive_index.tmp" "$archive_index"
chmod 644 all_posts.html chmod 644 "$archive_index"
rm $contentfile rm "$contentfile"
} }
# Generate the index.html with the content of the latest 10 posts # Generate the index.html with the content of the latest 10 posts
rebuild_index() { rebuild_index() {
echo -n "Rebuilding the index " echo -n "Rebuilding the index "
newindexfile="index.html.$RANDOM" newindexfile="$index_file.$RANDOM"
contentfile="$newindexfile.content" contentfile="$newindexfile.content"
while [ -f "$newindexfile" ]; do while [ -f "$newindexfile" ]; do
newindexfile="index.html.$RANDOM" newindexfile="$index_file.$RANDOM"
contentfile="$newindexfile.content" contentfile="$newindexfile.content"
done done
# Create the content file, maximum 10 entries # Create the content file, maximum 10 entries
n=0 n=0
for i in `ls -t *.html`; do # sort by date, newest first for i in $(ls -t *.html); do # sort by date, newest first
if [ "$i" == "index.html" ] || [ "$i" == "all_posts.html" ]; then continue; fi if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
if [ $n -ge 10 ]; then break; fi if [ "$n" -ge "$number_of_index_articles" ]; then break; fi
awk '/<!-- entry begin -->/, /<!-- entry end -->/' $i >> $contentfile awk '/<!-- entry begin -->/, /<!-- entry end -->/' "$i" >> "$contentfile"
echo -n "." echo -n "."
n=$(( $n + 1 )) n=$(( $n + 1 ))
done done
if [ "$global_feedburner" == "" ]; then if [ "$global_feedburner" == "" ]; then
echo '<div id="all_posts"><a href="all_posts.html">View more posts</a> &mdash; <a href="feed.rss">Subscribe</a></div>' >> $contentfile echo '<div id="all_posts"><a href="'$archive_index'">View more posts</a> &mdash; <a href="'$blog_feed'">'$template_subscribe'</a></div>' >> "$contentfile"
else else
echo '<div id="all_posts"><a href="all_posts.html">View more posts</a> &mdash; <a href="'$global_feedburner'">Susbcribe</a></div>' >> $contentfile echo '<div id="all_posts"><a href="'$archive_index'">'$template_archive'</a> &mdash; <a href="'$global_feedburner'">Susbcribe</a></div>' >> "$contentfile"
fi fi
echo "" echo ""
create_html_page $contentfile $newindexfile yes "$global_title" create_html_page "$contentfile" "$newindexfile" yes "$global_title"
rm $contentfile rm "$contentfile"
mv $newindexfile index.html mv "$newindexfile" "$index_file"
chmod 644 index.html chmod 644 "$index_file"
} }
# Displays a list of the posts # Displays a list of the posts
list_posts() { list_posts() {
lines="" lines=""
n=1 n=1
for i in `ls -t *.html`; do for i in $(ls -t *.html); do
if [ "$i" == "index.html" ] || [ "$i" == "all_posts.html" ]; then continue; fi if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
line="$n # `awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i` # `date -r $i +%B\ %d\,\ %Y`" line="$n # $(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i) # $(date -r $i +%B\ %d\,\ %Y)"
lines="${lines}""$line""\n" # Weird stuff needed for the newlines lines="${lines}""$line""\n" # Weird stuff needed for the newlines
n=$(( $n + 1 )) n=$(( $n + 1 ))
done done
echo -e $lines | column -t -s "#" echo -e "$lines" | column -t -s "#"
} }
# Generate the feed file # Generate the feed file
make_rss() { make_rss() {
echo -n "Making RSS " echo -n "Making RSS "
rssfile="feed.rss.$RANDOM" rssfile="$blog_feed.$RANDOM"
while [ -f "$rssfile" ]; do rssfile="feed.rss.$RANDOM"; done while [ -f "$rssfile" ]; do rssfile="$blog_feed.$RANDOM"; done
echo '<?xml version="1.0" encoding="UTF-8" ?>' >> $rssfile echo '<?xml version="1.0" encoding="UTF-8" ?>' >> "$rssfile"
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">' >> $rssfile echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">' >> "$rssfile"
echo '<channel><title>'$global_title'</title><link>'$global_url'</link>' >> $rssfile echo '<channel><title>'$global_title'</title><link>'$global_url'</link>' >> "$rssfile"
echo '<description>'$global_description'</description><language>en</language>' >> $rssfile echo '<description>'$global_description'</description><language>en</language>' >> "$rssfile"
echo '<lastBuildDate>'`date -R`'</lastBuildDate>' >> $rssfile echo '<lastBuildDate>'$(date -R)'</lastBuildDate>' >> "$rssfile"
echo '<pubDate>'`date -R`'</pubDate>' >> $rssfile echo '<pubDate>'$(date -R)'</pubDate>' >> "$rssfile"
echo '<atom:link href="'$global_url/feed.rss'" rel="self" type="application/rss+xml" />' >> $rssfile echo '<atom:link href="'$global_url/$blog_feed'" rel="self" type="application/rss+xml" />' >> "$rssfile"
n=0 n=0
for i in `ls -t *.html`; do for i in $(ls -t *.html); do
if [ "$i" == "index.html" ] || [ "$i" == "all_posts.html" ]; then continue; fi if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
if [ $n -ge 10 ]; then break; fi # max 10 items if [ "$n" -ge "$number_of_feed_articles" ]; then break; fi # max 10 items
echo -n "." echo -n "."
echo '<item><title>' >> $rssfile echo '<item><title>' >> "$rssfile"
echo "`awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i`" >> $rssfile echo "$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)" >> "$rssfile"
echo '</title><description><![CDATA[' >> $rssfile echo '</title><description><![CDATA[' >> "$rssfile"
echo "`awk '/<!-- text begin -->/, /<!-- entry end -->/{if (!/<!-- text begin -->/ && !/<!-- entry end -->/) print}' $i`" >> $rssfile echo "$(awk '/<!-- text begin -->/, /<!-- entry end -->/{if (!/<!-- text begin -->/ && !/<!-- entry end -->/) print}' $i)" >> "$rssfile"
echo "]]></description><link>$global_url/$i</link>" >> $rssfile echo "]]></description><link>$global_url/$i</link>" >> "$rssfile"
echo "<guid>$global_url/$i</guid>" >> $rssfile echo "<guid>$global_url/$i</guid>" >> "$rssfile"
echo "<dc:creator>$global_author</dc:creator>" >> $rssfile echo "<dc:creator>$global_author</dc:creator>" >> "$rssfile"
echo '<pubDate>'`date -r $i -R`'</pubDate></item>' >> $rssfile echo '<pubDate>'$(date -r "$i" -R)'</pubDate></item>' >> "$rssfile"
n=$(( $n + 1 )) n=$(( $n + 1 ))
done done
echo '</channel></rss>' >> $rssfile echo '</channel></rss>' >> "$rssfile"
echo "" echo ""
mv $rssfile feed.rss mv "$rssfile" "$blog_feed"
chmod 644 feed.rss chmod 644 "$blog_feed"
} }
# generate headers, footers, etc # generate headers, footers, etc
create_includes() { create_includes() {
echo '<h1 class="nomargin"><a class="ablack" href="'$global_url'">'$global_title'</a></h1>' > .title.html echo '<h1 class="nomargin"><a class="ablack" href="'$global_url'">'$global_title'</a></h1>' > ".title.html"
echo '<div id="description">'$global_description'</div>' >> .title.html echo '<div id="description">'$global_description'</div>' >> ".title.html"
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' > .header.html echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' > ".header.html"
echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>' >> .header.html echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>' >> ".header.html"
echo '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />' >> .header.html echo '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />' >> ".header.html"
echo '<link rel="stylesheet" href="main.css" type="text/css" />' >> .header.html echo '<link rel="stylesheet" href="main.css" type="text/css" />' >> ".header.html"
echo '<link rel="stylesheet" href="blog.css" type="text/css" />' >> .header.html echo '<link rel="stylesheet" href="blog.css" type="text/css" />' >> ".header.html"
if [ "$global_feedburner" == "" ]; then if [ "$global_feedburner" == "" ]; then
echo '<link rel="alternate" type="application/rss+xml" title="Blog entries" href="feed.rss" />' >> .header.html echo '<link rel="alternate" type="application/rss+xml" title="'$template_subscribe_browser_button'" href="'$blog_feed'" />' >> ".header.html"
else else
echo '<link rel="alternate" type="application/rss+xml" title="Blog entries" href="'$global_feedburner'" />' >> .header.html echo '<link rel="alternate" type="application/rss+xml" title="'$template_subscribe_browser_button'" href="'$global_feedburner'" />' >> ".header.html"
fi fi
protected_mail="$(echo "$global_email" | sed 's/@/\&#64;/g' | sed 's/\./\&#46;/g')"
echo '<div id="footer">'$global_license '<a href="'$global_author_url'">'$global_author'</a> &mdash; <a href="mailto:'$global_email'">'$global_email'</a></div>' >> .footer.html echo '<div id="footer">'$global_license '<a href="'$global_author_url'">'$global_author'</a> &mdash; <a href="mailto:'$protected_mail'">'$protected_mail'</a></div>' >> ".footer.html"
} }
# Delete the temporarily generated include files # Delete the temporarily generated include files
delete_includes() { delete_includes() {
rm .title.html .footer.html .header.html rm ".title.html" ".footer.html" ".header.html"
} }
# Create the css file from scratch # Create the css file from scratch
@ -477,172 +499,41 @@ create_css() {
# this function is modified if the user changes the blog.css file # this function is modified if the user changes the blog.css file
if [ ! -f "blog.css" ]; then if [ ! -f "blog.css" ]; then
# blog.css directives will be loaded after main.css and thus will prevail # blog.css directives will be loaded after main.css and thus will prevail
echo ' echo '#title{font-size: x-large;}
#title { a.ablack{color:black !important;}
font-size: x-large; li{margin-bottom:8px;}
} ul,ol{margin-left:24px;margin-right:24px;}
#all_posts{margin-top:24px;text-align:center;}
a.ablack { .subtitle{font-size:small;margin:12px 0px;}
color: black !important; .content p{margin-left:24px;margin-right:24px;}
} h1{margin-bottom:12px !important;}
#description{font-size:large;margin-bottom:12px;}
li { h3{margin-top:42px;margin-bottom:8px;}
margin-bottom: 8px; h4{margin-left:24px;margin-right:24px;}
} #twitter{line-height:20px;vertical-align:top;text-align:right;font-style:italic;color:#333;margin-top:24px;font-size:14px;}' > blog.css
ul, ol {
margin-left: 24px;
margin-right: 24px;
}
#all_posts {
margin-top: 24px;
text-align: center;
}
.subtitle {
font-size: small;
margin: 12px 0px;
}
.content p {
margin-left: 24px;
margin-right: 24px;
}
h1 {
margin-bottom: 12px !important;
}
#description {
font-size: large;
margin-bottom: 12px;
}
h3 {
margin-top: 42px;
margin-bottom: 8px;
}
h4 {
margin-left: 24px;
margin-right: 24px;
}
#twitter {
line-height: 20px;
vertical-align: top;
text-align: right;
font-style: italic;
color: #333;
margin-top: 24px;
font-size: 14px;
}
' > blog.css
fi fi
# This is the CSS file from my main page. Any other person would need it to run the blog # This is the CSS file from my main page. Any other person would need it to run the blog
# so it's attached here for convenience. # so it's attached here for convenience.
if [ `whoami` == "carlesfe" ] && [ ! -f main.css ]; then if [ "$(whoami)" == "carlesfe" ] && [ ! -f "main.css" ]; then
ln -s ../style.css main.css # XXX This is clearly machine-dependent, beware! ln -s "../style.css" "main.css" # XXX This is clearly machine-dependent, beware!
elif [ ! -f main.css ]; then elif [ ! -f "main.css" ]; then
echo ' echo 'body{font-family:Georgia,"Times New Roman",Times,serif;margin:0;padding:0;background-color:#F3F3F3;}
body { #divbodyholder{padding:5px;background-color:#DDD;width:874px;margin:24px auto;}
font-family: Georgia, "Times New Roman", Times, serif; #divbody{width:776px;border:solid 1px #ccc;background-color:#fff;padding:0px 48px 24px 48px;top:0;}
margin: 0; .headerholder{background-color:#f9f9f9;border-top:solid 1px #ccc;border-left:solid 1px #ccc;border-right:solid 1px #ccc;}
padding: 0; .header{width:800px;margin:0px auto;padding-top:24px;padding-bottom:8px;}
background-color: #F3F3F3; .content{margin-bottom:45px;}
} .nomargin{margin:0;}
.description{margin-top:10px;border-top:solid 1px #666;padding:10px 0;}
#divbodyholder { h3{font-size:20pt;width:100%;font-weight:bold;margin-top:32px;margin-bottom:0;}
padding: 5px; .clear{clear:both;}
background-color: #DDD; #footer{padding-top:10px;border-top:solid 1px #666;color:#333333;text-align:center;font-size:small;font-family:"Courier New","Courier",monospace;}
width: 874px; a{text-decoration:none;color:#003366 !important;}
margin: 24px auto; a:visited{text-decoration:none;color:#336699 !important;}
} blockquote{background-color:#f9f9f9;border-left:solid 4px #e9e9e9;margin-left:12px;padding:12px 12px 12px 24px;}
blockquote img{margin:12px 0px;}
#divbody { blockquote iframe{margin:12px 0px;}' > main.css
width: 776px;
border: solid 1px #ccc;
background-color: #fff;
padding: 0px 48px 24px 48px;
top: 0;
}
.headerholder {
background-color: #f9f9f9;
border-top: solid 1px #ccc;
border-left: solid 1px #ccc;
border-right: solid 1px #ccc;
}
.header {
width: 800px;
margin: 0px auto;
padding-top: 24px;
padding-bottom: 8px;
}
.content {
margin-bottom: 45px;
}
.nomargin {
margin: 0;
}
.description {
margin-top: 10px;
border-top: solid 1px #666;
padding: 10px 0;
}
h3 {
font-size: 20pt;
width: 100%;
font-weight: bold;
margin-top: 32px;
margin-bottom: 0;
}
.clear {
clear: both;
}
#footer {
padding-top: 10px;
border-top: solid 1px #666;
color: #333333;
text-align: center;
font-size: small;
font-family: Courier New, Courier, monospace;
}
a {
text-decoration: none;
color: #003366 !important;
}
a:visited {
text-decoration: none;
color: #336699 !important;
}
blockquote {
background-color: #f9f9f9;
border-left: solid 4px #e9e9e9;
margin-left: 12px;
padding: 12px 12px 12px 24px;
}
blockquote img {
margin: 12px 0px;
}
blockquote iframe {
margin: 12px 0px;
}
' > main.css
fi fi
} }
@ -652,25 +543,25 @@ rebuild_all_entries() {
echo -n "Rebuilding all entries " echo -n "Rebuilding all entries "
for i in *.html; do # no need to sort for i in *.html; do # no need to sort
if [ "$i" == "index.html" ] || [ "$i" == "all_posts.html" ]; then continue; fi if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
contentfile=".tmp.$RANDOM" contentfile=".tmp.$RANDOM"
while [ -f "$contentfile" ]; do contentfile=".tmp.$RANDOM"; done while [ -f "$contentfile" ]; do contentfile=".tmp.$RANDOM"; done
echo -n "." echo -n "."
# Get the title and entry, and rebuild the html structure from scratch (divs, title, description...) # Get the title and entry, and rebuild the html structure from scratch (divs, title, description...)
title="`awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i`" title="$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)"
awk '/<!-- text begin -->/, /<!-- text end -->/{if (!/<!-- text begin -->/ && !/<!-- text end -->/) print}' $i >> $contentfile awk '/<!-- text begin -->/, /<!-- text end -->/{if (!/<!-- text begin -->/ && !/<!-- text end -->/) print}' "$i" >> "$contentfile"
# Original post timestamp # Original post timestamp
timestamp="`date -r $i`" timestamp="$(date -r $i)"
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%k%M')"
mv $i.rebuilt $i mv "$i.rebuilt" "$i"
chmod 644 $i chmod 644 "$i"
touch -t $timestamp $i touch -t $timestamp "$i"
rm $contentfile rm "$contentfile"
done done
echo "" echo ""
} }
@ -697,7 +588,7 @@ reset() {
echo "Are you sure you want to delete all blog entries? Please write \"Yes, I am!\" " echo "Are you sure you want to delete all blog entries? Please write \"Yes, I am!\" "
read line read line
if [ "$line" == "Yes, I am!" ]; then if [ "$line" == "Yes, I am!" ]; then
rm *.html *.css *.rss rm "*.html" "*.css" "*.rss"
echo "Deleted all posts, stylesheets and feeds." echo "Deleted all posts, stylesheets and feeds."
else else
echo "Phew! You dodged a bullet there. Nothing was modified." echo "Phew! You dodged a bullet there. Nothing was modified."
@ -730,8 +621,8 @@ do_main() {
fi fi
# We're going to back up just in case # We're going to back up just in case
tar cfz .backup.tar.gz *.html tar cfz ".backup.tar.gz" *.html
chmod 600 .backup.tar.gz chmod 600 ".backup.tar.gz"
if [ "$1" == "reset" ]; then if [ "$1" == "reset" ]; then
reset reset