From 1f4d3dd2bf33aaf56f203e92b62914e694fca98f Mon Sep 17 00:00:00 2001 From: Bart Date: Wed, 13 Apr 2016 01:19:30 +0200 Subject: [PATCH 1/5] Added support for images and made author field optional One LOC per feature, hope you think it's worth it. http://imgur.com/YcBp29ql.png --- bb.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index 0bac792..2153ba9 100755 --- a/bb.sh +++ b/bb.sh @@ -438,7 +438,8 @@ create_html_page() { else echo "
$(LC_ALL=$date_locale date +"$date_format" --date="$timestamp") — " fi - echo "$author
" + [[ -n $author ]] && echo " — $author" + echo "" echo '' # This marks the text body, after the title, date... fi cat "$content" # Actual content @@ -951,6 +952,7 @@ create_css() { #description{font-size:large;margin-bottom:12px;} h3{margin-top:42px;margin-bottom:8px;} h4{margin-left:24px;margin-right:24px;} + img{max-width:100%;} #twitter{line-height:20px;vertical-align:top;text-align:right;font-style:italic;color:#333;margin-top:24px;font-size:14px;}' > blog.css fi From 09fa5532332dad897f93fda1125cc7f9e2e6e411 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Mon, 25 Apr 2016 21:14:24 +0200 Subject: [PATCH 2/5] avoid the user mistakingly using 'edit ' instead of 'post ' --- bb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bb.sh b/bb.sh index 2153ba9..de9d659 100755 --- a/bb.sh +++ b/bb.sh @@ -266,6 +266,7 @@ get_html_file_content() { # leave empty for default behavior (edit only text part and change name) edit() { # Original post timestamp + [[ ! -f "${1%%.*}.html" ]] && echo "Can't edit post "${1%%.*}.html", did you mean to use \"bb.sh post \"?" && exit -1 edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"%a, %d %b %Y %H:%M:%S %z" ) touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +'%Y%m%d%H%M') tags_before=$(tags_in_post "${1%%.*}.html") From a08f47bb695561c70970f3876e59ae84c9c657c6 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Tue, 26 Apr 2016 16:16:35 +0200 Subject: [PATCH 3/5] Store post dates in html comment. Sync those with filesystem. Closes #96 --- README.md | 2 ++ bb.sh | 50 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0c22047..ab28c63 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ As a guideline, pull requests should: Changelog --------- +- 2.7 Store post date on a comment in the html file (#96). + On rebuild, the post date will be synchronised between comment date and file date, with precedence for comment date. - 2.6 Support for multiple authors, use a different `.config` for each one - 2.5 Massive code cleanup by Martijn Dekker
'tags' command
diff --git a/bb.sh b/bb.sh index de9d659..ce07dcf 100755 --- a/bb.sh +++ b/bb.sh @@ -17,7 +17,7 @@ global_config=".config" # by the 'global_config' file contents global_variables() { global_software_name="BashBlog" - global_software_version="2.6" + global_software_version="2.7" # Blog title global_title="My fancy blog" @@ -124,10 +124,14 @@ global_variables() { template_twitter_button="Tweet" template_twitter_comment="<Type your comment here but please leave the URL so that other people can follow the comments>" - # The locale to use for the dates displayed on screen (not for the timestamps) + # The locale to use for the dates displayed on screen date_format="%B %d, %Y" - date_allposts_header="%B %Y" date_locale="C" + date_inpost="bashblog_timestamp" + # Don't change these dates + date_format_full="%a, %d %b %Y %H:%M:%S %z" + date_format_timestamp="%Y%m%d%H%M.%S" + date_allposts_header="%B %Y" # Perform the post title -> filename conversion # Experts only. You may need to tune the locales too @@ -265,10 +269,10 @@ get_html_file_content() { # "full" to edit full HTML, and not only text part (keeps old filename) # leave empty for default behavior (edit only text part and change name) edit() { - # Original post timestamp [[ ! -f "${1%%.*}.html" ]] && echo "Can't edit post "${1%%.*}.html", did you mean to use \"bb.sh post \"?" && exit -1 - edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"%a, %d %b %Y %H:%M:%S %z" ) - touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +'%Y%m%d%H%M') + # Original post timestamp + edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_full" ) + touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_timestamp") tags_before=$(tags_in_post "${1%%.*}.html") if [[ $2 == full ]]; then $EDITOR "$1" @@ -304,6 +308,7 @@ edit() { rm "$TMPFILE" fi touch -t "$touch_timestamp" "$filename" + touch -t "$touch_timestamp" "$1" chmod 644 "$filename" echo "Posted $filename" tags_after=$(tags_in_post "$filename") @@ -435,11 +440,16 @@ create_html_page() { echo "$title" echo '' if [[ -z $timestamp ]]; then - echo "
$(LC_ALL=$date_locale date +"$date_format") — " + echo "" else - echo "
$(LC_ALL=$date_locale date +"$date_format" --date="$timestamp") — " + echo "" fi - [[ -n $author ]] && echo " — $author" + if [[ -z $timestamp ]]; then + echo -n "
$(LC_ALL=$date_locale date +"$date_format")" + else + echo -n "
$(LC_ALL=$date_locale date +"$date_format" --date="$timestamp")" + fi + [[ -n $author ]] && echo -e " — \n$author" echo "
" echo '' # This marks the text body, after the title, date... fi @@ -864,7 +874,7 @@ make_rss() { while [[ -f $rssfile ]]; do rssfile=$blog_feed.$RANDOM; done { - pubdate=$(LC_ALL=C date +"%a, %d %b %Y %H:%M:%S %z") + pubdate=$(LC_ALL=C date +"$date_format_full") echo '' echo '' echo "$global_title$global_url/$index_file" @@ -885,7 +895,7 @@ make_rss() { echo "]]>$global_url/${i#./}" echo "$global_url/$i" echo "$(get_post_author "$i")" - echo "$(LC_ALL=C date -r "$i" +"%a, %d %b %Y %H:%M:%S %z")" + echo "$(LC_ALL=C date -r "$i" +"$date_format_full")" n=$(( n + 1 )) done < <(ls -t ./*.html) @@ -987,7 +997,7 @@ create_css() { rebuild_all_entries() { echo -n "Rebuilding all entries " - for i in ./*.html; do # no need to sort + for i in ./*.html; do is_boilerplate_file "$i" && continue; contentfile=.tmp.$RANDOM while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done @@ -998,12 +1008,20 @@ rebuild_all_entries() { get_html_file_content 'text' 'text' <"$i" >> "$contentfile" - # Original post timestamp - timestamp=$(LC_ALL=C date -r "$i" +"%a, %d %b %Y %H:%M:%S %z" ) + # Read timestamp from post, if present, and sync file timestamp + timestamp=$(awk '// { print }' "$i" | cut -d '#' -f 2) + if [[ -n $timestamp ]]; then + echo "$i" timestamp present $timestamp + # Convert to timestamp for touch + touch -t "$timestamp" "$i" + fi + # Read timestamp from file in correct format for 'create_html_page' + timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full") + echo "$i" now reading $timestamp create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")" # keep the original timestamp! - timestamp=$(LC_ALL=C date -r "$i" +'%Y%m%d%H%M') + timestamp=$(LC_ALL=C date -r "$i" +"$date_format_timestamp") mv "$i.rebuilt" "$i" chmod 644 "$i" touch -t "$timestamp" "$i" @@ -1067,7 +1085,7 @@ date_version_detect() { stat -f "%Sm" -t "$format" "$2" elif [[ $2 == --date* ]]; then # convert between dates using BSD date syntax - command date -j -f "%a, %d %b %Y %H:%M:%S %z" "${2#--date=}" "$1" + command date -j -f "$date_format_full" "${2#--date=}" "$1" else # acceptable format for BSD date command date -j "$@" From 2b8b02ac58e713980db2b762c77b4bfd4021a48d Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Tue, 26 Apr 2016 16:29:25 +0200 Subject: [PATCH 4/5] simplified a couple commands and removed debug echos --- bb.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bb.sh b/bb.sh index ce07dcf..14c1b5b 100755 --- a/bb.sh +++ b/bb.sh @@ -1010,14 +1010,9 @@ rebuild_all_entries() { # Read timestamp from post, if present, and sync file timestamp timestamp=$(awk '// { print }' "$i" | cut -d '#' -f 2) - if [[ -n $timestamp ]]; then - echo "$i" timestamp present $timestamp - # Convert to timestamp for touch - touch -t "$timestamp" "$i" - fi + [[ -n $timestamp ]] && touch -t "$timestamp" "$i" # Read timestamp from file in correct format for 'create_html_page' timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full") - echo "$i" now reading $timestamp create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")" # keep the original timestamp! From a36566a90cef64e18eabc693ca27eb4c12d775cd Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Tue, 26 Apr 2016 16:48:24 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab28c63..8a5e362 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,14 @@ I created it because I wanted a very, very simple way to post entries to a blog *How simple? Just type `./bb.sh post` and start writing your blogpost.* -You can see it live here: [read the initial blog post](https://web.archive.org/web/20130520204024/http://mmb.pcb.ub.es/~carlesfe/blog/creating-a-simple-blog-system-with-a-500-line-bash-script.html). That page was 100% generated using bashblog, no additional tweaking. +[![asciinema](https://asciinema.org/a/4nr44km9ipow4s7u2w2eabeik.png)](https://asciinema.org/a/4nr44km9ipow4s7u2w2eabeik) + +You can see a sample here: [read the initial blog post](https://web.archive.org/web/20130520204024/http://mmb.pcb.ub.es/~carlesfe/blog/creating-a-simple-blog-system-with-a-500-line-bash-script.html). That page was 100% generated using bashblog, no additional tweaking. [![demo](https://raw.githubusercontent.com/cfenollosa/bashblog/gh-pages/images/demo_thumb.png)](https://raw.githubusercontent.com/cfenollosa/bashblog/gh-pages/images/demo.png) +Check out [other bashblog users](https://www.google.com/search?q=%22Generated+with+bashblog,+a+single+bash+script+to+easily+create+blogs+like+this+one%22) + Usage -----