generate array of file time stamps for production

This commit is contained in:
Murphy 2024-09-25 14:42:59 -04:00
parent 290a58fdb0
commit a8b7f0d0db
Signed by: freya
GPG key ID: 744AB800E383AE52
5 changed files with 37 additions and 5 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
src/public/css/*.css
!src/public/css/prism.css
src/web/stamp.php
data

View file

@ -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

14
build/stamp.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
out="./src/web/stamp.php"
public="./src/public"
files=$(find "$public" -type f -printf %P\\n)
printf "<?php\n\$__stamps = array();\n" > "$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"

View file

@ -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;
}
/**

View file

@ -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() {