47 lines
1.5 KiB
Bash
47 lines
1.5 KiB
Bash
#!/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 "<h3>$template_tags_title</h3>"
|
|
echo "<ul>"
|
|
# 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 "<li><a href=\"$i\">$tagname</a> — $nposts $word</li>"
|
|
done
|
|
echo "" 1>&3
|
|
echo "</ul>"
|
|
echo "<div id=\"all_posts\"><a href=\"./$index_file\">$template_archive_index_page</a></div>"
|
|
} 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"
|
|
} |