#!/bin/sh
# site title (part of ${pagetitle} probably).
sitetitle="Martin Brien"
# site language.
sitelang="en"
# main site domain.
sitedomain="http://www.martinbrien.com"
# relative site url, can be "/blog" or something.
siteurlrel=""
# full site url.
siteurlfull="${sitedomain}${siteurlrel}"
# site keywords (global default), don't use too many.
sitekeywords="blog, suckless, dwm-hiltjo"
# site description (global default).
sitedescription="blog with various projects and articles about computer-related things"
# site mail used for contact "mail link".
sitemail="martin@martinbrien.com"
# site author (global).
siteauthor="hiltjo"
# site last updated (default use date when script was run).
siteupdated=$(date "+%Y-%m-%dT%H:%M:%SZ")
# directories containing content and metadata.
# NOTE: it's recommended to use absolute paths here, use "." for current directory.
pagesdir="pages"
# Output dir.
outputdir="output"
# Markdown processor: default: is "smu".
markdown="smu"
#gnudate(fmt,date)
gnudate() {
date "+$1" -d "$2"
}
#bsddate(fmt,date)
bsddate() {
date -j "+$1" "$(printf '%s' "$2" | tr -Cd '[:digit:]')"
}
# added for compatibility with GNU and BSD date.
alias formatdate='gnudate'
if ! gnudate '%Y' '2015-01-01 00:00' 2>/dev/null; then
alias formatdate='bsddate'
fi
#makeid(title), format "Some title" to "some-title".
makeid() {
printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | \
sed -e 's@[^[:alnum:]]\{1,\}@-@g' -e 's@-*$@@g' -e 's@^-*@@g'
}
# initial values for page variables, use some site vars as global defaults.
pagereset() {
id=""
title=""
url=""
description="${sitedescription}"
keywords="${sitekeywords}"
author="${siteauthor}"
content=""
tags=""
categories=""
timecreated=""
datecreated=""
timeupdated=""
dateupdated=""
}
pageread() {
meta="$1"
. "${meta}" # source page metadata.
basename=$(basename "${meta}" ".sh")
datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10)
dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10)
# if ${id} is empty and title is set: create id based on title.
if test -z "${id}" && test -n "${title}"; then
id=$(makeid "${title}")
fi
if test -z "${id}"; then
printf 'Warning: $id or $title not set in "%s", skipping...\n' "${meta}" >&2
return 1
fi
if test -z "${url}"; then
url="${id}.html"
fi
outfile="${id}.html"
urlfull="${siteurlfull}/${outfile}"
filename=""
# ${content} not set; try data from filetypes.
if test -z "${content}"; then
if test -f "${pagesdir}/${basename}.html"; then
filename="${pagesdir}/${basename}.html"
content=$(cat "${filename}")
elif test -f "${pagesdir}/${basename}.md"; then
filename="${pagesdir}/${basename}.md"
content=$("${markdown}" "${filename}")
fi
fi
# created="Created on: ${datecreated}
"
# if test "${datecreated}" != "${dateupdated}"; then
# created="${created}Last update on: ${dateupdated}
"
# fi
}
pageheader() {
# prefix page title with site title, make sure its neatly formatted.
if test -z "${title}"; then
pagetitle="${sitetitle}"
else
pagetitle="${title} - ${sitetitle}"
fi
cat <