diff --git a/lib/create_html_page.sh b/lib/create_html_page.sh index 11d8ee8..d9b437a 100644 --- a/lib/create_html_page.sh +++ b/lib/create_html_page.sh @@ -47,6 +47,8 @@ create_html_page() { file_url=${filename#./} file_url=${file_url%.rebuilt} # Get the correct URL when rebuilding + file_url=${file_url%.html} + file_url=${file_url%.md}.html # Get the correct link # one blog entry if [[ $index == no ]]; then echo '' # marks the beginning of the whole post diff --git a/lib/do_main.sh b/lib/do_main.sh index b9f592d..436cfae 100644 --- a/lib/do_main.sh +++ b/lib/do_main.sh @@ -77,7 +77,10 @@ do_main() { all_posts all_tags make_rss + echo 'making gophermap' make_gophermap + echo 'making geminicapsule' make_gemini + echo 'deleting includes' delete_includes } \ No newline at end of file diff --git a/lib/edit.sh b/lib/edit.sh index 885f4ef..eafe344 100644 --- a/lib/edit.sh +++ b/lib/edit.sh @@ -12,11 +12,12 @@ # "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) +declare date_format_full +declare date_format_timestamp +declare template_tags_line_header +declare prefix_tags edit() { - declare date_format_full - declare date_format_timestamp - declare template_tags_line_header - declare prefix_tags + [[ ! -f "${1%%.*}.html" ]] && \ printf "Can't edit post \"%s.html\", did you mean to use \"bb.sh post \"?\\n" "${1%%.*}" && exit 1 diff --git a/lib/get_html_file_content.sh b/lib/get_html_file_content.sh index 28cf6b3..376cb9b 100644 --- a/lib/get_html_file_content.sh +++ b/lib/get_html_file_content.sh @@ -6,9 +6,10 @@ # $3 "cut" to remove text from
to # note that this does not remove
line itself, # so you can see if text was cut or not +declare cut_line +declare cut_tags +declare template_tags_line_header get_html_file_content() { - declare cut_line cut_tags - declare template_tags_line_header awk "//, //{ if (!// && !//) print if (\"$3\" == \"cut\" && /$cut_line/){ diff --git a/lib/get_post_author.sh b/lib/get_post_author.sh index a086bd9..fdf69a6 100644 --- a/lib/get_post_author.sh +++ b/lib/get_post_author.sh @@ -3,6 +3,8 @@ # Return the post author # # $1 the html file +declare global_author get_post_author() { - awk '/
.+/, //{if (!/
.+/ && !//) print}' "$1" | sed 's/<\/div>//g' + # awk '/
.+/, //{if (!/
.+/ && !//) print}' "$1" | sed 's/<\/div>//g' + echo $global_author } \ No newline at end of file diff --git a/lib/is_boilerplate_file.sh b/lib/is_boilerplate_file.sh index 9107038..68b5e78 100644 --- a/lib/is_boilerplate_file.sh +++ b/lib/is_boilerplate_file.sh @@ -8,19 +8,17 @@ # # 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 +declare non_blogpost_files +declare index_file +declare archive_index +declare gophermap +declare gemini_index +declare tags_index +declare footer_file +declare header_file +declare prefix_tags +declare html_exclude is_boilerplate_file() { - return 1 ### Ugly Hack to Temporally disable the verification - - declare non_blogpost_files - declare index_file - declare archive_index - declare gophermap - declare gemini_index - declare tags_index - declare footer_file - declare header_file - declare prefix_tags - declare html_exclude name=${1#./} # First check against user-defined non-blogpost pages for item in "${non_blogpost_files[@]}"; do diff --git a/lib/list_tags.sh b/lib/list_tags.sh index 87dbdd0..028ac87 100644 --- a/lib/list_tags.sh +++ b/lib/list_tags.sh @@ -3,14 +3,14 @@ # Displays a list of the tags # # $2 if "-n", tags will be sorted by number of posts -list_tags() { - declare prefix_tags - declare template_tags_posts_singular - declare template_tags_posts +declare prefix_tags +declare template_tags_posts_singular +declare template_tags_posts +list_tags() { if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi if ls "./${prefix_tags}"*.html > /dev/null; then - echo "No posts yet. Use 'bb.sh post' to create one" && return + echo "No posts yet. Use '$0 post' to create one" && return fi lines="" diff --git a/lib/make_gemini.sh b/lib/make_gemini.sh index bdf3624..f34130c 100644 --- a/lib/make_gemini.sh +++ b/lib/make_gemini.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash - +declare gemini_index make_gemini() { - declare gemini_index + if [ ! -d "${HOME}/public_gemini" ]; then printf "Creating ~/public_gemini\\n" mkdir "${HOME}/public_gemini" diff --git a/lib/make_gophermap.sh b/lib/make_gophermap.sh index 6efd0ed..2b2f893 100644 --- a/lib/make_gophermap.sh +++ b/lib/make_gophermap.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash - +declare gophermap make_gophermap() { - declare gophermap if [ ! -d "${HOME}/public_gopher" ]; then printf "Creating gopher hole\\n" mkdir "${HOME}/public_gopher" @@ -23,5 +22,5 @@ make_gophermap() { EOF chmod +x "${HOME}/public_html/blog/${gophermap}" fi - chmod 644 "./*.md" + chmod 644 ./*.md } \ No newline at end of file diff --git a/lib/make_rss.sh b/lib/make_rss.sh index 5be3067..ebfe531 100644 --- a/lib/make_rss.sh +++ b/lib/make_rss.sh @@ -1,15 +1,16 @@ #!/usr/bin/env bash # Generate the feed file +declare blog_feed +declare date_format_full +declare global_title +declare global_url +declare global_description +declare index_file +declare number_of_feed_articles +declare cut_do make_rss() { - declare blog_feed - declare date_format_full - declare global_title - declare global_url - declare global_description - declare index_file - declare number_of_feed_articles - declare cut_do + echo -n "Making RSS " rssfile=$blog_feed.$RANDOM diff --git a/lib/parse_file.sh b/lib/parse_file.sh index 89371c3..4608d56 100644 --- a/lib/parse_file.sh +++ b/lib/parse_file.sh @@ -8,11 +8,11 @@ # note that although timestamp is optional, something must be provided at its # place if destination file name is provided, i.e: # parse_file source.txt "" destination.html +declare convert_filename +declare template_tags_line_header +declare prefix_tags +declare global_author parse_file() { - declare convert_filename - declare template_tags_line_header - declare prefix_tags - declare global_author # Read for the title and check that the filename is ok title="" while IFS='' read -r line; do diff --git a/lib/posts_with_tags.sh b/lib/posts_with_tags.sh index 9dd90c2..c07cab2 100644 --- a/lib/posts_with_tags.sh +++ b/lib/posts_with_tags.sh @@ -3,6 +3,7 @@ # Finds all posts referenced in a number of tags. # Arguments are tags # Prints one line with space-separated tags to stdout +declare prefix_tags posts_with_tags() { (($# < 1)) && return set -- "${@/#/$prefix_tags}" diff --git a/lib/rebuild_all_entries.sh b/lib/rebuild_all_entries.sh index e1ecc37..90553ec 100644 --- a/lib/rebuild_all_entries.sh +++ b/lib/rebuild_all_entries.sh @@ -2,13 +2,17 @@ # Regenerates all the single post entries, keeping the post content but modifying # the title, html structure, etc +#declare date_inpost +declare date_format_full +declare date_format_timestamp +declare markdown_bin +declare template_tags_line_header +declare prefix_tags rebuild_all_entries() { - declare date_inpost - declare date_format_full - declare date_format_timestamp + echo -n "Rebuilding all entries " - for i in ./*.html; do + for i in ./*.md; do is_boilerplate_file "$i" && continue; contentfile=.tmp.$RANDOM while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done @@ -16,22 +20,42 @@ rebuild_all_entries() { echo -n "." # Get the title and entry, and rebuild the html structure from scratch (divs, title, description...) title=$(get_post_title "$i") + $markdown_bin <"$i" >> "$contentfile" - get_html_file_content 'text' 'text' <"$i" >> "$contentfile" + + #Get Tags + while IFS='' read -r line; do + if [[ $line == "

$template_tags_line_header"* ]]; then + tags=$(echo "$line" | cut -d ":" -f 2- | sed -e 's/<\/p>//g' -e 's/^ *//' -e 's/ *$//' -e 's/, /,/g') + IFS=, read -r -a array <<< "$tags" + echo -n "

$template_tags_line_header " >> "${contentfile}.tmp" + for item in "${array[@]}"; do + echo -n "$item, " + done | sed 's/, $/<\/p>/g' >> "${contentfile}.tmp" + else + echo "$line" >> "${contentfile}.tmp" + fi + done < "$contentfile" + cp "${contentfile}" "$contentfile.old" + mv "${contentfile}.tmp" "$contentfile" # Read timestamp from post, if present, and sync file timestamp - timestamp=$(awk '// { print }' "$i" | cut -d '#' -f 2) - [[ -n $timestamp ]] && touch -t "$timestamp" "$i" + + #timestamp=$(awk '// { print }' "$i" | cut -d '#' -f 2) + #[[ -n $timestamp ]] && touch -t "$timestamp" "$i" + # Read timestamp from file in correct format for 'create_html_page' + timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full") create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")" # keep the original timestamp! timestamp=$(LC_ALL=C date -r "$i" +"$date_format_timestamp") - mv "$i.rebuilt" "$i" - chmod 644 "$i" - touch -t "$timestamp" "$i" - rm "$contentfile" + newfile=${i%.md}.html + mv "$i.rebuilt" "$newfile" + chmod 644 "$newfile" + touch -t "$timestamp" "$newfile" + #rm "$contentfile" done echo "" } \ No newline at end of file diff --git a/lib/rebuild_index.sh b/lib/rebuild_index.sh index 2c8920a..40271c8 100644 --- a/lib/rebuild_index.sh +++ b/lib/rebuild_index.sh @@ -1,21 +1,22 @@ #!/usr/bin/env bash # Generate the index.html with the content of the latest posts +declare index_file +declare number_of_index_articles +declare cut_do +declare cut_line +declare template_read_more +declare template_archive +declare template_subscribe +declare template_tags_title +declare blog_feed +declare global_author +declare global_feedburner +declare global_title +declare archive_index +declare tags_index rebuild_index() { - declare index_file - declare number_of_index_articles - declare cut_do - declare cut_line - declare template_read_more - declare template_archive - declare template_subscribe - declare template_tags_title - declare blog_feed - declare global_author - declare global_feedburner - declare global_title - declare archive_index - declare tags_index + echo -n "Rebuilding the index " newindexfile=$index_file.$RANDOM contentfile=$newindexfile.content diff --git a/lib/rebuild_tags.sh b/lib/rebuild_tags.sh index e1da522..0c36b8e 100644 --- a/lib/rebuild_tags.sh +++ b/lib/rebuild_tags.sh @@ -9,14 +9,15 @@ # example: # rebuild_tags "one_post.html another_article.html" "example-tag another-tag" # mind the quotes! +declare prefix_tags +declare cut_do +declare cut_line +declare template_read_more +declare template_tag_title +declare global_title +declare global_author rebuild_tags() { - declare prefix_tags - declare cut_do - declare cut_line - declare template_read_more - declare template_tag_title - declare global_title - declare global_author + if (($# < 2)); then # will process all files and tags files=$(ls -t ./*.html) diff --git a/lib/tags_in_post.sh b/lib/tags_in_post.sh index 35c6eda..c9e000e 100644 --- a/lib/tags_in_post.sh +++ b/lib/tags_in_post.sh @@ -3,7 +3,7 @@ # Finds all tags referenced in one post. # Accepts either filename as first argument, or post content at stdin # Prints one line with space-separated tags to stdout +declare template_tags_line_header tags_in_post() { - declare template_tags_line_header sed -n "/^

$template_tags_line_header/{s/^

$template_tags_line_header//;s/<[^>]*>//g;s/[ ,]\+/ /g;p;}" "$1" | tr ', ' ' ' } \ No newline at end of file diff --git a/lib/write_entry.sh b/lib/write_entry.sh index 26d7cd1..4ddefaa 100644 --- a/lib/write_entry.sh +++ b/lib/write_entry.sh @@ -7,12 +7,8 @@ declare global_url declare convert_filename write_entry() { f=$2 - extension=${f##*.} - if [[ $extension != md ]]; then - f=${f}.md - fi - if [[ -n $f ]]; thenq - if [[ -f $f ]]; then + if [[ -n $f ]]; then + if [[ ! -f $f ]]; then echo "The file $f doesn't exist" delete_includes exit diff --git a/md2gemini.awk b/md2gemini.awk index c77c168..5658c38 100755 --- a/md2gemini.awk +++ b/md2gemini.awk @@ -6,6 +6,6 @@ # Based on md2html by Jesus Galan (yiyus) 2009 # # -# Usage: md2gemini.awk file.md > file.html +# Usage: md2gemini.awk file.md > file.gmi 1 \ No newline at end of file diff --git a/md2gopher.awk b/md2gopher.awk index 7b58a4b..ed862a1 100755 --- a/md2gopher.awk +++ b/md2gopher.awk @@ -6,7 +6,7 @@ # Based on md2html by Jesus Galan (yiyus) 2009 # # -# Usage: md2gopher.awk file.md > file.html +# Usage: md2gopher.awk file.md > file.txt function eschtml(t) { #gsub("&", "\\&", t); diff --git a/md2html.awk b/md2html.awk index b981c04..9862032 100755 --- a/md2html.awk +++ b/md2html.awk @@ -1,9 +1,9 @@ #!/bin/awk -f # -# by: Josemar Lohn -# lo.hn on www/gemini/gopher +# by: Jesus Galan (yiyus) 2009 # -# Based on md2html by Jesus Galan (yiyus) 2009 +# Updated By Josemar Lohn +# lo.hn on www/gemini/gopher # # # Usage: md2html.awk file.md > file.html diff --git a/spec/do_main_spec.sh b/spec/do_main_spec.sh index c46c4bb..4e06b97 100644 --- a/spec/do_main_spec.sh +++ b/spec/do_main_spec.sh @@ -7,7 +7,7 @@ Describe 'do_main()' It 'Call function do_main without paramenters' When call do_main The line 1 of output should eq "You're not in your blog directory. Moving you there now" - #The line 2 of output should eq "tildelog 0.1" + The line 2 of output should eq "tildelog 0.1" #The line 3 of output should eq "usage: ./tildelog.sh command [filename]" End End