2020-05-13 09:46:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-05-13 16:24:04 +02:00
|
|
|
BASEDIR=`dirname $0`
|
|
|
|
|
|
|
|
if [ -f $BASEDIR/config.sh ]; then
|
|
|
|
. $BASEDIR/config.sh
|
2020-05-13 14:46:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$POSTS_DIR" ]
|
|
|
|
then
|
|
|
|
echo "POSTS_DIR environment variable is unset." > /dev/stderr
|
|
|
|
exit 2
|
|
|
|
fi
|
2020-05-13 09:46:58 +02:00
|
|
|
|
2020-05-13 16:24:04 +02:00
|
|
|
FIX=0
|
|
|
|
|
|
|
|
while getopts "f" option
|
2020-05-13 09:46:58 +02:00
|
|
|
do
|
2020-05-13 16:24:04 +02:00
|
|
|
case $option in
|
|
|
|
f)
|
|
|
|
FIX=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
local rc=0
|
|
|
|
post=$1
|
2020-05-13 09:46:58 +02:00
|
|
|
title=`sed -n 's/^title: "\?\(.*\)"\?$/\1/p' $post`
|
|
|
|
safename=`echo $title | iconv -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]' | tr -s '[:punct:] ' '-' | sed 's/-*$//g;s/^-*//g'`
|
2020-05-13 16:24:04 +02:00
|
|
|
if [ $post == $safename.md ]
|
|
|
|
then
|
|
|
|
rc=0
|
|
|
|
else
|
|
|
|
if [ $FIX -eq 1 ]
|
|
|
|
then
|
|
|
|
mv -v $post $safename.md
|
|
|
|
else
|
|
|
|
echo "$post should be named $safename.md" >&2
|
|
|
|
fi
|
|
|
|
rc=1
|
|
|
|
fi
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
cd $BASEDIR/$POSTS_DIR
|
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
rc=0
|
|
|
|
for post in *
|
|
|
|
do
|
|
|
|
check $post
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
rc=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
check $1
|
|
|
|
rc=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $rc
|