From 99fea81fcbf7bbdd902a33e0c4a9d492826fde80 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Tue, 18 Mar 2014 21:40:50 +0100 Subject: [PATCH 1/6] add tabstop to vim modeline --- bb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index c3b6383..1a68286 100755 --- a/bb.sh +++ b/bb.sh @@ -1066,4 +1066,4 @@ do_main() { # do_main $* -# vim: set shiftwidth=4 expandtab: +# vim: set shiftwidth=4 tabstop=4 expandtab: From 74537033f3f144f6360d338ecd99764b85f82f10 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Tue, 18 Mar 2014 22:17:34 +0100 Subject: [PATCH 2/6] bugfix: keep old page filename in the page's title link to itself pass proper filename through parse_file to create_html_page Bug was that when editing with "bb edit page.html" and changing title, regenerated page.html had

linking to newtitle.html (non-existing file) --- bb.sh | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/bb.sh b/bb.sh index 1a68286..9097a61 100755 --- a/bb.sh +++ b/bb.sh @@ -365,12 +365,12 @@ edit() { get_html_file_content 'text' 'text' <$1 | sed "s|\\1|\\1|g" >> "$TMPFILE" rm $1 $EDITOR "$TMPFILE" - parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file - rm "$TMPFILE" if [ "$2" = "keep" ]; then - mv $filename $1 - filename="$1" + parse_file "$TMPFILE" "$edit_timestamp" "$1" + else + parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file fi + rm "$TMPFILE" fi touch -t "$touch_timestamp" "$filename" chmod 644 "$filename" @@ -487,8 +487,12 @@ create_html_page() { # Parse the plain text file into an html file # -# $1 file name +# $1 source file name # $2 (optional) timestamp for the file +# $3 (optional) destination file name +# note that although timestamp is optional, something must be provided at its +# place if destination file name is provided, i.e: +# parse_file source.txt "" destination.html parse_file() { # Read for the title and check that the filename is ok title="" @@ -497,21 +501,25 @@ parse_file() { # set title and # remove extra

and

added by markdown 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" + if [ "$3" ]; then + filename=$3 + else + 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" - # Check for duplicate file names - while [ -f "$filename" ]; do - suffix="$RANDOM" - filename="$(echo $filename | sed 's/\.html/'$suffix'\.html/g')" - done + # Check for duplicate file names + while [ -f "$filename" ]; do + suffix="$RANDOM" + filename="$(echo $filename | sed 's/\.html/'$suffix'\.html/g')" + done + fi + content="$filename.tmp" # Parse possible tags elif [[ "$line" = "

$template_tags_line_header"* ]]; then tags="$(echo "$line" | cut -d ":" -f 2- | sed -e 's/<\/p>//g' -e 's/^ *//' -e 's/ *$//' -e 's/, /,/g')" From 1dea4161dac346a1f36c80dc18d25ad474132c71 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Tue, 18 Mar 2014 23:11:14 +0100 Subject: [PATCH 3/6] delete generated HTML file before generating new one, not at the bottom Bug was that when confirming "[E]dit again" by providing an empty string, the file wasn't deleted we could as well do if [ "$post_status" != "p" ] && [ "$post_status" != "P" ] but this way is IMO cleaner --- bb.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bb.sh b/bb.sh index 9097a61..bdafb17 100755 --- a/bb.sh +++ b/bb.sh @@ -584,7 +584,9 @@ EOF chmod 600 "$TMPFILE" post_status="E" + filename="" while [ "$post_status" != "p" ] && [ "$post_status" != "P" ]; do + [ "$filename" ] && rm "$filename" # Delete the generated html file, if any $EDITOR "$TMPFILE" if [[ "$fmt" == "md" ]]; then html_from_md="$(markdown "$TMPFILE")" @@ -622,9 +624,6 @@ EOF echo "Saved your draft as '$draft'" exit fi - if [[ "$post_status" == "e" ]] || [[ "$post_status" == "E" ]]; then - rm "$filename" # Delete the html file as it will be generated again - fi done rm "$TMPFILE" From 5cbeaa9ad83d6d7f090a56bdea5b0a6c29b9e1d1 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Tue, 18 Mar 2014 23:49:16 +0100 Subject: [PATCH 4/6] use expr to clean tags RegExp way --- bb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index bdafb17..0dda557 100755 --- a/bb.sh +++ b/bb.sh @@ -744,7 +744,7 @@ rebuild_tags() { # 'split' tags by commas echo "$line" | cut -c 10- | while IFS="," read -a tags; do for dirty_tag in "${tags[@]}"; do # extract html around it - tag="$(echo $dirty_tag | grep -o ">.*" | awk '{print substr($0, 2, length($0)-5)}' | tr " " "_")" + tag="$(expr "$dirty_tag" : ".*>\(.*\)> "$prefix_tags$tag".tmp.html done From daf456b9560be7a01cbc57b03fc800dfbad1a452 Mon Sep 17 00:00:00 2001 From: Aleksei Shpakovskii Date: Wed, 19 Mar 2014 18:02:15 +0100 Subject: [PATCH 5/6] Clean up tag links only in "Tags:" line The bug was that if you decide, for some reason, insert links to tag pages into text of your article, then after editing this article, the links were gone. That happened because "tag links cleaning" was too agressive (it was cleaning tags not only on tag line, but in the whole text) --- bb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index 0dda557..470b5e1 100755 --- a/bb.sh +++ b/bb.sh @@ -362,7 +362,7 @@ edit() { # Title echo "$(get_post_title $1)" > "$TMPFILE" # Post text with plaintext tags - get_html_file_content 'text' 'text' <$1 | sed "s|\\1|\\1|g" >> "$TMPFILE" + get_html_file_content 'text' 'text' <$1 | sed "/^

$template_tags_line_header/s|\\1|\\1|g" >> "$TMPFILE" rm $1 $EDITOR "$TMPFILE" if [ "$2" = "keep" ]; then From 22912381206ded2165a5de0a5ff7d9d073246155 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Wed, 19 Mar 2014 23:05:11 +0100 Subject: [PATCH 6/6] preserve backslashes when posting/editing ask "read" not to process backslash sequences when reading user-edited file and leave them as is, instead --- bb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index 470b5e1..cda88f9 100755 --- a/bb.sh +++ b/bb.sh @@ -496,7 +496,7 @@ create_html_page() { parse_file() { # Read for the title and check that the filename is ok title="" - while IFS='' read line; do + while IFS='' read -r line; do if [[ "$title" == "" ]]; then # set title and # remove extra

and

added by markdown