add options to bring back old behavior and keep old filename

This commit is contained in:
Alexey Shpakovsky 2014-03-01 14:34:52 +01:00 committed by Aleksei Shpakovskii
parent b365aec797
commit 773c5fa363

33
bb.sh
View File

@ -342,19 +342,32 @@ get_html_file_content() {
# Note that if you edit title then filename might also change # Note that if you edit title then filename might also change
# #
# $1 the file to edit # $1 the file to edit
# $2 (optional) edit mode:
# "keep" to keep old filename
# "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() { edit() {
edit_timestamp="$(date -r $1 +'%Y%m%d%H%M')" edit_timestamp="$(date -r $1 +'%Y%m%d%H%M')"
# Create the content file if [ "$2" = "full" ]; then
TMPFILE="$1.$RANDOM" $EDITOR "$1"
# Title filename="$1"
echo "$(get_post_title $1)" > "$TMPFILE" else
# Post text with plaintext tags # Create the content file
get_html_file_content 'text' 'text' <$1 | sed "s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >> "$TMPFILE" TMPFILE="$1.$RANDOM"
rm $1 # Title
$EDITOR "$TMPFILE" echo "$(get_post_title $1)" > "$TMPFILE"
parse_file "$TMPFILE" # this command sets $filename as the html processed file # Post text with plaintext tags
get_html_file_content 'text' 'text' <$1 | sed "s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >> "$TMPFILE"
rm $1
$EDITOR "$TMPFILE"
parse_file "$TMPFILE" # this command sets $filename as the html processed file
rm "$TMPFILE"
if [ "$2" = "keep" ]; then
mv $filename $1
filename="$1"
fi
fi
touch -t $edit_timestamp "$filename" touch -t $edit_timestamp "$filename"
rm "$TMPFILE"
chmod 644 "$filename" chmod 644 "$filename"
echo "Posted $filename" echo "Posted $filename"
} }