summaryrefslogtreecommitdiff
path: root/new-doc
blob: 9c0f0c4819ec3d509639cbdd4f781436e376d827 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash 
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"
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.xsl "$docname"/
 
cd "$here"
./new-tag "${tags[@]}"