modifying the principle : all to be published article shall be in the published folder, and bob publish, publish them all
This commit is contained in:
parent
6976b4856f
commit
1d811c2abe
54
bob
54
bob
@ -108,6 +108,48 @@ publish()
|
|||||||
update_index
|
update_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publish_one()
|
||||||
|
{
|
||||||
|
# Storing the path of the post/article to publish
|
||||||
|
# The path is supposed to have this format "./drafts/published/<article>.*
|
||||||
|
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()
|
unpublish()
|
||||||
{
|
{
|
||||||
# storing the path of the article
|
# storing the path of the article
|
||||||
@ -146,17 +188,7 @@ elif [[ "$1" == "usage" ]]; then
|
|||||||
elif [[ "$1" == "init" ]]; then
|
elif [[ "$1" == "init" ]]; then
|
||||||
init
|
init
|
||||||
elif [[ "$1" == "publish" ]]; then
|
elif [[ "$1" == "publish" ]]; then
|
||||||
if [[ $# -eq 1 ]]; then
|
publish_all
|
||||||
echo "Usage : bob publish <draft_name>"
|
|
||||||
else
|
|
||||||
publish $2
|
|
||||||
fi
|
|
||||||
elif [[ "$1" == "unpublish" ]]; then
|
|
||||||
if [[ $# -eq 1 ]]; then
|
|
||||||
echo "Usage : bob unpublish <post_name>"
|
|
||||||
else
|
|
||||||
unpublish $2
|
|
||||||
fi
|
|
||||||
elif [[ "$1" == "deploy" ]]; then
|
elif [[ "$1" == "deploy" ]]; then
|
||||||
deploy
|
deploy
|
||||||
elif [[ "$1" == "help" ]]; then
|
elif [[ "$1" == "help" ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user