#!/usr/bin/env bash
# Create an index page with all the posts
declare archive_index
declare template_archive_index_page
declare template_archive_title
declare date_allposts_header
declare date_format
declare date_locale
declare index_file
declare global_title
declare global_author
all_posts() {
echo -n "Creating an index page with all the posts "
contentfile=$archive_index.$RANDOM
while [[ -f $contentfile ]]; do
contentfile=$archive_index.$RANDOM
done
{
echo "
$template_archive_title
"
prev_month=""
while IFS='' read -r i; do
is_boilerplate_file "$i" && continue
echo -n "." 1>&3
# Month headers
month=$(LC_ALL=$date_locale date -r "$i" +"$date_allposts_header")
if [[ $month != "$prev_month" ]]; then
[[ -n $prev_month ]] && echo "" # Don't close ul before first header
echo ""
echo ""
prev_month=$month
fi
# Title
title=$(get_post_title "$i")
echo -n "- $title —"
# Date
date=$(LC_ALL=$date_locale date -r "$i" +"$date_format")
echo " $date
"
done < <(ls -t ./*.html)
echo "" 1>&3
echo "
"
echo ""
} 3>&1 >"$contentfile"
create_html_page "$contentfile" "$archive_index.tmp" yes "$global_title — $template_archive_title" "$global_author"
mv "$archive_index.tmp" "$archive_index"
chmod 644 "$archive_index"
rm "$contentfile"
}