rename scripts

This commit is contained in:
2020-05-13 16:25:49 +02:00
parent f042a9561d
commit 1c617413d5
3 changed files with 0 additions and 0 deletions

29
tests/check_assets.sh Normal file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
if [ -f config.sh ]; then
. config.sh
fi
if [ -z "$POSTS_DIR" ]
then
echo "POSTS_DIR environment variable is unset." > /dev/stderr
exit 2
fi
if [ -z "$ASSETS_DIR" ]
then
echo "ASSETS_DIR environment variable is unset." > /dev/stderr
exit 2
fi
rc=0
sed -rn 's|^.*\!\[.*\]\(%assets_url%/(.*)\)$|\1|p' $POSTS_DIR/* | while read line
do
if [ ! -f "$ASSETS_DIR/$line" ]
then
echo "$line not found"
rc=1
fi
done
exit $rc

65
tests/check_post_filename.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
BASEDIR=`dirname $0`
if [ -f $BASEDIR/config.sh ]; then
. $BASEDIR/config.sh
fi
if [ -z "$POSTS_DIR" ]
then
echo "POSTS_DIR environment variable is unset." > /dev/stderr
exit 2
fi
FIX=0
while getopts "f" option
do
case $option in
f)
FIX=1
;;
esac
done
shift $(($OPTIND - 1))
function check() {
local rc=0
post=$1
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'`
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

2
tests/config.sh Normal file
View File

@@ -0,0 +1,2 @@
POSTS_DIR="../content/posts"
ASSETS_DIR="../assets"