From ef0dbb91bac64531b9ef94c6af27b36b2f0c19b2 Mon Sep 17 00:00:00 2001 From: PrivacyDev Date: Sat, 10 Dec 2022 00:12:57 -0500 Subject: [PATCH] added script to download and serve fonts locally by default --- Dockerfile | 3 ++- localizefonts.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100755 localizefonts.sh diff --git a/Dockerfile b/Dockerfile index 68e50f0d..881f371a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,9 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/yarn \ --mount=type=cache,target=/app/node_modules \ + pkg add curl && \ 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 diff --git a/localizefonts.sh b/localizefonts.sh new file mode 100755 index 00000000..1d211f19 --- /dev/null +++ b/localizefonts.sh @@ -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/*