diff --git a/bob2 b/bob2 new file mode 100755 index 0000000..8fa31ed --- /dev/null +++ b/bob2 @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +usage() +{ + echo + echo "This script is made for those who want to blog and are also addicted to the command line" + echo + echo "Run the initiation for a start. After that, place all your future blog + posts, written in markdown (.md or .markdown), in the draft folder." + echo + echo "Once you publish your blog, all the drafts in the said folder will be + converted to html, added to the posts folder and append to the index.html" + echo + echo "To remove a post, just remove it from the draft folder and republish + your blog" + echo + echo "bob commands :" + echo " help display this help" + echo " init initiate the blog" + echo " publish publish the blog" +} + + +init() +{ + echo Name of the author of the blog : + read author + echo "author:$author" > .blog.conf + echo Name of the blog : + read blog + echo "blog:$blog" >> .blog.conf + echo "Language of the blog : (en)" + read lang + if [ -z $lang ]; then + lang=en + fi + echo "lang:$lang" >> .blog.conf + echo "Activate dark mode : (y/N)" + read dark + if [ -z $dark ]; then + dark=n + fi + echo "dark:$dark" >> .blog.conf + mkdir drafts + mkdir bases + mkdir posts + mkdir css + _init_css + _index "$blog" "$lang" "$dark" +} + + + +if [[ $# -eq 0 ]]; then + usage +elif [[ "$1" == "help" ]]; then + usage +elif [[ "$1" == "usage" ]]; then + usage +elif [[ "$1" == "init" ]]; then + init +elif [[ "$1" == "publish" ]]; then + publish +elif [[ "$1" == "help" ]]; then + usage +fi diff --git a/lib/markdown.awk b/lib/markdown.awk new file mode 100755 index 0000000..2a67787 --- /dev/null +++ b/lib/markdown.awk @@ -0,0 +1,150 @@ +#!/usr/bin/awk + +BEGIN { + env = "none" + stack_pointer = 0 + push(env) +} + +# Function to push a value onto the stack +function push(value) { + stack_pointer++ + stack[stack_pointer] = value +} + +# Function to pop a value from the stack (LIFO) +function pop() { + if (stack_pointer > 0) { + value = stack[stack_pointer] + delete stack[stack_pointer] + stack_pointer-- + return value + } else { + return "empty" + } +} + +# Function to get last value in LIFO +function last() { + return stack[stack_pointer] +} + +function replaceEmAndStrong(line, result, start, end) { + # Replace occurrences of **...** with ... + while (match(line, /\*\*([^*]+)\*\*/)) { + start = RSTART + end = RSTART + RLENGTH - 1 + # Build the result: before match, , content, , after match + line = substr(line, 1, start-1) "" substr(line, start+2, RLENGTH-4) "" substr(line, end+1) + } + + # Replace occurrences of *...* with ... + while (match(line, /\*([^*]+)\*/)) { + start = RSTART + end = RSTART + RLENGTH - 1 + # Build the result: before match, , content, , after match + line = substr(line, 1, start-1) "" substr(line, start+1, RLENGTH-2) "" substr(line, end+1) + } + + return line +} + + +function closeOne() { + env = pop() + print "" +} + +# Matching headers +/^#+ / { + match($0, /#+ /); + n = RLENGTH; + print "" substr($0, n + 1) "" +} + +# Matching blockquotes +/^> / { + env = last() + if (env == "blockquote") + { + # In a blockquote block only print the text + print substr($0, 3); + } else { + # Otherwise, init the blockquote block + push("blockquote") + print "
\n" substr($0, 3) + } +} + +# Matching unordered lists +/^[-+*] / { + env = last() + if (env == "ul" ) { + # In a unordered list block, print a new item + print "
  • " substr($0, 3) "
  • " + } else { + # Otherwise, init the unordered list block + push("ul") + print "