#!/bin/bash
# Generate index HTML page
#
# Copyright (C) 2019 Mike Gerwitz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# The index page consists of post abstracts, some static text, and the
# static header and footer. All post metadata files must have been built,
# along with `post/list'.
#
# This script includes the static body (see `main').
##
set -euo pipefail
# Get the file name of the Nth most recent post. This relies on the
# existence of `post/list'.
pnfile()
{
local -ri n=${1?Missing relative post number}
sed "${n}q;d" post/list
}
# Read field FIELD from post metadata recfile FILE.
pmeta()
{
local -r file=${1?Missing file name}
local -r field=${2?Missing field name}
recsel -P "$field" "$file"
}
# Process each numeric argument using `abstract'. Each argument must be a
# relative post number (see `pnfile').
abstracts()
{
while [ $# -gt 0 ]; do
abstract "$1"
shift
done
}
# Generate HTML for relative post number N (see `pnfile').
abstract()
{
local -ri n=${1?Missing relative post number}
local file title date slug body
file=$( pnfile "$n" )
title=$( pmeta "$file" subject )
date=$( pmeta "$file" date )
slug=$( pmeta "$file" slug )
body=$( pmeta "$file" abstract )
cat <