This commit is contained in:
John Haverlack 2026-02-05 15:05:28 -09:00
parent 2d6cd827c5
commit 76c876f644
3 changed files with 7 additions and 120 deletions

View File

@ -1,60 +0,0 @@
#!/usr/bin/env bash
# Usage: scripts/build-frontmatter.sh conf/metadata.yaml templates/frontmatter.html conf/frontmatter.html
# Description:
# Reads templates/frontmatter.html or templates/frontmatter.tex
# Replaces all $key$ with values from metadata.yaml
# Writes result to conf/frontmatter.html or frontmatter.tex
# Requirements:
# metadata.yaml must be flat (key: value)
set -euo pipefail
META_FILE="$1"
TEMPLATE_FILE="$2"
OUTPUT_FILE="$3"
TEMP_FILE="scripts/tmp/frontmatter.tmp"
# Check arguments
echo " META_FILE: $META_FILE"
echo " TEMPLATE_FILE: $TEMPLATE_FILE"
echo " OUTPUT_FILE: $OUTPUT_FILE"
echo " TEMP_FILE: $TEMP_FILE"
echo ""
# Start fresh output
cp "$TEMPLATE_FILE" "$OUTPUT_FILE"
# Load metadata into Bash associative array
declare -A META
while IFS= read -r line; do
# skip empty or comment lines
[[ -z "$line" || "$line" =~ ^# ]] && continue
key=$(echo "$line" | cut -d ':' -f 1 | xargs)
val=$(echo "$line" | cut -d ':' -f 2- | xargs) # capture full value after first colon, trim spaces
# strip surrounding quotes if present
val="${val%\"}"
val="${val#\"}"
META["$key"]="$val"
done < "$META_FILE"
# Read template line by line and substitute
for key in "${!META[@]}"; do
# Strip leading/trailing whitespace and quotes
val="${META[$key]}"
val="${val%\"}" # remove trailing "
val="${val#\"}" # remove leading "
val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" # trim spaces safely
# Escape special chars for sed
esc_val=$(printf '%s' "$val" | sed -e 's/[\/&$]/\\&/g')
search_key="\$${key}\$"
echo " Replacing ${search_key}${val}"
sed -i "s|\\\$${key}\\\$|${val}|g" "$OUTPUT_FILE"
# ls -l "$OUTPUT_FILE"
done
echo "✅ Rendered: $OUTPUT_FILE"

View File

@ -1,51 +0,0 @@
#!/usr/bin/env bash
set -e
REQ_PKGS=(
make
pandoc
texlive
texlive-xetex
texlive-latex-extra
texlive-fonts-recommended
texlive-fonts-extra
lmodern
epubcheck
)
echo "==> Checking and installing build dependencies"
install_pkg() {
PKG="$1"
if dpkg -s "$PKG" >/dev/null 2>&1; then
echo "$PKG already installed"
else
echo " Installing $PKG"
sudo apt-get install -y "$PKG"
fi
}
echo "==> Updating package index"
sudo apt-get update -y
for PKG in "${REQ_PKGS[@]}"; do
install_pkg "$PKG"
done
echo ""
echo "==> Verifying MathJax directory..."
if [ -d "lib/mathjax" ]; then
echo " ✅ MathJax directory exists"
else
echo " ❌ MathJax directory missing!"
echo " Please restore lib/mathjax/ or re-clone repo"
exit 1
fi
echo ""
echo "🎉 Build environment ready."
echo "Try building with:"
echo " make pdf"
echo " make html"
echo " make epub"
echo ""

16
scripts/new-project.sh Normal file → Executable file
View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash
# Usage: scripts/new-project.sh <project-directory>
set -euo pipefail
# Check arguments
@ -8,16 +7,15 @@ if [ "$#" -ne 1 ]; then
exit 1
fi
# Gets Script Directory
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
B3_DIR=$( cd -- "$( dirname -- "$SCRIPT_DIR/.." )" &> /dev/null && pwd )
# Resolve directories
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
B3_DIR="$( cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd )"
# Create project directory
PROJECT_DIR="$1"
mkdir -p "$PROJECT_DIR"
echo "$SCRIPT_DIR"
echo "$B3_DIR"
echo "Script dir: $SCRIPT_DIR"
echo "Template root: $B3_DIR"
# Copy B3 template to project directory
#rsync -av --exclude ".git" "$B3_DIR/" "$PROJECT_DIR"
# Copy template (excluding .git)
# rsync -av --exclude ".git" "$B3_DIR/" "$PROJECT_DIR"