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"
|
|
|
|
|
2015-08-19 10:41:24 +00:00
|
|
|
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
|
2017-01-02 10:15:21 +00:00
|
|
|
tag_file="blog/tag/${tag}.md"
|
2015-08-28 14:34:43 +00:00
|
|
|
echo -n "[$tag] "
|
2014-06-26 16:48:13 +00:00
|
|
|
|
|
|
|
if [ ! -f $tag_file ]
|
|
|
|
then
|
2015-08-28 14:34:43 +00:00
|
|
|
echo "creating ($tag_file)"
|
2015-08-19 10:41:24 +00:00
|
|
|
|
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
|
2015-08-28 14:34:43 +00:00
|
|
|
updated=0
|
|
|
|
if ! egrep "^tag: +${tag}$" $tag_file 2>&1 > /dev/null; then
|
|
|
|
echo "adding tag"
|
2014-06-26 16:48:13 +00:00
|
|
|
sed -i "0,/---/! s/---/tag: $tag\\n---/" $tag_file
|
2015-08-28 14:34:43 +00:00
|
|
|
updated=1
|
2014-06-26 16:48:13 +00:00
|
|
|
fi
|
|
|
|
|
2015-08-28 14:34:43 +00:00
|
|
|
if ! egrep "^layout: +" $tag_file 2>&1 > /dev/null; then
|
|
|
|
echo "adding layout"
|
2015-04-22 16:11:35 +00:00
|
|
|
sed -i "0,/---/! s/---/layout: $layout\\n---/" $tag_file
|
2015-08-28 14:34:43 +00:00
|
|
|
updated=1
|
|
|
|
fi
|
|
|
|
|
2016-02-26 14:24:15 +00:00
|
|
|
if [ $updated = 0 ]; then
|
2015-08-28 14:34:43 +00:00
|
|
|
echo ""
|
2014-06-26 16:48:13 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|