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)
This commit is contained in:
parent
7e6816c391
commit
f3fa14dc5a
1 changed files with 18 additions and 10 deletions
28
bb.sh
28
bb.sh
|
@ -258,7 +258,7 @@ test_markdown() {
|
||||||
# Parse a Markdown file into HTML and return the generated file
|
# Parse a Markdown file into HTML and return the generated file
|
||||||
markdown() {
|
markdown() {
|
||||||
out="$(echo $1 | sed 's/md$/html/g')"
|
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
|
$markdown_bin $1 > $out
|
||||||
echo $out
|
echo $out
|
||||||
}
|
}
|
||||||
|
@ -360,16 +360,24 @@ edit() {
|
||||||
$EDITOR "$1"
|
$EDITOR "$1"
|
||||||
filename="$1"
|
filename="$1"
|
||||||
else
|
else
|
||||||
# Create the content file
|
if [[ "${1##*.}" == "md" ]]; then
|
||||||
TMPFILE="$(basename $1).$RANDOM.html"
|
# editing markdown file
|
||||||
# Title
|
$EDITOR "$1"
|
||||||
echo "$(get_post_title $1)" > "$TMPFILE"
|
TMPFILE="$(markdown "$1")"
|
||||||
# Post text with plaintext tags
|
filename="${1%%.*}.html"
|
||||||
get_html_file_content 'text' 'text' <$1 | sed "/^<p>$template_tags_line_header/s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >> "$TMPFILE"
|
else
|
||||||
rm $1
|
# Create the content file
|
||||||
$EDITOR "$TMPFILE"
|
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 "/^<p>$template_tags_line_header/s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >> "$TMPFILE"
|
||||||
|
$EDITOR "$TMPFILE"
|
||||||
|
filename="$1"
|
||||||
|
fi
|
||||||
|
rm "$filename"
|
||||||
if [ "$2" = "keep" ]; then
|
if [ "$2" = "keep" ]; then
|
||||||
parse_file "$TMPFILE" "$edit_timestamp" "$1"
|
parse_file "$TMPFILE" "$edit_timestamp" "$filename"
|
||||||
else
|
else
|
||||||
parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file
|
parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue