#!/bin/bash
cp ../store.html.orig ../store.html
cp ../purchase-form.html.orig ../purchase-form.html
while IFS= read -r line
do
name=$(echo "$line"|jq .name|tr -d '"')
AI=$(echo "$line"|jq .ai|tr -d '"')
imageLocation=$(echo "$line"|jq .location|tr -d '"')
imageName=$(echo "$line"|jq .image|tr -d '"')
#imageName=$(echo "$name"|tr ' ' '-'|sed -e 's/$/.webp/g')
pageName=$(echo "$name"|tr ' ' '-'|tr -d "'"|sed -e 's/$/.html/g')
price=$(echo "$line"|jq .price|tr -d '"')
desc=$(echo "$line"|jq .desc|tr -d '"')
if [ "$AI" = "true" ]
#if [ "false" = "true" ]
then
aitext=$(./textgen.py 200 "$desc")
while [[ pass -eq 0 ]]
do
aitext=$(./textgen.py 200 "$desc")
if [[ "$aitext" == *"/"* ]]
then
echo "detected a slash"
pass=0
elif [[ "$aitext" == "" ]]
then
echo "text was empty"
pass=0
elif [[ "$aitext" = *"http"* ]]
then
echo "detected an http url"
pass=0
else
pass=1
fi
done
desc="$aitext<\/span>"
echo "$desc"
fi
cp -v "template.html" "$pageName"
sed -i -e "s/;IMG;/..\/assets\/$imageLocation\/$imageName/g" "$pageName"
sed -i -e "s/;TITLE;/$name/g" "$pageName"
sed -i -e "s/;PRICE;/$price/g" "$pageName"
#sed -i -e "s/;DESC;/$desc/g" "$pageName"
perl -pe "s/;DESC;/$desc/" -i "$pageName" || sed -i -e "s/;DESC;/$desc/g" "$pageName" || sed -i -e "s/;DESC;/$name/g" "$pageName"
sed -i -e "//a \n