From 1d811c2abe0ccab40f64dc20d35ac8183007a5a6 Mon Sep 17 00:00:00 2001 From: Simon Petit Date: Thu, 5 Dec 2024 11:56:19 +0100 Subject: [PATCH] modifying the principle : all to be published article shall be in the published folder, and bob publish, publish them all --- bob | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/bob b/bob index f0e8b11..36ad4c8 100755 --- a/bob +++ b/bob @@ -108,6 +108,48 @@ publish() update_index } +publish_one() +{ + # Storing the path of the post/article to publish + # The path is supposed to have this format "./drafts/published/
.* + article_path=$1 + + # from the relative path, only retrieving the name of the article (without file extension) + article_name=$(echo $article_path | cut -d '/' -f 4 | cut -d '.' -f 1) + + # Convert the markdown draft into an html article and storing it locally + post=$(awk -f ${BOB_LIB}/markdown.awk ./$article_path) + + # Retrieving the html article template + template="${BOB_LIB}/template/post.html" + + # Escaping the & for next step to not confuse awk + escaped_post=$(echo "$post" | sed 's/&/\\&/g') + + # In the template, replacing the string {{article}} by the actual content parsed above + awk -v content="$escaped_post" '{gsub(/\{\{article\}\}/, content); print}' "$template" > "./posts/$article_name.html" +} + +publish_all() +{ + # List all drafts to be published + published=$(ls -1 ./drafts/published) + + # turning it into an array + published_array=($published) + + # Remove all html articles in case a previously published one was removed + rm ./posts/*.html + + # Publish them one by one (ie turning md into html) + for file in "${published_array[@]}"; do + publish_one ./drafts/published/$file + done + + # updating the index.html as new articles are supposedly present and some may be removed + update_index +} + unpublish() { # storing the path of the article @@ -146,17 +188,7 @@ elif [[ "$1" == "usage" ]]; then elif [[ "$1" == "init" ]]; then init elif [[ "$1" == "publish" ]]; then - 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 + publish_all elif [[ "$1" == "deploy" ]]; then deploy elif [[ "$1" == "help" ]]; then