50 lines
1.7 KiB
Bash
50 lines
1.7 KiB
Bash
#!/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 "<h3>$template_archive_title</h3>"
|
|
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 "</ul>" # Don't close ul before first header
|
|
echo "<h4 class='allposts_header'>$month</h4>"
|
|
echo "<ul>"
|
|
prev_month=$month
|
|
fi
|
|
# Title
|
|
title=$(get_post_title "$i")
|
|
echo -n "<li><a href=\"$i\">$title</a> —"
|
|
# Date
|
|
date=$(LC_ALL=$date_locale date -r "$i" +"$date_format")
|
|
echo " $date</li>"
|
|
done < <(ls -t ./*.html)
|
|
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" "$archive_index.tmp" yes "$global_title — $template_archive_title" "$global_author"
|
|
mv "$archive_index.tmp" "$archive_index"
|
|
chmod 644 "$archive_index"
|
|
rm "$contentfile"
|
|
} |