From abf6101439fef07c0ae2260f9a8f6930fe620bad Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 16:05:25 +0100 Subject: [PATCH 1/7] Make inclusion of CSS files configurable --- bb.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bb.sh b/bb.sh index 05cd414..0fdfb26 100755 --- a/bb.sh +++ b/bb.sh @@ -178,6 +178,8 @@ global_variables() { # extra content to add just after we open the tag # and before the actual blog content body_begin_file="" + # CSS files to include on every page + css_include=('main.css' 'blog.css') # Localization and i18n # "Comments?" (used in twitter link after every post) @@ -817,8 +819,9 @@ create_includes() { echo '' > ".header.html" echo '' >> ".header.html" echo '' >> ".header.html" - echo '' >> ".header.html" - echo '' >> ".header.html" + for css_file in ${css_include[*]}; do + echo '' >> ".header.html" + done if [[ "$global_feedburner" == "" ]]; then echo '' >> ".header.html" else From 0fc7058ae76f1eb97bd4d8f22e512e17600cdf7f Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 16:22:28 +0100 Subject: [PATCH 2/7] make CSS generation optional --- bb.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bb.sh b/bb.sh index 0fdfb26..8a147e8 100755 --- a/bb.sh +++ b/bb.sh @@ -178,8 +178,9 @@ global_variables() { # extra content to add just after we open the tag # and before the actual blog content body_begin_file="" - # CSS files to include on every page - css_include=('main.css' 'blog.css') + # CSS files to include on every page, f.ex. css_include=('main.css' 'blog.css') + # leave empty to use generated + css_include=() # Localization and i18n # "Comments?" (used in twitter link after every post) @@ -846,6 +847,7 @@ delete_includes() { create_css() { # To avoid overwriting manual changes. However it is recommended that # this function is modified if the user changes the blog.css file + [ $css_include ] && return || css_include=('main.css' 'blog.css') if [[ ! -f "blog.css" ]]; then # blog.css directives will be loaded after main.css and thus will prevail echo '#title{font-size: x-large;} @@ -1023,8 +1025,8 @@ do_main() { [[ "$1" == "reset" ]] && reset && exit - create_includes create_css + create_includes [[ "$1" == "post" ]] && write_entry "$@" [[ "$1" == "rebuild" ]] && rebuild_all_entries [[ "$1" == "delete" ]] && rm "$2" &> /dev/null From a8b9b0280123066e0acc7879a6db41a413feb8c7 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 16:35:00 +0100 Subject: [PATCH 3/7] add vim modeline --- bb.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bb.sh b/bb.sh index 8a147e8..0779812 100755 --- a/bb.sh +++ b/bb.sh @@ -1053,3 +1053,5 @@ do_main() { # Do not change anything here. If you want to modify the code, edit do_main() # do_main $* + +# vim: set shiftwidth=4 expandtab: From b861d25a3a477772d22cc741ddf290d2c1cf20f1 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 17:37:57 +0100 Subject: [PATCH 4/7] Keep first backup of this day it holds the version of the blog which was here "today in the morning". this is useful for those who, like me, first do "bb.sh rebuild" few times before realizing "oh damn I screwed up everything". Note: you are not expected to screw up on midnight. --- bb.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bb.sh b/bb.sh index 0779812..bd4f7b7 100755 --- a/bb.sh +++ b/bb.sh @@ -1022,6 +1022,10 @@ do_main() { tar cfz ".backup.tar.gz" *.html && chmod 600 ".backup.tar.gz" + # Keep first backup of this day containing yesterday's version of the blog + [ "$(date -r .yesterday.tar.gz +'%d')" != "$(date +'%d')" ] && + cp .backup.tar.gz .yesterday.tar.gz &> /dev/null + [[ "$1" == "reset" ]] && reset && exit From 52f974c606edff7caeec5c70d6cda1f5674cc1f5 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 22:24:30 +0100 Subject: [PATCH 5/7] Make filename generation routine play nice with Russian and Unix --- bb.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bb.sh b/bb.sh index bd4f7b7..b6bfe1b 100755 --- a/bb.sh +++ b/bb.sh @@ -499,7 +499,11 @@ parse_file() { title=$(echo "$line" | sed 's/<\/*p>//g') filename="$(echo $title | tr [:upper:] [:lower:])" filename="$(echo $filename | sed 's/\ /-/g')" + filename="$(echo $filename | sed 'y/йцукенгшщзхъфывапролджэячсмитьбю/jcukengsszh-fyvaproldzeahsmit-by/')" + filename="$(echo $filename | sed 'y/ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ/jcukengsszh-fyvaproldzeahsmit-by/')" filename="$(echo $filename | tr -dc '[:alnum:]-')" # html likes alphanumeric + filename="$(echo $filename | sed 's/^-*//')" # unix utilities are unhappy if filename starts with - + [ "$filename" ] || filename=$RANDOM # if filename gets empty, put something in it filename="$filename.html" content="$filename.tmp" From eef08c1984dafb8d292925d3ab56464e9f12e2b1 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 1 Mar 2014 23:01:47 +0100 Subject: [PATCH 6/7] cut on tag pages, too --- bb.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bb.sh b/bb.sh index b6bfe1b..981358a 100755 --- a/bb.sh +++ b/bb.sh @@ -666,7 +666,7 @@ all_tags() { echo "
    " >> "$contentfile" for i in $(ls $prefix_tags*.html); do echo -n "." - nposts="$(grep -c "^<\!-- entry begin -->$" $i)" + nposts="$(grep -c "<\!-- text begin -->" $i)" tagname="$(echo $i | cut -c $((${#prefix_tags}+1))- | sed 's/\.html//g')" echo "
  • $tagname — $nposts $template_tags_posts
  • " >> "$contentfile" done @@ -720,14 +720,18 @@ rebuild_index() { rebuild_tags() { echo -n "Rebuilding tag pages " n=0 - rm $prefix_tags*.tmp.html &> /dev/null + rm $prefix_tags*.html &> /dev/null # First we will process all files and create temporal tag files # with just the content of the posts for i in $(ls -t *.html); do is_boilerplate_file "$i" && continue; echo -n "." tmpfile="$(mktemp tmp.XXX)" - awk '//, //' "$i" >> "$tmpfile" + if [ "$cut_do" ]; then + get_html_file_content 'entry' 'entry' 'cut' <$i | awk '/'"$cut_line"'/ { print "

    '"$template_read_more"'

    " ; next } 1' >> "$tmpfile" + else + get_html_file_content 'entry' 'entry' <$i >> "$tmpfile" + fi while read line; do if [[ "$line" = "

    $template_tags_line_header"* ]]; then # 'split' tags by commas @@ -739,7 +743,7 @@ rebuild_tags() { done done fi - done < "$tmpfile" + done < "$i" rm "$tmpfile" done # Now generate the tag files with headers, footers, etc From 132b51714b02820c5b5fe1f42037780f128ec084 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sun, 9 Mar 2014 16:47:32 +0100 Subject: [PATCH 7/7] Preserve line indentation in HTML file while rebuilding it --- bb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bb.sh b/bb.sh index 981358a..c3b6383 100755 --- a/bb.sh +++ b/bb.sh @@ -492,7 +492,7 @@ create_html_page() { parse_file() { # Read for the title and check that the filename is ok title="" - while read line; do + while IFS='' read line; do if [[ "$title" == "" ]]; then # set title and # remove extra

    and

    added by markdown @@ -732,7 +732,7 @@ rebuild_tags() { else get_html_file_content 'entry' 'entry' <$i >> "$tmpfile" fi - while read line; do + while IFS='' read line; do if [[ "$line" = "

    $template_tags_line_header"* ]]; then # 'split' tags by commas echo "$line" | cut -c 10- | while IFS="," read -a tags; do