#!/usr/bin/env bash
# Create an index page with all the tags
declare tags_index
declare template_tags_posts
declare template_tags_posts_singular
declare template_tags_posts_2_4
declare template_tags_title
declare prefix_tags
declare index_file
declare template_archive_index_page
declare global_author
declare global_title
all_tags() {
echo -n "Creating an index page with all the tags "
contentfile=$tags_index.$RANDOM
while [[ -f $contentfile ]]; do
contentfile=$tags_index.$RANDOM
done
{
echo "
$template_tags_title
"
echo ""
# shellcheck disable=SC2231 # Intended splitting of $prefix_tags
for i in $prefix_tags*.html; do
[[ -f "$i" ]] || break
echo -n "." 1>&3
nposts=$(grep -c "<\!-- text begin -->" "$i")
tagname=${i#"$prefix_tags"}
tagname=${tagname%.html}
case $nposts in
1) word=$template_tags_posts_singular;;
2|3|4) word=$template_tags_posts_2_4;;
*) word=$template_tags_posts;;
esac
echo "- $tagname — $nposts $word
"
done
echo "" 1>&3
echo "
"
echo ""
} 3>&1 > "$contentfile"
create_html_page "$contentfile" "$tags_index.tmp" yes "$global_title — $template_tags_title" "$global_author"
mv "$tags_index.tmp" "$tags_index"
chmod 644 "$tags_index"
rm "$contentfile"
}