55 lines
1.8 KiB
Bash
55 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Generate the index.html with the content of the latest posts
|
|
declare index_file
|
|
declare number_of_index_articles
|
|
declare cut_do
|
|
declare cut_line
|
|
declare template_read_more
|
|
declare template_archive
|
|
declare template_subscribe
|
|
declare template_tags_title
|
|
declare blog_feed
|
|
declare global_author
|
|
declare global_feedburner
|
|
declare global_title
|
|
declare archive_index
|
|
declare tags_index
|
|
rebuild_index() {
|
|
|
|
echo -n "Rebuilding the index "
|
|
newindexfile=$index_file.$RANDOM
|
|
contentfile=$newindexfile.content
|
|
while [[ -f $newindexfile ]]; do
|
|
newindexfile=$index_file.$RANDOM
|
|
contentfile=$newindexfile.content
|
|
done
|
|
|
|
# Create the content file
|
|
{
|
|
n=0
|
|
while IFS='' read -r i; do
|
|
is_boilerplate_file "$i" && continue
|
|
if ((n >= number_of_index_articles)); then break; fi
|
|
if [[ -n $cut_do ]]; then
|
|
get_html_file_content 'entry' 'entry' 'cut' <"$i" | awk "/$cut_line/ { print \"<p class=\\\"readmore\\\"><a href=\\\"$i\\\">$template_read_more</a></p>\" ; next } 1"
|
|
else
|
|
get_html_file_content 'entry' 'entry' <"$i"
|
|
fi
|
|
echo -n "." 1>&3
|
|
n=$((n + 1))
|
|
done < <(ls -t ./*.html) # sort by date, newest first
|
|
|
|
feed=$blog_feed
|
|
if [[ -n $global_feedburner ]]; then feed=$global_feedburner; fi
|
|
echo "<div id=\"all_posts\"><a href=\"$archive_index\">$template_archive</a> — <a href=\"$tags_index\">$template_tags_title</a> — <a href=\"$feed\">$template_subscribe</a></div>"
|
|
} 3>&1 >"$contentfile"
|
|
|
|
echo ""
|
|
|
|
create_html_page "$contentfile" "$newindexfile" yes "$global_title" "$global_author"
|
|
rm "$contentfile"
|
|
mv "$newindexfile" "$index_file"
|
|
chmod 644 "$index_file"
|
|
}
|