Skip to content

Instantly share code, notes, and snippets.

@RadwaKamal
Last active December 10, 2016 13:15
Show Gist options
  • Save RadwaKamal/8c85ce40b3f58fe367dedbb94138d6d7 to your computer and use it in GitHub Desktop.
Save RadwaKamal/8c85ce40b3f58fe367dedbb94138d6d7 to your computer and use it in GitHub Desktop.
Shell script to generate <tag_name>.md file automatically for a jekyll blog.
#!/bin/bash
target=(_posts/*.md)
prv_last_file=`cat last_file.txt`
tag_template=`cat tag_template.md`
for ((i=${#target[@]}-1; i>=0; i--)); do
if [ "$prv_last_file" == "${target[$i]}" ]; then
echo ${target[${#target[@]}-1]} > last_file.txt
echo "We are done, Thank you!"
break
else
content=`cat ${target[$i]} | grep -m1 "tags\s*:"`
tags=`echo $content | cut -d: -f2-`
for tag in $tags; do
clean_tag=`echo $tag | tr -d '[:space:]'`
if [ -e "tag/$clean_tag.md" ]; then
continue
else
echo "${tag_template//tag_name/$clean_tag}" >> tag/$clean_tag.md
echo "$clean_tag file created successfully."
fi
done
echo ${target[${#target[@]}-1]} > last_file.txt
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment