diff --git a/.gitignore b/.gitignore index 1d40616..e32f34a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ css bash posts *.conf -index.html -README.html +index.html \ No newline at end of file diff --git a/Makefile b/Makefile index a6c5959..4e749a2 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,14 @@ install: @echo "Installing bob" cp bob /usr/local/bin cp bob2 /usr/local/bin - cp -r lib /usr/local/lib/bob + cp -r lib/template /usr/local/lib/bob/template + cp lib/*.awk /usr/local/lib/bob uninstall: @echo "Uninstalling bob" rm /usr/local/bin/bob rm /usr/local/bin/bob2 - rm -r /usr/local/lib/bob + rm -rf /usr/local/lib/bob .PHONY: test # Declare 'test' as a phony target diff --git a/bob2 b/bob2 index 8fa31ed..982ad3c 100755 --- a/bob2 +++ b/bob2 @@ -16,7 +16,7 @@ usage() echo echo "bob commands :" echo " help display this help" - echo " init initiate the blog" + echo " init initiate a blog" echo " publish publish the blog" } @@ -25,31 +25,60 @@ init() { echo Name of the author of the blog : read author - echo "author:$author" > .blog.conf + echo "author=$author" > .blog.conf echo Name of the blog : read blog - echo "blog:$blog" >> .blog.conf - echo "Language of the blog : (en)" + 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 "lang=$lang" >> .blog.conf echo "Activate dark mode : (y/N)" read dark if [ -z $dark ]; then dark=n fi - echo "dark:$dark" >> .blog.conf + echo "dark=$dark" >> .blog.conf mkdir drafts - mkdir bases + # mkdir templates mkdir posts - mkdir css - _init_css - _index "$blog" "$lang" "$dark" + # mkdir css + # _init_css + # _index "$blog" "$lang" "$dark" } +update_index() +{ + ls -t ./posts | awk ' + BEGIN { + print "" + }' +} +publish() +{ + post=$(awk -f lib/markdown.awk ./drafts/$1.md) + template="./lib/template/post.html" + awk -v content="$post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$1.html" + mv ./drafts/$1.md ./drafts/published/$1.md +} + +unpublish() +{ + rm ./posts/$1.html + mv ./drafts/published/$1.md ./drafts/$1.md +} if [[ $# -eq 0 ]]; then usage @@ -60,7 +89,17 @@ elif [[ "$1" == "usage" ]]; then elif [[ "$1" == "init" ]]; then init elif [[ "$1" == "publish" ]]; then - publish + if [[ $# -eq 1 ]]; then + echo "Usage : bob publish " + else + publish $2 + fi +elif [[ "$1" == "unpublish" ]]; then + if [[ $# -eq 1 ]]; then + echo "Usage : bob unpublish " + else + unpublish $2 + fi elif [[ "$1" == "help" ]]; then usage fi diff --git a/lib/template/post.html b/lib/template/post.html index 0bc4be6..e3627a0 100644 --- a/lib/template/post.html +++ b/lib/template/post.html @@ -1,16 +1,19 @@ - - - simpet - - - - - -

simpet

-
+ + + + simpet + + + + + + +

simpet

+
{{article}} -
- - +
+ + + \ No newline at end of file diff --git a/test/bob/test_init.sh b/test/bob/test_init.sh new file mode 100644 index 0000000..e69de29 diff --git a/test/test.sh b/test/test.sh index dcbab40..9c898b8 100755 --- a/test/test.sh +++ b/test/test.sh @@ -8,4 +8,26 @@ NC='\033[0m' # No Color (reset) echo -e "${YELLOW}Testing markown parser :${NC}\n" -./parser/test_md_parser.sh ../lib/markdown.awk awk +./test/parser/test_md_parser.sh ./lib/markdown.awk awk + +echo -e "${YELLOW}Testing bob init :${NC}\n" + +author="author" +blog="blog" +lang="fr" +dark="y" + +./bob2 init << EOF +$author +$blog +$lang +$dark +EOF + +conf_author=$(grep "^author=" .blog.conf | cut -d '=' -f 2) +conf_blog=$(grep "^blog=" .blog.conf | cut -d '=' -f 2) +conf_lang=$(grep "^lang=" .blog.conf | cut -d '=' -f 2) +conf_dark=$(grep "^dark=" .blog.conf | cut -d '=' -f 2) + +rm -r posts +rm -r drafts \ No newline at end of file