Change placeholder fallback logic (#61)

* Remove placeholder fallback

* Iteration

* Update documentation with new fallback behavior
This commit is contained in:
Franck Nijhof 2020-03-29 13:16:01 +02:00 committed by GitHub
parent 32983c2b92
commit b51a4013f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 15 deletions

View file

@ -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

View file

@ -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"}

View file

@ -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