-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_append.sh
51 lines (47 loc) · 1.5 KB
/
version_append.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# This is used to help with file caching.
# Most browsers cache JS file, meaning that when a new version is pushed
# perople visiting the page will load the cached JS file, thus
# not seeing any of the changes from the update.
# This appends a hash to each local path in index.html and /dist.elm.js
# meaning that files can be cached for arbitrarily long amounts of time
# but still detect and load new versions when changed on the server
# this script is run automatically as part of the dockerfile
shopt -s globstar
#changeFiles='./public/css/blur.css ./public/dist/elm.js ./public/index.html'
changeFiles=("./public/css/blur.css")
for file in $changeFiles
do
files=()
paths=()
j=0
for i in ./public/**/*
do
if [ -f "$i" ];
then
#printf "Path: %s\n" "${i##/*}" # shortest suffix removal
hash=`sha256sum "${i##/*}" | awk '{ print $1 }'`
#hash= sha256sum "${i}"
noSrc=${i/'./src'/} # remove src
noPublic=${noSrc/'./public'/}
if [[ $noPublic == /* ]]
then
paths[$j]="${noPublic}"
files[$j]="$noPublic?v=${hash:0:12}"
j=$((j+1))
fi
fi
done
# Update the html and elm files
modify=`cat $file`
echo $modify
for i in $(seq 0 $j)
do
old_name=${paths[$i]}
new_name=${files[$i]}
modify=${modify//$old_name/$new_name}
done
echo "----------"
echo $modify
#echo $modify > $file
done