Standardize page header/footer generation

master
Hugo Thunnissen 2 years ago
parent 66a7de0291
commit 1bb57e222b

@ -24,7 +24,7 @@ if ! [[ -f "$posts_file" ]]; then
exit 1
fi
link-back-from-root() {
link-back-to-root() {
declare root="$1" directory="$2"
directory="${directory#$root}"
@ -47,62 +47,53 @@ html-to-text() {
html2text -nobs -style compact "$@"
}
print-blog-html-top() {
echo '<html>
<head>
<title>Blog</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
</head>
<body>
<div style="display: flex; flex-direction: horizontal;">
<a href="index.html">Home</a>
<span style="margin-left: 1em; margin-right: 1em;">|</span>
<a href="feed.xml">RSS Feed</a>
</div>
<h1>Blog</h1>
'
}
print-blog-html-bottom() {
echo ' </body>
</html>'
timestamp() {
date +'%s'
}
rfc-822-date-time() {
LC_ALL=C date "$@" --rfc-email
}
print-post-html-top() {
print-html-top() {
declare title="$1" root="$2" directory="$3"
declare backlink=''
backlink="$(link-back-to-root "$root" "$directory")" || return $?
cat <<EOF
<!DOCTYPE HTML>
<html>
<head>
<title>${title}</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
<link rel="stylesheet" type="text/css" href="${backlink}style.css">
<meta charset="UTF-8">
</head>
<body>
<div style="display: flex; flex-direction: horizontal;">
<a href="$(link-back-from-root "$root" "$directory")blog.html">Blog</a>
<span style="margin-left: 1em; margin-right: 1em;">|</span>
<a href="../../feed.xml">RSS Feed</a>
</div>
<nav style="display: flex; flex-direction: horizontal;">
<div class="navitem"><a href="${backlink}index.html">Home</a></div>
<div class="navitem"><a href="${backlink}blog.html">Blog</a></div>
<div class="navitem"><a href="${backlink}feed.xml">RSS Feed</a></div>
</nav>
<article>
EOF
}
print-html-bottom() {
echo '</article>
</body>
</html>'
}
print-post-html-bottom() {
declare publish_date="$1" last_edit_date="$2"
cat <<EOF
<span class="publish-date">
<section class="publish-date">
<i>First published: ${publish_date}</i><br>
<i>Last edited: ${last_edit_date}</i>
</span>
</section>
</article>
</body>
</html>
@ -154,7 +145,7 @@ el-enclose() {
}
publish-html() {
declare root="$1" source_dir="$2" publish_dir="$3" contents="$4"
declare root="$1" source_dir="$2" publish_dir="$3" contents="$4" title="$5"
declare pubdate_file="$source_dir/publish_date.txt" \
checksum_file="$source_dir/last_checksum.txt" \
@ -162,13 +153,13 @@ publish-html() {
current_checksum=''
current_checksum="$(cksum <<<"$contents")"
declare checksum=''
declare checksum='' pubdate='' last_edit_date=''
# Determine a publishing date for the post
if [[ -f "$pubdate_file" ]]; then
read -r pubdate < "$pubdate_file"
else
pubdate="$(date)"
pubdate="$(timestamp)"
echo "$pubdate" > "$pubdate_file"
fi
@ -184,23 +175,26 @@ publish-html() {
fi
if [[ "$checksum" != "$current_checksum" ]]; then
last_edit_date="$(date)"
last_edit_date="$(timestamp)"
echo "$last_edit_date" > "$last_edit_file"
echo "$current_checksum" > "$checksum_file"
fi
declare pubdate='' last_edit_date=''
if [[ -z $last_edit_date ]]; then
last_edit_date="$pubdate"
fi
# Convert publishing date to be conform RFC 822
pubdate="$(rfc-822-date-time --date="$pubdate")" || return $?
last_edit_date="$(rfc-822-date-time --date="$last_edit_date")" || return $?
pubdate="$(rfc-822-date-time --date="@$pubdate")" || return $?
last_edit_date="$(rfc-822-date-time --date="@$last_edit_date")" || return $?
declare index_file="$publish_dir/index.html"
if [[ "$checksum" != "$current_checksum" ]] || ! [[ -f "$index_file" ]]; then
printf 'Publishing to %s\n' "$index_file" >&2
mkdir -p "$publish_dir" || return $?
print-post-html-top "$title" "$root" "$publish_dir" > "$index_file"
print-html-top "$title" "$root" "$publish_dir" > "$index_file"
printf '%s\n' "$contents" >> "$index_file"
print-post-html-bottom "$pubdate" "$last_edit_date" >> "$index_file"
fi
@ -218,7 +212,7 @@ new_rss="$blog_rss.new"
mkdir -p "$publish_dir" || exit $?
print-blog-html-top > "$new_html"
print-html-top 'Blog' "$publish_dir" "$publish_dir" > "$new_html"
print-blog-rss-top > "$new_rss"
while read -r post_html_path; do
@ -243,7 +237,7 @@ while read -r post_html_path; do
post_publish_dir="$publish_dir/posts/$(basename "$post_dir")" || exit $?
read -rd '' post_html < "$post_html_path" || true
publish-html "$publish_dir" "$post_dir" "$post_publish_dir" "$post_html" || exit $?
publish-html "$publish_dir" "$post_dir" "$post_publish_dir" "$post_html" "$title" || exit $?
{
el 'div class="blog-feed-item"'
@ -271,14 +265,16 @@ while read -r post_html_path; do
} >> "$new_rss"
done < "$posts_file"
print-blog-html-bottom >> "$new_html"
print-html-bottom >> "$new_html"
print-blog-rss-bottom >> "$new_rss"
mv -v "$new_html" "$blog_html" || exit $?
mv -v "$new_rss" "$blog_rss" || exit $?
cp -v "$here/style.css" "$publish_dir/style.css"
cp -v "$here/index.html" "$publish_dir/index.html"
read -rd '' index_html < "$here/index/index.html" || true
publish-html "$publish_dir" "$here/index" "$publish_dir" "$index_html" "Hugo's Homepage"
cp -rv "$here/assets" "$publish_dir/assets"

@ -1,66 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Hugot</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
</head>
<body>
<a href="blog.html">Blog</a>
<h1>Hugo's homepage</h1>
<p>
Hello and welcome to my personal homepage! I'll add some info about my
projects to this page soon. In the mean time, maybe take a look at
my <a href="blog.html">blog</a>
</p>
<p>
Other places you can find me at on the web:
<ul>
<li><a rel="me" href="https://mstdn.social/@hugot">Fediverse</a></li>
<li><a href="https://github.com/hugot/">GitHub</a></li>
<li><a href="https://git.snorba.art/hugo/">ᕦ⊙෴⊙ᕤ baart</a></li>
</ul>
</p>
<div class="cardbox">
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
</div>
</body>
</html>
<!-- Local Variables: -->
<!-- sgml-basic-offset: 1 -->
<!-- End: -->

@ -0,0 +1,53 @@
<h1>Hugo's Homepage</h1>
<p>
Hello and welcome to my personal homepage! I'll add some info about my
projects to this page soon. In the mean time, maybe take a look at
my <a href="blog.html">blog</a>
</p>
<p>
Other places you can find me at on the web:
<ul>
<li><a rel="me" href="https://mstdn.social/@hugot">Fediverse</a></li>
<li><a href="https://github.com/hugot/">GitHub</a></li>
<li><a href="https://git.snorba.art/hugo/">ᕦ⊙෴⊙ᕤ baart</a></li>
</ul>
</p>
<div class="cardbox">
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
<div class="card">
<header>dns-yml</header>
<p>
Manage DNS records through version controlled yaml files.
</p>
</div>
</div>
<!-- Local Variables: -->
<!-- sgml-basic-offset: 1 -->
<!-- End: -->

@ -0,0 +1 @@
1891825100 1228

@ -1 +0,0 @@
Fri May 20 11:15:16 PM CEST 2022

@ -1 +1 @@
Sat 08 Feb 2020 09:30:06 AM CET
1581150606

@ -1 +0,0 @@
Fri May 20 11:25:14 PM CEST 2022

@ -1 +1 @@
Sat 08 Feb 2020 12:14:16 PM CET
1581160456

@ -1 +1 @@
Mon 17 Feb 2020 11:55:42 AM CET
1581936942

@ -2,6 +2,7 @@
:root {
--theme-bright: #f9f5eb;
--theme-text: #5b4636;
}
a:visited {
@ -37,6 +38,7 @@ aside {
.publish-date {
font-size: 14px;
margin-top: 1em;
}
code {
@ -52,6 +54,8 @@ code {
flex-direction: column;
justify-content: space-around;
margin: -0.5em;
margin-top: 0;
margin-bottom: 0;
flex-wrap: wrap;
}
@ -78,7 +82,6 @@ code {
.publish-date {
font-size: 12px;
}
aside {
@ -131,3 +134,15 @@ code {
color: #5b4636;
text-decoration: none;
}
nav .navitem {
padding-right: 0.5em;
}
nav .navitem + .navitem a {
padding-left: 0.5em;
}
nav .navitem + .navitem::before {
content: "|";
}

Loading…
Cancel
Save