added script to download and serve fonts locally by default

This commit is contained in:
PrivacyDev 2022-12-10 00:12:57 -05:00
parent a91531efa4
commit ef0dbb91ba
2 changed files with 12 additions and 1 deletions

View file

@ -6,8 +6,9 @@ COPY . .
RUN --mount=type=cache,target=/root/.cache/yarn \ RUN --mount=type=cache,target=/root/.cache/yarn \
--mount=type=cache,target=/app/node_modules \ --mount=type=cache,target=/app/node_modules \
pkg add curl && \
yarn install --prefer-offline && \ yarn install --prefer-offline && \
yarn build && sed -i 's/fonts.gstatic.com/fonts.kavin.rocks/g' dist/assets/*.css yarn build && ./localizefonts.sh
FROM nginx:alpine FROM nginx:alpine

10
localizefonts.sh Executable file
View file

@ -0,0 +1,10 @@
#/bin/sh
base='https://fonts\.(gstatic\.com|kavin\.rocks)'
fonts=$(cat dist/assets/* | grep -Po "$base[^)]*" | sort | uniq)
for font in $fonts; do
file="dist/fonts$(echo $font | sed "s#$base##")"
mkdir -p "$(dirname "$file")"
curl -L "$font" -o "$file"
done
sed -i "s#$base#/fonts#g" dist/assets/*