#! /bin/bash
updates_list=()
output+=('
TRANSATLANTICISM updates\n')
output+=('\n')
output+=('\n')
DaySuffix() {
case `date -d "$date" +"%d"` in
1|21|31) echo "ST";;
2|22) echo "ND";;
3|23) echo "RD";;
*) echo "TH";;
esac
}
c=0
while IFS= read -r line; do
if [[ "$line" != "" ]]; then
current_entry+=("$line")
else
for line in "${current_entry[@]}"; do
eval "entry$c+=(\"$line\")"
done
current_entry=()
updates_list+=("entry$c")
c=$(( c + 1 ))
fi
done < "updates.txt"
for update in "${updates_list[@]}"; do
date="$(eval echo \${$update[0]})"
date="$(date -d "$date" +"%^b %-d`DaySuffix`, %Y")"
type="$(eval echo \${$update[1]})"
subtitle="$(eval echo \${$update[2]})"
content="$(eval echo \${$update[3]})"
output+=("$hr$type: $date
$subtitle
$content
\n")
hr="
\n"
done
recent_posts=("${output[@]:3:3}")
while IFS= read -r line; do
if [[ $line == "" ]]; then
line="${recent_posts[@]}"
fi
index_page+="$line\n"
done < "./pages/index_no_stream.html"
echo -e "$index_page" > "./pages/index.html"
output+=('\n')
echo -e "${output[@]}" > "./pages/updates.html"