gergelypolonkai-web-jekyll/_make_tags.sh

36 lines
862 B
Bash
Raw Normal View History

2014-06-26 16:48:13 +00:00
#! /bin/sh
#
# Find all tags in all posts under _posts, and generate a file for
# each under blog/tag. Also, if a tag page does not contain the tag:
# or layout: keywords, the script will include them in the front
# matter.
2015-04-22 16:11:35 +00:00
layout="posts-by-tag"
for tag in `grep -h ^tags: _posts/* | sed -re 's/^tags: +\[//' -e 's/\]$//' -e 's/, /\n/g' | sort | uniq`
2014-06-26 16:48:13 +00:00
do
tag_file="blog/tag/${tag}.html"
if [ ! -f $tag_file ]
then
echo "Creating $tag_file"
2014-06-26 16:48:13 +00:00
cat <<EOF > $tag_file
---
2015-04-22 16:11:35 +00:00
layout: $layout
2014-06-26 16:48:13 +00:00
tag: $tag
---
EOF
else
if ! egrep "^tag: +${tag}$" $tag_file 2>&1 > /dev/null
2014-06-26 16:48:13 +00:00
then
sed -i "0,/---/! s/---/tag: $tag\\n---/" $tag_file
fi
if ! egrep "^layout: +" $tag_file 2>&1 > /dev/null
2014-06-26 16:48:13 +00:00
then
2015-04-22 16:11:35 +00:00
sed -i "0,/---/! s/---/layout: $layout\\n---/" $tag_file
2014-06-26 16:48:13 +00:00
fi
fi
done