tildelog/lib/create_html_page.sh

93 lines
3.3 KiB
Bash

#!/usr/bin/env bash
# Adds all the bells and whistles to format the html page
# Every blog post is marked with a <!-- entry begin --> and <!-- entry end -->
# which is parsed afterwards in the other functions. There is also a marker
# <!-- text begin --> to determine just the beginning of the text body of the post
#
# $1 a file with the body of the content
# $2 the output file
# $3 "yes" if we want to generate the index.html,
# "no" to insert new blog posts
# $4 title for the html header
# $5 original blog timestamp
# $6 post author
declare body_begin_file
declare date_inpost
declare date_locale
declare date_format
declare date_format_timestamp
declare global_url
declare body_end_file
create_html_page() {
content=$1
filename=$2
index=$3
title=$4
timestamp=$5
author=$6
# Create the actual blog post
# html, head
{
cat ".header.html"
echo "<title>$title</title>"
twitter_card "$content" "$title"
echo "</head><body>"
# stuff to add before the actual body content
[[ -n $body_begin_file ]] && cat "$body_begin_file"
# body divs
echo '<div id="divbodyholder">'
echo '<div class="headerholder"><div class="header">'
# blog title
echo '<div id="title">'
cat .title.html
echo '</div></div></div>' # title, header, headerholder
echo '<div id="divbody"><div class="content">'
file_url=${filename#./}
file_url=${file_url%.rebuilt} # Get the correct URL when rebuilding
file_url=${file_url%.html}
file_url=${file_url%.md}.html # Get the correct link
# one blog entry
if [[ $index == no ]]; then
echo '<!-- entry begin -->' # marks the beginning of the whole post
echo "<h3><a class=\"ablack\" href=\"$file_url\">"
# remove possible <p>'s on the title because of markdown conversion
title=${title//<p>/}
title=${title//<\/p>/}
echo "$title"
echo '</a></h3>'
if [[ -z $timestamp ]]; then
echo "<!-- $date_inpost: #$(LC_ALL=$date_locale date +"$date_format_timestamp")# -->"
else
echo "<!-- $date_inpost: #$(LC_ALL=$date_locale date +"$date_format_timestamp" --date="$timestamp")# -->"
fi
if [[ -z $timestamp ]]; then
echo -n "<div class=\"subtitle\">$(LC_ALL=$date_locale date +"$date_format")"
else
echo -n "<div class=\"subtitle\">$(LC_ALL=$date_locale date +"$date_format" --date="$timestamp")"
fi
[[ -n $author ]] && echo -e " &mdash; \n$author"
echo "</div>"
echo '<!-- text begin -->' # This marks the text body, after the title, date...
fi
cat "$content" # Actual content
if [[ $index == no ]]; then
echo -e '\n<!-- text end -->'
twitter "$global_url/$file_url"
echo '<!-- entry end -->' # absolute end of the post
fi
echo '</div>' # content
# page footer
cat .footer.html
# close divs
echo '</div></div>' # divbody and divbodyholder
[[ -n $body_end_file ]] && cat "$body_end_file"
echo '</body></html>'
} > "$filename"
}