Files
website/Makefile
Andrew Stryker 80ea5b1c2c Add shared libs directory to gitignore and Makefile
Configure statdown to write CSS/JS dependencies to static/libs/
so they are shared across posts, and ignore that directory in git.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 21:36:00 -07:00

113 lines
3.3 KiB
Makefile

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#
#> Manage building Hugo website
#>
#> Andrew Stryker <axs@sdf.org>
#>
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#-----------------------------------------------------------------------------#
#
# Configuration
#
#-----------------------------------------------------------------------------#
SHELL = /usr/bin/bash
DEST ?= axs@sdf.org:html
SITE_URL ?= https://axs.sdf.org
HUGO_SERVE_FLAGS ?= --buildDrafts
hugo_serve_cmd = hugo server ${HUGO_SERVE_FLAGS}
help_generator = generate-help.awk
#-----------------------------------------------------------------------------#
#
# Define user interface
#
#-----------------------------------------------------------------------------#
.PHONY: default help publish build
default: build
build: .build_sentinel #> Build site with Hugo (default)
publish: build #> Publish site
@echo "📰Publishing..."
@# rsync options:
@# verbose: show each operation
@# links: preserve symlinks
@# safe-links: ignore symlinks that point outside of tree
@# times: preserve modification times
@# delete: delete extraneous files, i.e., files on destination
@# chmod: set permsions
@echo "\t 📡 Copying from public to ${DEST}"
@rsync \
--verbose \
--recursive \
--links \
--safe-links \
--times \
--delete \
--chmod=D755,F644 \
public/ \
${DEST}
@echo "\t 🛡️ Setting permissions"
@ssh axs@sdf.org 'mkhomepg -p'
@echo "✓ Publising complete"
@echo "\nThe site should be available on ${SITE_URL}"
serve: #> Start a Hugo server
@if [[ -z $${TMUX} ]]; \
then \
echo not tmux; \
else \
echo Starting a Hugo server in a new Tmux window; \
tmux neww ${hugo_serve_cmd}; \
fi
help: #> Generate this help message
@gawk -f ${help_generator} $(MAKEFILE_LIST)
#-----------------------------------------------------------------------------#
#
# Rmd rendering via statdown
#
#-----------------------------------------------------------------------------#
# Discover all Rmd source files and derive their .md targets
RMD_SOURCES := $(wildcard content/posts/*/index.Rmd)
MD_TARGETS := $(RMD_SOURCES:.Rmd=.md)
# Shared asset location for CSS/JS dependencies (via depkit)
LIBS_DIR := static/libs
LIBS_URL := /libs
# Pattern rule: render index.md from index.Rmd using statdown
# Re-render when renv.lock changes (package version update)
# Assets are written to static/libs/ so they are shared across posts
%/index.md: %/index.Rmd renv.lock
@echo "🔄 Rendering $<"
cd $* && Rscript -e 'renv::restore(prompt = FALSE); statdown::statdown_render("index.Rmd", output_root = "$(CURDIR)/$(LIBS_DIR)", url_root = "$(LIBS_URL)")'
#-----------------------------------------------------------------------------#
#
# Define file interface
#
#-----------------------------------------------------------------------------#
.build_sentinel: $(MD_TARGETS) $(wildcard content/*/*)
@echo "\t 🏗️ Building site"
@# We call hugo with two options:
@# --cleanDestinationDir, to remove deleted files
@# --minify, to compress files my removing extra whitespace
hugo --cleanDestinationDir --minify
@touch $@
@echo "✓ Building complete"
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#