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
|
#!/usr/bin/env bash
set -e
workDir="$(dirname $(realpath ${0}))"
tmpDir="/tmp/pyfunceble-demos"
jsonDest="${tmpDir}/asciinema_demo.json"
jsonTemplate='{"title": "%%title%%","link": "%%link%%"}'
templates=()
finalJson=""
for file in ${workDir}/*.tut
do
pyfuncebleIOTitle="$(fgrep "pyfunceble-io-title" ${file} | awk -v FS=": " '{ print $2}')"
if [[ -z "${pyfuncebleIOTitle}" ]]
then
pyfuncebleIOTitle="PyFunceble-Demo"
fi
# uploadLink=$(${workDir}/upload.sh ${file})
uploadLink="https://github.com"
if [[ "${uploadLink}" =~ ^https:.* ]]
then
localTemplate="${jsonTemplate}"
localTemplate="${localTemplate//%%title%%/${pyfuncebleIOTitle}}"
localTemplate="${localTemplate//%%link%%/${uploadLink}/iframe}"
templates[${#templates[@]}]="${localTemplate}"
fi
done
finalJson+="["
templatesLength="${#templates[@]}"
for index in "${!templates[@]}"
do
if [[ ! -z ${templates[${index}]} ]]
then
finalJson+="${templates[${index}]}"
if [[ "${index}" != "$((${templatesLength}-1))" ]]
then
finalJson+=","
fi
fi
done
finalJson+="]"
echo "${finalJson}" >> "${jsonDest}"
|