From 7e6816c391643afe1b91c4d4f25ff546ed64df9c Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 22 Mar 2014 15:14:01 +0100 Subject: save markdown file --- bb.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bb.sh b/bb.sh index cda88f9..4103996 100755 --- a/bb.sh +++ b/bb.sh @@ -167,6 +167,9 @@ global_variables() { # 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='
' + # save markdown file when posting with "bb post -m" + # possible values: "yes", "" + save_markdown="yes" # prefix for tags/categories files # please make sure that no other html file starts with this prefix prefix_tags="tag_" @@ -626,7 +629,11 @@ EOF fi done - rm "$TMPFILE" + if [[ "$fmt" == "md" && "$save_markdown" ]]; then + mv "$TMPFILE" "${filename%%.*}.md" + else + rm "$TMPFILE" + fi chmod 644 "$filename" echo "Posted $filename" } -- cgit v1.2.3 From f3fa14dc5a737bd0c0424e21e9dc1df1c2e20210 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 22 Mar 2014 15:45:56 +0100 Subject: edit markdown posts usage: bb.sh edit article.md to edit previously posted article (for which markdown source was saved), and repost it (under the same name or not) --- bb.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bb.sh b/bb.sh index 4103996..5d4aaa7 100755 --- a/bb.sh +++ b/bb.sh @@ -258,7 +258,7 @@ test_markdown() { # Parse a Markdown file into HTML and return the generated file markdown() { out="$(echo $1 | sed 's/md$/html/g')" - while [ -f "$out" ]; do out="$(echo $out | sed 's/\.html$/\.'$RANDOM'\.html')"; done + while [ -f "$out" ]; do out="$(echo $out | sed 's/\.html$/\.'$RANDOM'\.html/')"; done $markdown_bin $1 > $out echo $out } @@ -360,16 +360,24 @@ edit() { $EDITOR "$1" filename="$1" else - # Create the content file - TMPFILE="$(basename $1).$RANDOM.html" - # Title - echo "$(get_post_title $1)" > "$TMPFILE" - # Post text with plaintext tags - get_html_file_content 'text' 'text' <$1 | sed "/^

$template_tags_line_header/s|\\1|\\1|g" >> "$TMPFILE" - rm $1 - $EDITOR "$TMPFILE" + if [[ "${1##*.}" == "md" ]]; then + # editing markdown file + $EDITOR "$1" + TMPFILE="$(markdown "$1")" + filename="${1%%.*}.html" + else + # Create the content file + TMPFILE="$(basename $1).$RANDOM.html" + # Title + echo "$(get_post_title $1)" > "$TMPFILE" + # Post text with plaintext tags + get_html_file_content 'text' 'text' <$1 | sed "/^

$template_tags_line_header/s|\\1|\\1|g" >> "$TMPFILE" + $EDITOR "$TMPFILE" + filename="$1" + fi + rm "$filename" if [ "$2" = "keep" ]; then - parse_file "$TMPFILE" "$edit_timestamp" "$1" + parse_file "$TMPFILE" "$edit_timestamp" "$filename" else parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file fi -- cgit v1.2.3 From 49285d02b8298c7c34bdb97d32c73e4d6c6266ac Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sat, 22 Mar 2014 15:51:55 +0100 Subject: rename *.md file together with *.html if called like this: bb.sh edit -n posted.md then editing title will rename posted.html to reflect new title. Now it will rename posted.md, too --- bb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bb.sh b/bb.sh index 5d4aaa7..08c5baa 100755 --- a/bb.sh +++ b/bb.sh @@ -380,6 +380,7 @@ edit() { parse_file "$TMPFILE" "$edit_timestamp" "$filename" else parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file + [[ "${1##*.}" == "md" ]] && mv "$1" "${filename%%.*}.md" 2>/dev/null fi rm "$TMPFILE" fi -- cgit v1.2.3 From 599b5a4e58f939e541fc18d5f24f8f6af2351a21 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Sun, 23 Mar 2014 10:22:59 +0100 Subject: use *.html file timestamp, even when editing *.md file --- bb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bb.sh b/bb.sh index 08c5baa..7d7167e 100755 --- a/bb.sh +++ b/bb.sh @@ -354,8 +354,8 @@ get_html_file_content() { # leave empty for default behavior (edit only text part and change name) edit() { # Original post timestamp - edit_timestamp="$(LC_ALL=$date_locale date -r $1 +"%a, %d %b %Y %H:%M:%S %z" )" - touch_timestamp="$(LC_ALL=$date_locale date -r $1 +'%Y%m%d%H%M')" + edit_timestamp="$(LC_ALL=$date_locale date -r "${1%%.*}.html" +"%a, %d %b %Y %H:%M:%S %z" )" + touch_timestamp="$(LC_ALL=$date_locale date -r "${1%%.*}.html" +'%Y%m%d%H%M')" if [ "$2" = "full" ]; then $EDITOR "$1" filename="$1" -- cgit v1.2.3