From 3bc07f896526062a35b3d856edbcb0a429f2d82c Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 5 Mar 2020 21:14:12 +0100 Subject: [PATCH] Add build scripts --- .gitignore | 1 + netlify.toml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/build.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 .gitignore create mode 100644 netlify.toml create mode 100755 scripts/build.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..07ed7069 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/* \ No newline at end of file diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000..bd5a6203 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,48 @@ +[build] + publish = "build" + command = "bash ./scripts/build.sh" + +[[headers]] + for = "/_placeholder/*.png" + [headers.values] + Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate" + +[[headers]] + for = "/*.png" + [headers.values] + Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate" + +[[redirects]] + from = "/" + to = "https://github.com/home-assistant/brands" + force = true + status = 301 + headers = {Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate"} + +[[redirects]] + from = "/*/icon.png" + to = "/_placeholder/icon.png" + force = false + status = 302 + headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"} + +[[redirects]] + from = "/*/logo.png" + to = "/_placeholder/logo.png" + force = false + status = 302 + headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"} + +[[redirects]] + from = "/*/icon@2x.png" + to = "/_placeholder/icon@2x.png" + force = false + status = 302 + headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"} + +[[redirects]] + from = "/*/logo@2x.png" + to = "/_placeholder/logo@2x.png" + force = false + status = 302 + headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"} diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 00000000..ac917c08 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Copy folder, without symlinks, but use actual files instead +rsync -aL --exclude '_homeassistant' src/ build + +# Use icon as logo in case of a missing logo +find ./build -type f -name "icon.png" | while read icon; do + dir=$(dirname "${icon}") + if [[ ! -f "${dir}/logo.png" ]]; then + cp "${icon}" "${dir}/logo.png" + echo "Using ${icon} as logo" + fi +done + +# Use icon as icon@2x in case it is missing +find ./build -type f -name "icon.png" | while read icon; do + dir=$(dirname "${icon}") + if [[ ! -f "${dir}/icon@2x.png" ]]; then + cp "${icon}" "${dir}/icon@2x.png" + echo "Using ${icon} as hDPI icon" + fi +done + +# Use logo as logo@2x in case it is missing +find ./build -type f -name "logo.png" | while read logo; do + dir=$(dirname "${logo}") + if [[ ! -f "${dir}/logo@2x.png" ]]; then + cp "${logo}" "${dir}/logo@2x.png" + echo "Using ${logo} as hDPI logo" + fi +done