From b6f4e1e8923d1a7f6c908c05afce7915684765dc Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Wed, 26 Feb 2014 21:04:36 +0100 Subject: [PATCH 1/7] Move text and title extraction to separate functions --- bb.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index 2659346..69b1828 100755 --- a/bb.sh +++ b/bb.sh @@ -309,6 +309,11 @@ disqus_footer() { ' } +# Reads HTML file from stdin, prints its content to stdout +get_html_file_content() { + awk '//, //{if (!// && !//) print}' +} + # Edit an existing, published .html file while keeping its original timestamp # Please note that this function does not automatically republish anything, as # it is usually called from 'main'. @@ -847,7 +852,7 @@ rebuild_all_entries() { echo -n "." # Get the title and entry, and rebuild the html structure from scratch (divs, title, description...) title="$(get_post_title "$i")" - awk '//, //{if (!// && !//) print}' "$i" >> "$contentfile" + get_html_file_content <$i >> "$contentfile" # Original post timestamp timestamp="$(LC_ALL=$date_locale date -r $i +"%a, %d %b %Y %H:%M:%S %z" )" From c581392bd4d44c98cc9309560d14fdf7714aa33b Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Wed, 26 Feb 2014 22:21:51 +0100 Subject: [PATCH 2/7] use get_html_file_content while building index and RSS --- bb.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bb.sh b/bb.sh index 69b1828..35d46d4 100755 --- a/bb.sh +++ b/bb.sh @@ -310,8 +310,10 @@ disqus_footer() { } # Reads HTML file from stdin, prints its content to stdout +# $1 where to start ("text" or "entry") +# $2 where to stop ("text" or "entry") get_html_file_content() { - awk '//, //{if (!// && !//) print}' + awk '//, //{if (!// && !//) print}' } # Edit an existing, published .html file while keeping its original timestamp @@ -646,7 +648,7 @@ rebuild_index() { for i in $(ls -t *.html); do # sort by date, newest first is_boilerplate_file "$i" && continue; if [[ "$n" -ge "$number_of_index_articles" ]]; then break; fi - awk '//, //' "$i" >> "$contentfile" + get_html_file_content 'entry' 'entry' <$1 >> "$contentfile" echo -n "." n=$(( $n + 1 )) done @@ -745,8 +747,7 @@ make_rss() { echo '' >> "$rssfile" echo "$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)" >> "$rssfile" echo '> "$rssfile" - echo "$(awk '//, //{if (!// && !//) print}' $i)" >> "$rssfile" - + echo "$(get_html_file_content 'text' 'entry' <$i)" >> "$rssfile" echo "]]>$global_url/$i" >> "$rssfile" echo "$global_url/$i" >> "$rssfile" echo "$global_author" >> "$rssfile" @@ -852,7 +853,7 @@ rebuild_all_entries() { echo -n "." # Get the title and entry, and rebuild the html structure from scratch (divs, title, description...) title="$(get_post_title "$i")" - get_html_file_content <$i >> "$contentfile" + get_html_file_content 'text' 'text' <$i >> "$contentfile" # Original post timestamp timestamp="$(LC_ALL=$date_locale date -r $i +"%a, %d %b %Y %H:%M:%S %z" )" From 7e7d1a8688fa73db93566524907c8b0c93fbdfd1 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Wed, 26 Feb 2014 23:04:31 +0100 Subject: [PATCH 3/7] cut text (leave up to "") in index and RSS note that when requested to cut entry, it keeps stuff between text end and entry end, so twitter button will still find its way into RSS feed also fix indentation --- bb.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bb.sh b/bb.sh index 35d46d4..cffa105 100755 --- a/bb.sh +++ b/bb.sh @@ -310,10 +310,19 @@ disqus_footer() { } # Reads HTML file from stdin, prints its content to stdout -# $1 where to start ("text" or "entry") -# $2 where to stop ("text" or "entry") +# $1 where to start ("text" or "entry") +# $2 where to stop ("text" or "entry") +# $3 "cut" to remove text from to +# note that this does not remove comment itself, +# so you can see if text was cut or not get_html_file_content() { - awk '//, //{if (!// && !//) print}' + awk '//, //{ + if (!// && !//) print + if ("'$3'" == "cut" && //){ + if ("'$2'" == "text") exit # no need to read further + while (getline > 0 && !//) {} + } + }' } # Edit an existing, published .html file while keeping its original timestamp @@ -648,7 +657,7 @@ rebuild_index() { for i in $(ls -t *.html); do # sort by date, newest first is_boilerplate_file "$i" && continue; if [[ "$n" -ge "$number_of_index_articles" ]]; then break; fi - get_html_file_content 'entry' 'entry' <$1 >> "$contentfile" + get_html_file_content 'entry' 'entry' 'cut' <$i >> "$contentfile" echo -n "." n=$(( $n + 1 )) done @@ -747,7 +756,7 @@ make_rss() { echo '' >> "$rssfile" echo "$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)" >> "$rssfile" echo '> "$rssfile" - echo "$(get_html_file_content 'text' 'entry' <$i)" >> "$rssfile" + echo "$(get_html_file_content 'text' 'entry' 'cut' <$i)" >> "$rssfile" echo "]]>$global_url/$i" >> "$rssfile" echo "$global_url/$i" >> "$rssfile" echo "$global_author" >> "$rssfile" From cf6bdb027b461cca071212e7bb7e5f188a9d7a89 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Wed, 26 Feb 2014 23:22:26 +0100 Subject: [PATCH 4/7] "Read more..." link for articles which were cut --- bb.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index cffa105..5d92e74 100755 --- a/bb.sh +++ b/bb.sh @@ -175,6 +175,8 @@ global_variables() { # Localization and i18n # "Comments?" (used in twitter link after every post) template_comments="Comments?" + # "Read more..." (link under cut article on index page) + template_read_more="Read more..." # "View more posts" (used on bottom of index page as link to archive) template_archive="View more posts" # "All posts" (title of archive page) @@ -657,7 +659,7 @@ rebuild_index() { for i in $(ls -t *.html); do # sort by date, newest first is_boilerplate_file "$i" && continue; if [[ "$n" -ge "$number_of_index_articles" ]]; then break; fi - get_html_file_content 'entry' 'entry' 'cut' <$i >> "$contentfile" + get_html_file_content 'entry' 'entry' 'cut' <$i | sed "s|<.-- text cut -->|

$template_read_more

|" >> "$contentfile" echo -n "." n=$(( $n + 1 )) done From ff36737c128d838109798b50312f692ec75cd263 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Thu, 27 Feb 2014 22:01:01 +0100 Subject: [PATCH 5/7] get_post_title in make_rss(), too --- bb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index 5d92e74..39d7c2e 100755 --- a/bb.sh +++ b/bb.sh @@ -756,7 +756,7 @@ make_rss() { [[ "$n" -ge "$number_of_feed_articles" ]] && break # max 10 items echo -n "." echo '' >> "$rssfile" - echo "$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)" >> "$rssfile" + echo "$(get_post_title "$i")" >> "$rssfile" echo '> "$rssfile" echo "$(get_html_file_content 'text' 'entry' 'cut' <$i)" >> "$rssfile" echo "]]>$global_url/$i" >> "$rssfile" From 652e5f8053f5e00875f10fdf0757b106a4504b0a Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Thu, 27 Feb 2014 22:40:11 +0100 Subject: [PATCH 6/7] make cut_line confugurable --- bb.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bb.sh b/bb.sh index 39d7c2e..2176108 100755 --- a/bb.sh +++ b/bb.sh @@ -160,6 +160,9 @@ global_variables() { # feed file (rss in this case) blog_feed="feed.rss" number_of_feed_articles="10" + # Regexp matching the HTML line where to do the cut + # note that slash is regexp separator so you need to prepend it with backslash + cut_line='
' # prefix for tags/categories files # please make sure that no other html file starts with this prefix prefix_tags="tag_" @@ -314,13 +317,13 @@ disqus_footer() { # Reads HTML file from stdin, prints its content to stdout # $1 where to start ("text" or "entry") # $2 where to stop ("text" or "entry") -# $3 "cut" to remove text from to -# note that this does not remove comment itself, +# $3 "cut" to remove text from
to +# note that this does not remove
line itself, # so you can see if text was cut or not get_html_file_content() { awk '//, //{ if (!// && !//) print - if ("'$3'" == "cut" && //){ + if ("'$3'" == "cut" && /'"$cut_line"'/){ if ("'$2'" == "text") exit # no need to read further while (getline > 0 && !//) {} } @@ -659,7 +662,7 @@ rebuild_index() { for i in $(ls -t *.html); do # sort by date, newest first is_boilerplate_file "$i" && continue; if [[ "$n" -ge "$number_of_index_articles" ]]; then break; fi - get_html_file_content 'entry' 'entry' 'cut' <$i | sed "s|<.-- text cut -->|

$template_read_more

|" >> "$contentfile" + get_html_file_content 'entry' 'entry' 'cut' <$i | awk '/'"$cut_line"'/ { print "

'"$template_read_more"'

" ; next } 1' >> "$contentfile" echo -n "." n=$(( $n + 1 )) done From 8f5c7b4a2757cdccabe9796a014748e4d2df0417 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Thu, 27 Feb 2014 22:53:00 +0100 Subject: [PATCH 7/7] make cutting optional --- bb.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bb.sh b/bb.sh index 2176108..96d410a 100755 --- a/bb.sh +++ b/bb.sh @@ -160,6 +160,10 @@ global_variables() { # feed file (rss in this case) blog_feed="feed.rss" number_of_feed_articles="10" + # "cut" blog entry when putting it to index page + # i.e. include only up to first
(---- in markdown) + # possible values: "cut", "" + cut_do="cut" # Regexp matching the HTML line where to do the cut # note that slash is regexp separator so you need to prepend it with backslash cut_line='
' @@ -662,7 +666,11 @@ rebuild_index() { for i in $(ls -t *.html); do # sort by date, newest first is_boilerplate_file "$i" && continue; if [[ "$n" -ge "$number_of_index_articles" ]]; then break; fi - get_html_file_content 'entry' 'entry' 'cut' <$i | awk '/'"$cut_line"'/ { print "

'"$template_read_more"'

" ; next } 1' >> "$contentfile" + if [ "$cut_do" ]; then + get_html_file_content 'entry' 'entry' 'cut' <$i | awk '/'"$cut_line"'/ { print "

'"$template_read_more"'

" ; next } 1' >> "$contentfile" + else + get_html_file_content 'entry' 'entry' <$i >> "$contentfile" + fi echo -n "." n=$(( $n + 1 )) done @@ -761,7 +769,7 @@ make_rss() { echo '' >> "$rssfile" echo "$(get_post_title "$i")" >> "$rssfile" echo '> "$rssfile" - echo "$(get_html_file_content 'text' 'entry' 'cut' <$i)" >> "$rssfile" + echo "$(get_html_file_content 'text' 'entry' $cut_do <$i)" >> "$rssfile" echo "]]>$global_url/$i" >> "$rssfile" echo "$global_url/$i" >> "$rssfile" echo "$global_author" >> "$rssfile"