here="$(cd "$(dirname "$0")";pwd)";
cd "$(dirname "$0")"/src
usage="new-doc - create new documents for WebCoso
Usage:
new-doc [-k kind] [-f] <document path> <tag>...
The <document path> will be taken relative to
$(pwd)
Non-existent tags will be created.
Kind is a suffix to templates/du2html.
"
if [[ $# -eq 0 ]]; then
>&2 echo "$usage"
exit 1
fi
shopt -s extglob
now="$(TZ=UTC date +'%F %T')"
force=0
kind=''
while getopts fk: optname; do
case "$optname" in
f) force=1 ;;
k) kind="$OPTARG" ;;
?) echo "$usage"; exit 2 ;;
esac
done
shift $[ $OPTIND - 1 ]
docname="$1"
shift
declare -a tags
tags=("$@")
if [[ -d "$docname" && "$force" -ne 1 ]]; then
>&2 echo "\"$docname\" already exists"
exit 1
fi
docname="${docname%/}"
mkdir -p "$docname"
mkdir -p ../additions/"$docname"
langs="${LANGS:-en it}"
for lang in $langs; do
{
cat <<EOF
${docname//?/=}
$docname
${docname//?/=}
:CreationDate: $now
:Id: $docname
EOF
if [[ ${#tags[@]} -gt 0 ]]; then
i=0
for tag in "${tags[@]}"; do
tag="${tag%/}"
if [[ $i -eq 0 ]]; then
echo -n ':tags: '
else
echo -n ' '
fi
echo "- $tag"
i=$(( $i + 1 ))
done
fi
echo ''
} > "$docname/document.${lang}.rest.txt"
echo "/document.${lang}.du.xml" >> "${docname}/.gitignore"
done
ln -s "${docname//+([^\/])/..}"/../templates/du2html${kind:+"-$kind"}.xsl "$docname"/du2html.xsl
cd "$here"
./new-tag "${tags[@]}"