here="$(cd "$(dirname "$0")";pwd)";
cd "$(dirname "$0")"/src
if [[ $# -eq 0 ]]; then
cat <<EOF
new-doc - create new documents for WebCoso
Usage:
new-doc <document path> <tag>...
The <document path> will be taken relative to
$(pwd)
Non-existent tags will be created
EOF
exit 1
fi
shopt -s extglob
now="$(TZ=UTC date +'%F %T')"
force=0
if [[ "$1" == "-f" ]]; then
force=1
shift
fi
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"
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
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"
done
ln -s "${docname//+([^\/])/..}"/../templates/du2html.xsl "$docname"/
cd "$here"
./new-tag "${tags[@]}"