build: testing new build

This commit is contained in:
Dave Kerr
2025-03-31 08:10:24 +01:00
parent d6a7d4eac3
commit c1c7f013e7
7 changed files with 150 additions and 131 deletions

View File

@@ -1,32 +1,33 @@
#!/usr/bin/env bash
# This script prepares a `hacker-laws.md` file for export to PDF or e-book format.
# Require a version number and get the current date.
version=$1
date=$(date "+%Y-%m-%d")
# Fail on errors.
set -e -o pipefail
if [ -z "$version" ]; then
echo "Usage: $0 <version>"
# Check if parameters are provided
input="$1"
output="$2"
if [ -z "${input}" ] || [ -z "${output}" ]; then
echo "usage: $(basename "$0") <input> <output>" >&2
echo " input: source markdown file (usually README.md)" >&2
echo " output: output markdown file (usually hacker-laws.md)" >&2
exit 1
fi
# Create `hacker-laws.md` with frontmatter and README content in one step.
cat << EOF > hacker-laws.md
---
title: "Hacker Laws"
author: "Dave Kerr, github.com/dwmkerr/hacker-laws"
subtitle: "Laws, Theories, Principles, and Patterns that developers will find useful. ${version}, ${date}."
---
# Grab env vars used to configure output, fail if required are missing.
export date="${DATE:-$(date +%F)}"
export version="${VERSION?error: VERSION must be set}"
EOF
cat README.md >> hacker-laws.md
# Update the input file to an intermedate.
intermediate="${input}.temp"
DATE="${date}" VERSION="${version}" envsubst < "${input}" > "${intermediate}"
# Use a single `sed` command to clean up unwanted lines and emojis in one pass.
sed -i'' -e '/💻📖.*/d' \
sed -e '/💻📖.*/d' \
-e 's/❗/Warning/g' \
-e '/^\[Translations.*/d' \
-e '/\*.*/d' \
-e '/ \*.*/d' \
-e '/## Translations/,$d' hacker-laws.md
-e '/## Translations/,$d' "${intermediate}" > "${output}"
rm "${intermediate}"
echo "hacker-laws.md prepared successfully."
echo "${output} prepared successfully."