85123: Fallback to favicon of default theme and src/assets/images/favicon.ico

This commit is contained in:
Bruno Roemers
2021-11-24 12:18:45 +01:00
parent 99a2cf926a
commit 893a306da0
2 changed files with 31 additions and 7 deletions

View File

@@ -292,20 +292,44 @@ export class AppComponent implements OnInit, AfterViewInit {
const themeConfig = this.themeService.getThemeConfigFor(themeName); const themeConfig = this.themeService.getThemeConfigFor(themeName);
const headTagConfigs = themeConfig?.headTags; const headTagConfigs = themeConfig?.headTags;
// if the current theme does not have head tags, we inherit the head tags of the parent
if (isEmpty(headTagConfigs)) { if (isEmpty(headTagConfigs)) {
const parentThemeName = themeConfig.extends; const parentThemeName = themeConfig.extends;
return isNotEmpty(parentThemeName) ? this.createHeadTags(parentThemeName) : []; if (isNotEmpty(parentThemeName)) {
// inherit the head tags of the parent theme
return this.createHeadTags(parentThemeName);
}
const defaultThemeName = DEFAULT_THEME_CONFIG.name;
if (
isEmpty(defaultThemeName) ||
themeName === defaultThemeName ||
themeName === BASE_THEME_NAME
) {
// last resort, use fallback favicon.ico
return [
this.createHeadTag({
'tagName': 'link',
'attributes': {
'rel': 'icon',
'href': 'assets/images/favicon.ico',
'sizes': 'any',
}
})
];
}
// inherit the head tags of the default theme
return this.createHeadTags(DEFAULT_THEME_CONFIG.name);
} }
return headTagConfigs.map(this.createHeadTag.bind(this)); return headTagConfigs.map(this.createHeadTag.bind(this));
} }
private createHeadTag(themeHeadTag: HeadTagConfig): HTMLElement { private createHeadTag(headTagConfig: HeadTagConfig): HTMLElement {
const tag = this.document.createElement(themeHeadTag.tagName); const tag = this.document.createElement(headTagConfig.tagName);
if (isNotEmpty(themeHeadTag.attributes)) { if (isNotEmpty(headTagConfig.attributes)) {
Object.entries(themeHeadTag.attributes) Object.entries(headTagConfig.attributes)
.forEach(([key, value]) => tag.setAttribute(key, value)); .forEach(([key, value]) => tag.setAttribute(key, value));
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB