From e494fc6c357243445bcf6c80cd0064a38f26112e Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Fri, 26 Dec 2025 09:56:06 -0600 Subject: [PATCH] Auto fill crate version in web page The webpage has a placeholder string instead of a hard-coded version. This gets replaced by the Makefile with the help of a pair of `sed` calls. And with that, I've upgraded my ad-hoc web bundler with an ad-hoc HTML templating engine. --- Makefile | 8 ++++++++ www/index.html | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 742d0290..aec9b22d 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,14 @@ CARGO_PROFILE := wasm-release # Override DESTDIR to set a custom install path (such as your web root) DESTDIR ?= . +# # # Automatic Variables # # # +# (meaning you shouldn't modify them yourself) +# +# These are for automatically finding information or files so that they can be +# used somewhere in the build process. SRC_DIR = ./src SRCS := $(wildcard $(SRC_DIR)/**) +CRATE_VERSION != sed -nre 's/^version = "(.*)"/\1/p' Cargo.toml .PHONY: clean full-clean install tarball tarball-standalone web web-standalone @@ -48,11 +54,13 @@ out/boids.js out/boids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/ano out/index.html: www/index.html cp -a $< $@ rm -f out/boids.html + sed -i -e "s/#CRATE_VERSION_PLACEHOLDER#/$(CRATE_VERSION)/" $@ # Like `out/index.html`, but renames it for use in a larger site. out/boids.html: www/index.html cp -a $< $@ rm -f out/index.html + sed -i -e "s/#CRATE_VERSION_PLACEHOLDER#/$(CRATE_VERSION)/" $@ # Clean the web build, but not the Cargo cache. Cargo handles it's own caching # and I don't want to obliterate it all the time. diff --git a/www/index.html b/www/index.html index bf856e1d..4c15d1e8 100644 --- a/www/index.html +++ b/www/index.html @@ -103,8 +103,7 @@ Program Version - - v0.6.0 + #CRATE_VERSION_PLACEHOLDER#