diff --git a/lib/all_posts.sh b/lib/all_posts.sh index 20a4a0c..234f2e3 100644 --- a/lib/all_posts.sh +++ b/lib/all_posts.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash # Create an index page with all the posts +declare archive_index +declare template_archive_index_page +declare template_archive_title +declare date_allposts_header +declare date_format +declare date_locale +declare index_file +declare global_title +declare global_author all_posts() { - declare archive_index - declare template_archive_index_page - declare template_archive_title - declare date_allposts_header - declare date_format - declare date_locale - declare index_file - declare global_title - declare global_author echo -n "Creating an index page with all the posts " contentfile=$archive_index.$RANDOM while [[ -f $contentfile ]]; do diff --git a/lib/all_tags.sh b/lib/all_tags.sh index 0090c17..7d72710 100644 --- a/lib/all_tags.sh +++ b/lib/all_tags.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash # Create an index page with all the tags +declare tags_index +declare template_tags_posts +declare template_tags_posts_singular +declare template_tags_posts_2_4 +declare template_tags_title +declare prefix_tags +declare index_file +declare template_archive_index_page +declare global_author +declare global_title all_tags() { - declare tags_index - declare template_tags_posts - declare template_tags_posts_singular - declare template_tags_posts_2_4 - declare template_tags_title - declare prefix_tags - declare index_file - declare template_archive_index_page - declare global_author - declare global_title echo -n "Creating an index page with all the tags " contentfile=$tags_index.$RANDOM while [[ -f $contentfile ]]; do diff --git a/lib/create_html_page.sh b/lib/create_html_page.sh index 51759bd..11d8ee8 100644 --- a/lib/create_html_page.sh +++ b/lib/create_html_page.sh @@ -12,14 +12,14 @@ # $4 title for the html header # $5 original blog timestamp # $6 post author +declare body_begin_file +declare date_inpost +declare date_locale +declare date_format +declare date_format_timestamp +declare global_url +declare body_end_file create_html_page() { - declare body_begin_file - declare date_inpost - declare date_locale - declare date_format - declare date_format_timestamp - declare global_url - declare body_end_file content=$1 filename=$2 index=$3 diff --git a/lib/create_includes.sh b/lib/create_includes.sh index 6c2dceb..afd275a 100644 --- a/lib/create_includes.sh +++ b/lib/create_includes.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash # generate headers, footers, etc +declare global_author +declare global_author_url +declare global_description +declare global_email +declare global_feedburner +declare global_license +declare global_title +declare global_url +declare index_file +declare header_file +declare css_include +declare template_subscribe_browser_button +declare blog_feed +declare footer_file create_includes() { - declare global_author - declare global_author_url - declare global_description - declare global_email - declare global_feedburner - declare global_license - declare global_title - declare global_url - declare index_file - declare header_file - declare css_include - declare template_subscribe_browser_button - declare blog_feed - declare footer_file { echo "

$global_title

" echo "
$global_description
" diff --git a/lib/date_version_detect.sh b/lib/date_version_detect.sh index 382fef3..91e5c85 100644 --- a/lib/date_version_detect.sh +++ b/lib/date_version_detect.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # Detects if GNU date is installed +declare date_format_full date_version_detect() { - declare date_format_full if ! stat -c"%U" /dev/null >/dev/null 2>&1 ; then # BSD environment if command -v gdate >/dev/null 2>&1 ; then diff --git a/lib/do_main.sh b/lib/do_main.sh index ebbc9d5..b9f592d 100644 --- a/lib/do_main.sh +++ b/lib/do_main.sh @@ -37,19 +37,19 @@ do_main() { if [[ $1 == edit ]]; then if (($# < 2)) || [[ ! -f ${!#} ]]; then - echo "Please enter a valid .md or .html file to edit" + echo "Please enter a valid .md file to edit" exit fi fi # Test for existing html files - if ls ./*.html &> /dev/null; then + if ls ./*.md &> /dev/null; then # We're going to back up just in case tar -c -z -f ".backup.tar.gz" -- *.html && - chmod 600 ".backup.tar.gz" - elif [[ $1 == rebuild ]]; then - echo "Can't find any html files, nothing to rebuild" - return + chmod 600 ".backup.tar.gz" + elif [[ $1 == rebuild ]]; then + echo "Can't find any html files, nothing to rebuild" + return fi # Keep first backup of this day containing yesterday's version of the blog diff --git a/lib/get_post_title.sh b/lib/get_post_title.sh index 5a7b5b4..7744155 100644 --- a/lib/get_post_title.sh +++ b/lib/get_post_title.sh @@ -4,5 +4,6 @@ # # $1 the html file get_post_title() { - awk '/

/, /<\/a><\/h3>/{if (!/

/ && !/<\/a><\/h3>/) print}' "$1" + #awk '/

/, /<\/a><\/h3>/{if (!/

/ && !/<\/a><\/h3>/) print}' "$1" + head -1 $1 } \ No newline at end of file diff --git a/lib/is_boilerplate_file.sh b/lib/is_boilerplate_file.sh index a942cd8..9107038 100644 --- a/lib/is_boilerplate_file.sh +++ b/lib/is_boilerplate_file.sh @@ -9,6 +9,8 @@ # Return 0 (bash return value 'true') if the input file is an index, feed, etc # or 1 (bash return value 'false') if it is a blogpost is_boilerplate_file() { + return 1 ### Ugly Hack to Temporally disable the verification + declare non_blogpost_files declare index_file declare archive_index diff --git a/lib/list_posts.sh b/lib/list_posts.sh index eb56e0d..adff45b 100644 --- a/lib/list_posts.sh +++ b/lib/list_posts.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash # Displays a list of the posts +declare date_format +declare date_locale list_posts() { - declare date_format - declare date_locale - if ls ./*.html > /dev/null; then - echo "No posts yet. Use 'bb.sh post' to create one" && return - fi - + ls ./*.md &> /dev/null + (($? != 0)) && + echo "No posts yet. Use '$0 post' to create one" && + return + lines="" n=1 while IFS='' read -r i; do @@ -15,7 +16,6 @@ list_posts() { line="$n # $(get_post_title "$i") # $(LC_ALL=$date_locale date -r "$i" +"$date_format")" lines+=$line\\n n=$(( n + 1 )) - done < <(ls -t ./*.html) - + done < <(ls -t ./*.md) echo -e "$lines" | column -t -s "#" } \ No newline at end of file diff --git a/lib/write_entry.sh b/lib/write_entry.sh index ed49021..26d7cd1 100644 --- a/lib/write_entry.sh +++ b/lib/write_entry.sh @@ -2,46 +2,26 @@ # Manages the creation of the text file and the parsing to html file # also the drafts +declare template_tags_line_header +declare global_url +declare convert_filename write_entry() { - declare template_tags_line_header - declare global_url - declare convert_filename - declare save_markdown - test_markdown && fmt=md || fmt=html f=$2 - [[ $2 == -html ]] && fmt=html && f=$3 - - if [[ -n $f ]]; then - TMPFILE=$f - if [[ ! -f $TMPFILE ]]; then - echo "The file doesn't exist" + extension=${f##*.} + if [[ $extension != md ]]; then + f=${f}.md + fi + if [[ -n $f ]]; thenq + if [[ -f $f ]]; then + echo "The file $f doesn't exist" delete_includes exit fi - # guess format from TMPFILE - extension=${TMPFILE##*.} - [[ $extension == md || $extension == html ]] && fmt=$extension - # but let user override it (`bb.sh post -html file.md`) - [[ $2 == -html ]] && fmt=html - # Test if Markdown is working before re-posting a .md file - if [[ $extension == md ]]; then - if test_markdown; then - echo "Markdown is not working, please edit HTML file directly." - exit - fi - fi else TMPFILE=.entry-$RANDOM.$fmt echo -e "Title on this line\n" >> "$TMPFILE" - [[ $fmt == html ]] && cat << EOF >> "$TMPFILE" -

The rest of the text file is an html blog post. The process will continue as soon -as you exit your editor.

- -

$template_tags_line_header keep-this-tag-format, tags-are-optional, example

-EOF - - [[ $fmt == md ]] && cat << EOF >> "$TMPFILE" + cat << EOF >> "$TMPFILE" The rest of the text file is a **Markdown** blog post. The process will continue as soon as you exit your editor. @@ -54,21 +34,29 @@ EOF filename="" while [[ $post_status != "p" && $post_status != "P" ]]; do [[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any + $EDITOR "$TMPFILE" - if [[ $fmt == md ]]; then - html_from_md=$(mrkdwn "$TMPFILE") - parse_file "$html_from_md" - rm "$html_from_md" - else - parse_file "$TMPFILE" # this command sets $filename as the html processed file - fi + + html_from_md=$(mrkdwn "$TMPFILE") + + parse_file "$html_from_md" + rm "$html_from_md" + chmod 644 "$filename" [[ -n $preview_url ]] || preview_url=$global_url echo "To preview the entry, open $preview_url/$filename in your browser" - echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) " + echo -n "[P]ost this entry, [E]dit again, [D]raft for later, [C]ancel and quit? (p/e/d/c) " read -r post_status + #Case user cancelled + if [[ $post_status == c || $post_status == C ]]; then + rm "$TMPFILE" + delete_includes + echo "Your draft was erased. Nothing was changed in your blog." + exit + fi + #Case User choose post if [[ $post_status == d || $post_status == D ]]; then mkdir -p "drafts/" chmod 700 "drafts/" @@ -87,11 +75,7 @@ EOF fi done - if [[ $fmt == md && -n $save_markdown ]]; then - mv "$TMPFILE" "${filename%%.*}.md" - else - rm "$TMPFILE" - fi + mv "$TMPFILE" "${filename%%.*}.md" chmod 644 "$filename" echo "Posted $filename" relevant_tags=$(tags_in_post "$filename")