web: improve loading of custom favicon

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-02 21:19:39 +02:00
parent 2f64b76eba
commit 974ddc07f7
4 changed files with 13 additions and 8 deletions

View File

@ -8,7 +8,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>{% block title %}{% trans title|default:tenant.branding_title %}{% endblock %}</title>
<link rel="icon" type="image/png" href="{% static 'dist/assets/icons/icon.png' %}?v={{ ak_version }}">
<link rel="shortcut icon" type="image/png" href="{% static 'dist/assets/icons/icon.png' %}?v={{ ak_version }}">
<link rel="stylesheet" type="text/css" href="{% static 'dist/patternfly-base.css' %}?v={{ ak_version }}">
<link rel="stylesheet" type="text/css" href="{% static 'dist/page.css' %}?v={{ ak_version }}">

View File

@ -26,10 +26,20 @@ let globalTenantPromise: Promise<CurrentTenant>;
export function tenant(): Promise<CurrentTenant> {
if (!globalTenantPromise) {
globalTenantPromise = new CoreApi(DEFAULT_CONFIG).coreTenantsCurrentRetrieve().then(tenant => {
const relIcon = document.head.querySelector<HTMLLinkElement>("link[rel=icon]");
if (relIcon) {
relIcon.href = tenant.brandingLogo;
/**
* <link rel="icon" href="/static/dist/assets/icons/icon.png">
* <link rel="shortcut icon" href="/static/dist/assets/icons/icon.png">
*/
const rels = ["icon", "shortcut icon"];
rels.forEach(rel => {
let relIcon = document.head.querySelector<HTMLLinkElement>("link[rel=icon]");
if (!relIcon) {
relIcon = document.createElement('link');
relIcon.rel = rel;
document.getElementsByTagName('head')[0].appendChild(relIcon);
}
relIcon.href = tenant.brandingLogo;
})
return tenant;
});
}

View File

@ -3,8 +3,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" type="image/png" href="/static/dist/assets/icons/icon.png">
<link rel="shortcut icon" type="image/png" href="/static/dist/assets/icons/icon.png">
<link rel="stylesheet" type="text/css" href="/static/dist/patternfly-base.css">
<link rel="stylesheet" type="text/css" href="/static/dist/page.css">
<link rel="stylesheet" type="text/css" href="/static/dist/empty-state.css">

View File

@ -3,8 +3,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" type="image/png" href="/static/dist/assets/icons/icon.png">
<link rel="shortcut icon" type="image/png" href="/static/dist/assets/icons/icon.png">
<link rel="stylesheet" type="text/css" href="/static/dist/patternfly-base.css">
<link rel="stylesheet" type="text/css" href="/static/dist/page.css">
<link rel="stylesheet" type="text/css" href="/static/dist/empty-state.css">