56 lines
1.0 KiB
Bash
Executable File
56 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
. ./_commands/_extract.sh
|
|
|
|
dir=$1 file=$2
|
|
|
|
page=${file%.choice}
|
|
|
|
values=$(extract "$dir" "$page.md" ac_choices)
|
|
|
|
choose() {
|
|
dir=$1 file=$2 target=$3
|
|
|
|
user=${dir#*/users/}
|
|
user=${user%%/*}
|
|
target=${target#*(}
|
|
target=${target%)*}
|
|
target=${target#/pages}
|
|
|
|
echo "Choice => $target for user $user"
|
|
|
|
mkdir -p "../content/users/$user${target%/*}/"
|
|
cp "../content/pages$target.md" "../content/users/$user${target%/*}/"
|
|
|
|
# Delete former result files
|
|
rm "$dir"/*.result
|
|
|
|
# Generate a result file
|
|
echo "$target" > "$dir/$page.result"
|
|
|
|
./_commands/default_actions.sh "$dir" "${target##*/}"
|
|
|
|
./_commands/count.sh "$dir" "${target##*/}" "${page}"
|
|
}
|
|
|
|
index=0
|
|
target=$(cat "$dir/$file")
|
|
|
|
for value in $values
|
|
do
|
|
if [ $index = "${target#ac_choice=}" ]
|
|
then
|
|
choose "$dir" "$file" "$value"
|
|
break
|
|
fi
|
|
index=$((index+1))
|
|
done
|
|
|
|
if [ -z "${dir##*/content/users/*}" ]
|
|
then
|
|
# Remove the originating file
|
|
rm "$dir/$page.md"
|
|
# And destination directory
|
|
rm -rf "${dir%/content/*}/public/${dir#*/content/}/$page/"
|
|
fi
|