From a8b7f0d0db2aa64efb6d176de321402d1f5e5bdb Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 25 Sep 2024 14:42:59 -0400 Subject: [PATCH] generate array of file time stamps for production --- .gitignore | 1 + Makefile | 19 ++++++++++++++++--- build/stamp.sh | 14 ++++++++++++++ src/web/core/core.php | 5 +++-- src/web/index.php | 3 +++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100755 build/stamp.sh diff --git a/.gitignore b/.gitignore index b9d6a5b..8084040 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ src/public/css/*.css !src/public/css/prism.css +src/web/stamp.php data diff --git a/Makefile b/Makefile index b8d5407..3184a9a 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,31 @@ MIXINS = $(shell find src/scss -name "_*.scss") SCSS = $(shell find src/scss -name "*.scss" -not -name "_*") CSS = $(patsubst src/scss/%.scss,src/public/css/%.css,$(SCSS)) -.PHONY: all css clean +.PHONY: all clean css stamp -css: $(CSS) +all: clean css stamp clean: + @# clean scss @printf "\033[31m RM \033[0m%s\n" src/public/css @rm -f src/public/css/*.css + @git stash -- src/public/css/prism.css > /dev/null -all: clean css + @# clean stamps + @printf "\033[31m RM \033[0m%s\n" src/web/stamp.php + @rm -f src/web/stamp.php + +# =============================================== COMPILE SCSS == + +css: $(CSS) $(CSS): src/public/css/%.css : src/scss/%.scss $(MIXINS) @printf "\033[33m SCSS \033[0m%s\n" $< @mkdir -p $(@D) @sassc --style compressed $< $@ +# ============================================ GENERATE STAMPS == + +stamp: + @printf "\033[32m STMP \033[0m%s\n" src/web/stamp.php + @./build/stamp.sh diff --git a/build/stamp.sh b/build/stamp.sh new file mode 100755 index 0000000..3b19b04 --- /dev/null +++ b/build/stamp.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +out="./src/web/stamp.php" +public="./src/public" +files=$(find "$public" -type f -printf %P\\n) + +printf " "$out" +for file in $files; do + stamp=$(date +%s -r "$public/$file") + echo "\$__stamps['public/$file'] = $stamp;" >> "$out"; +done +echo "define('FILE_TIMES', \$__stamps);" >> "$out" +echo "unset(\$__stamps);" >> "$out" + diff --git a/src/web/core/core.php b/src/web/core/core.php index f1ce07e..feaecdf 100644 --- a/src/web/core/core.php +++ b/src/web/core/core.php @@ -25,8 +25,9 @@ abstract class Core { { if (ENVIRONMENT == 'devlopment') return time(); - $path = PHP_ROOT . '/' . $path; - return @filemtime($path); + if (isset(FILE_TIMES[$path])) + return FILE_TIMES[$path]; + return 0; } /** diff --git a/src/web/index.php b/src/web/index.php index 63e5b61..577bc60 100644 --- a/src/web/index.php +++ b/src/web/index.php @@ -48,6 +48,9 @@ require(WEB_ROOT . '/core/controller.php'); require(WEB_ROOT . '/core/model.php'); require(WEB_ROOT . '/core/router.php'); +// load file stamps +require(WEB_ROOT . '/stamp.php'); + // ============================== START == function __init() {