Revert commit: 7c2024e
This commit is contained in:
parent
c91ef91b06
commit
ea39d0d524
60
bb.sh
60
bb.sh
|
@ -81,15 +81,15 @@ global_variables() {
|
|||
blog_feed="feed.rss"
|
||||
number_of_feed_articles="10"
|
||||
# "cut" blog entry when putting it to index page. Leave blank for full articles in front page
|
||||
# i.e. include only up to first '<hr>', or '----' in rst
|
||||
# i.e. include only up to first '<hr>', or '----' in commonmark
|
||||
cut_do=""
|
||||
# When cutting, cut also tags? If "no", tags will appear in index page for cut articles
|
||||
cut_tags="yes"
|
||||
# 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='<hr ?\/?>'
|
||||
# save rst file when posting with "bb post -m". Leave blank to discard it.
|
||||
save_rst="yes"
|
||||
# save commonmark file when posting with "bb post -m". Leave blank to discard it.
|
||||
save_commonmark="yes"
|
||||
# prefix for tags/categories files
|
||||
# please make sure that no other html file starts with this prefix
|
||||
prefix_tags="tag_"
|
||||
|
@ -165,7 +165,7 @@ global_variables() {
|
|||
# pandoc location.
|
||||
pandoc_bin=$(which pandoc 2>/dev/null)
|
||||
# pandoc command
|
||||
pandoc_command="$pandoc_bin -f rst -t html"
|
||||
pandoc_command="$pandoc_bin -f commonmark -t html"
|
||||
# Markdown location. Trying to autodetect by default.
|
||||
# The invocation must support the signature 'markdown_bin in.md > out.html'
|
||||
#[[ -f Markdown.pl ]] && markdown_bin=./Markdown.pl || markdown_bin=$(which Markdown.pl 2>/dev/null || which markdown 2>/dev/null)
|
||||
|
@ -202,9 +202,9 @@ test_pandoc() {
|
|||
}
|
||||
|
||||
|
||||
# Parse a reStructuredText file into HTML and return the generated file
|
||||
rst() {
|
||||
out=${1%.rst}.html
|
||||
# Parse a Commonmark Markdown file into HTML and return the generated file
|
||||
commonmark() {
|
||||
out=${1%.md}.html
|
||||
while [[ -f $out ]]; do out=${out%.html}.$RANDOM.html; done
|
||||
$pandoc_command "$1" > "$out"
|
||||
echo "$out"
|
||||
|
@ -294,7 +294,7 @@ get_html_file_content() {
|
|||
# Please note that this function does not automatically republish anything, as
|
||||
# it is usually called from 'main'.
|
||||
#
|
||||
# Note that it edits HTML file, even if you wrote the post as reStructuredText originally
|
||||
# Note that it edits HTML file, even if you wrote the post as commonmark originally
|
||||
# Note that if you edit title then filename might also change
|
||||
#
|
||||
# $1 the file to edit
|
||||
|
@ -312,15 +312,15 @@ edit() {
|
|||
$EDITOR "$1"
|
||||
filename=$1
|
||||
else
|
||||
if [[ ${1##*.} == rst ]]; then
|
||||
if [[ ${1##*.} == md ]]; then
|
||||
test_pandoc
|
||||
if (($? != 0)); then
|
||||
echo "pandoc is not working, please edit HTML file directly."
|
||||
exit
|
||||
fi
|
||||
# editing reStructuredText file
|
||||
# editing commonmark file
|
||||
$EDITOR "$1"
|
||||
TMPFILE=$(rst "$1")
|
||||
TMPFILE=$(commonmark "$1")
|
||||
filename=${1%%.*}.html
|
||||
else
|
||||
# Create the content file
|
||||
|
@ -337,7 +337,7 @@ edit() {
|
|||
parse_file "$TMPFILE" "$edit_timestamp" "$filename"
|
||||
else
|
||||
parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file
|
||||
[[ ${1##*.} == rst ]] && mv "$1" "${filename%%.*}.rst" 2>/dev/null
|
||||
[[ ${1##*.} == md ]] && mv "$1" "${filename%%.*}.md" 2>/dev/null
|
||||
fi
|
||||
rm "$TMPFILE"
|
||||
fi
|
||||
|
@ -471,7 +471,7 @@ create_html_page() {
|
|||
if [[ $index == no ]]; then
|
||||
echo '<!-- entry begin -->' # marks the beginning of the whole post
|
||||
echo "<h3><a class=\"ablack\" href=\"$file_url\">"
|
||||
# remove possible <p>'s on the title because of reStructuredText conversion
|
||||
# remove possible <p>'s on the title because of commonmark markdown conversion
|
||||
title=${title//<p>/}
|
||||
title=${title//<\/p>/}
|
||||
echo "$title"
|
||||
|
@ -568,7 +568,7 @@ parse_file() {
|
|||
# Manages the creation of the text file and the parsing to html file
|
||||
# also the drafts
|
||||
write_entry() {
|
||||
test_pandoc && fmt=rst || fmt=html
|
||||
test_pandoc && fmt=md || fmt=html
|
||||
f=$2
|
||||
[[ $2 == -html ]] && fmt=html && f=$3
|
||||
|
||||
|
@ -581,11 +581,11 @@ write_entry() {
|
|||
fi
|
||||
# guess format from TMPFILE
|
||||
extension=${TMPFILE##*.}
|
||||
[[ $extension == rst || $extension == html ]] && fmt=$extension
|
||||
# but let user override it (`bb.sh post -html file.rst`)
|
||||
[[ $extension == md || $extension == html ]] && fmt=$extension
|
||||
# but let user override it (`bb.sh post -html file.md`)
|
||||
[[ $2 == -html ]] && fmt=html
|
||||
# Test if pandoc is working before re-posting a .rst file
|
||||
if [[ $extension == rst ]]; then
|
||||
# Test if pandoc is working before re-posting a .md file
|
||||
if [[ $extension == md ]]; then
|
||||
test_pandoc
|
||||
if (($? != 0)); then
|
||||
echo "pandoc is not working, please edit HTML file directly."
|
||||
|
@ -602,8 +602,8 @@ as you exit your editor.</p>
|
|||
|
||||
<p>$template_tags_line_header keep-this-tag-format, tags-are-optional, example</p>
|
||||
EOF
|
||||
[[ $fmt == rst ]] && cat << EOF >> "$TMPFILE"
|
||||
The rest of the text file is a **reStructuredText** blog post. The process will continue
|
||||
[[ $fmt == md ]] && cat << EOF >> "$TMPFILE"
|
||||
The rest of the text file is a **Commonmark Markdown** blog post. The process will continue
|
||||
as soon as you exit your editor.
|
||||
|
||||
$template_tags_line_header keep-this-tag-format, tags-are-optional, beware-with-underscores-in-markdown, example
|
||||
|
@ -616,10 +616,10 @@ EOF
|
|||
while [[ $post_status != "p" && $post_status != "P" ]]; do
|
||||
[[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any
|
||||
$EDITOR "$TMPFILE"
|
||||
if [[ $fmt == rst ]]; then
|
||||
html_from_rst=$(rst "$TMPFILE")
|
||||
parse_file "$html_from_rst"
|
||||
rm "$html_from_rst"
|
||||
if [[ $fmt == md ]]; then
|
||||
html_from_md=$(commonmark "$TMPFILE")
|
||||
parse_file "$html_from_md"
|
||||
rm "$html_from_md"
|
||||
else
|
||||
parse_file "$TMPFILE" # this command sets $filename as the html processed file
|
||||
fi
|
||||
|
@ -648,8 +648,8 @@ EOF
|
|||
fi
|
||||
done
|
||||
|
||||
if [[ $fmt == rst && -n $save_rst ]]; then
|
||||
mv "$TMPFILE" "${filename%%.*}.rst"
|
||||
if [[ $fmt == md && -n $save_commonmark ]]; then
|
||||
mv "$TMPFILE" "${filename%%.*}.md"
|
||||
else
|
||||
rm "$TMPFILE"
|
||||
fi
|
||||
|
@ -977,7 +977,7 @@ create_includes() {
|
|||
protected_mail=${global_email//@/@}
|
||||
protected_mail=${protected_mail//./.}
|
||||
echo "<div id=\"footer\">$global_license <a href=\"$global_author_url\">$global_author</a> — <a href=\"mailto:$protected_mail\">$protected_mail</a><br/>"
|
||||
echo 'Generated with <a href="https://git.disroot.org/PresGas/bashblog-unbound">bashblog-unbound</a>.</div>'
|
||||
echo 'Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>'
|
||||
} >> ".footer.html"
|
||||
fi
|
||||
}
|
||||
|
@ -1074,9 +1074,9 @@ usage() {
|
|||
echo ""
|
||||
echo "Commands:"
|
||||
echo " post [-html] [filename] insert a new blog post, or the filename of a draft to continue editing it"
|
||||
echo " it tries to use pandoc reStructuredText by default, and falls back to HTML if it's not available."
|
||||
echo " it tries to use pandoc commonmark markdown by default, and falls back to HTML if it's not available."
|
||||
echo " use '-html' to override it and edit the post as HTML even when pandoc is available"
|
||||
echo " edit [-n|-f] [filename] edit an already published .html or .rst file. **NEVER** edit manually a published .html file,"
|
||||
echo " edit [-n|-f] [filename] edit an already published .html or .md file. **NEVER** edit manually a published .html file,"
|
||||
echo " always use this function as it keeps internal data and rebuilds the blog"
|
||||
echo " use '-n' to give the file a new name, if title was changed"
|
||||
echo " use '-f' to edit full html file, instead of just text part (also preserves name)"
|
||||
|
@ -1161,7 +1161,7 @@ do_main() {
|
|||
|
||||
if [[ $1 == edit ]]; then
|
||||
if (($# < 2)) || [[ ! -f ${!#} ]]; then
|
||||
echo "Please enter a valid .rst or .html file to edit"
|
||||
echo "Please enter a valid .md or .html file to edit"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue