From b51a4013f0dfa76f9c9a93566c75d6b372db930d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 29 Mar 2020 13:16:01 +0200 Subject: [PATCH] Change placeholder fallback logic (#61) * Remove placeholder fallback * Iteration * Update documentation with new fallback behavior --- README.md | 31 ++++++++++++++++++++++++++----- netlify.toml | 18 +++++++++--------- scripts/build.sh | 4 +++- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fd6b09fe..47df32df 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,35 @@ Those images are served in the following format: - `https://brands.home-assistant.io/[domain]/logo.png` - `https://brands.home-assistant.io/[domain]/icon@2x.png` - `https://brands.home-assistant.io/[domain]/logo@2x.png` +- `https://brands.home-assistant.io/_/[domain]/icon.png` +- `https://brands.home-assistant.io/_/[domain]/logo.png` +- `https://brands.home-assistant.io/_/[domain]/icon@2x.png` +- `https://brands.home-assistant.io/_/[domain]/logo@2x.png` ### Missing image handling -- If a domain is missing, the images from the `_placeholder` domain is served instead. -- If a domain is missing the `icon.png` file, the placeholder will be will be served instead. -- If a domain is missing the `logo.png` file, the `icon.png` is served instead. -- If a domain is missing the `icon@2.png` file, the `icon.png` is served instead. -- If a domain is missing the `logo@2.png` file, the `logo.png` is served instead. +The website can service images with and without a fallback to an placeholder +image. + +### Without placeholder fallback + +This method uses the plain URLs, **WITHOUT** the `/_/` in the URL path. +A missing image, will result in a 404 being served. + +For example: <`https://brands.home-assistant.io/[domain]/icon.png`> + +- If a domain is missing the `icon.png` file, 404 will be served +- If a domain is missing the `logo.png` file, the `icon.png` is served instead (if available). +- If a domain is missing the `icon@2.png` file, the `icon.png` is served instead (if available). +- If a domain is missing the `logo@2.png` file, the `logo.png` is served instead (if available). + +### With placeholder fallback + +This method uses the plain URLs, **WITH** the `/_/` in the URL path. +A missing image, will result in placeholder image being served telling the logo/icon is missing. +This also applies to domains, in case the integration domain is missing. + +For example: <`https://brands.home-assistant.io/_/[domain]/icon.png`> ### Caching diff --git a/netlify.toml b/netlify.toml index bd5a6203..01a45edd 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,7 +3,7 @@ command = "bash ./scripts/build.sh" [[headers]] - for = "/_placeholder/*.png" + for = "/_/_placeholder/*.png" [headers.values] Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate" @@ -20,29 +20,29 @@ headers = {Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate"} [[redirects]] - from = "/*/icon.png" - to = "/_placeholder/icon.png" + 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" + 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" + 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" + 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 index ac917c08..a5ac5e4f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash # Copy folder, without symlinks, but use actual files instead -rsync -aL --exclude '_homeassistant' src/ build +mkdir -p build/_ +rsync -aL --exclude '_homeassistant' src/ build/_ +rsync -aL --exclude '_homeassistant' --exclude '_placeholder' src/ build # Use icon as logo in case of a missing logo find ./build -type f -name "icon.png" | while read icon; do