Skip to content

Commit

Permalink
feat: move icon to theme section
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Jan 8, 2024
1 parent 739b2fa commit 2e5e813
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
17 changes: 4 additions & 13 deletions apps/datahub/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'
import { getGlobalConfig } from '@geonetwork-ui/util/app-config'
import { getThemeConfig } from '@geonetwork-ui/util/app-config'
import { ThemeService } from '@geonetwork-ui/util/shared'

@Component({
selector: 'datahub-root',
Expand All @@ -8,17 +9,7 @@ import { getGlobalConfig } from '@geonetwork-ui/util/app-config'
})
export class AppComponent implements OnInit {
ngOnInit(): void {
const favicon = getGlobalConfig().FAVICON
if (favicon) this.setFavicon(favicon)
}

private setFavicon(faviconPath: string): void {
const link =
document.querySelector("link[rel*='icon']") ||
document.createElement('link')
link['type'] = 'image/x-icon'
link['rel'] = 'icon'
link['href'] = faviconPath
document.getElementsByTagName('head')[0].appendChild(link)
const favicon = getThemeConfig().FAVICON
if (favicon) ThemeService.setFavicon(favicon)
}
}
5 changes: 3 additions & 2 deletions conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ proxy_path = ""
# More information about the translation can be found in the docs (https://geonetwork.github.io/geonetwork-ui/main/docs/reference/i18n.html)
# languages = ['en', 'fr', 'de']

# Use it to set custom location for favicon
# favicon = "assets/favicon.ico"

### VISUAL THEME

Expand Down Expand Up @@ -64,6 +62,9 @@ background_color = "#fdfbff"
# title_font = "'My Custom Title Font', fallback-font-title"
# fonts_stylesheet_url = "https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=Permanent+Marker&display=swap"

# Use it to set custom location for the favicon; by default, the path `/favicon.ico` will be used
# favicon = "assets/favicon.ico"

### SEARCH SETTINGS

# This section contains settings used for fine-tuning the search experience
Expand Down
4 changes: 2 additions & 2 deletions libs/util/app-config/src/lib/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function loadAppConfig() {
'login_url',
'web_component_embedder_url',
'languages',
'favicon',
],
warnings,
errors
Expand All @@ -127,7 +126,6 @@ export function loadAppConfig() {
WEB_COMPONENT_EMBEDDER_URL:
parsedGlobalSection.web_component_embedder_url,
LANGUAGES: parsedGlobalSection.languages,
FAVICON: parsedGlobalSection.favicon,
} as GlobalConfig)

const parsedLayersSections = parseMultiConfigSection(
Expand Down Expand Up @@ -187,6 +185,7 @@ export function loadAppConfig() {
'fonts_stylesheet_url',
'thumbnail_placeholder',
'header_background',
'favicon',
],
warnings,
errors
Expand All @@ -206,6 +205,7 @@ export function loadAppConfig() {
TITLE_FONT: parsedThemeSection.title_font,
MAIN_FONT: parsedThemeSection.main_font,
FONTS_STYLESHEET_URL: parsedThemeSection.fonts_stylesheet_url,
FAVICON: parsedThemeSection.favicon,
} as ThemeConfig)

const parsedSearchSection = parseConfigSection(
Expand Down
2 changes: 1 addition & 1 deletion libs/util/app-config/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface GlobalConfig {
LOGIN_URL?: string
WEB_COMPONENT_EMBEDDER_URL?: string
LANGUAGES?: string[]
FAVICON?: string
}

export interface LayerConfig {
Expand Down Expand Up @@ -38,6 +37,7 @@ export interface ThemeConfig {
MAIN_FONT?: string
TITLE_FONT?: string
FONTS_STYLESHEET_URL?: string
FAVICON?: string
}

export interface SearchPreset {
Expand Down
9 changes: 9 additions & 0 deletions libs/util/shared/src/lib/services/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ export class ThemeService {
}
return chroma.hsl(hue % 360, saturation, lightness).css()
}

static setFavicon(faviconPath: string): void {
const link =
document.querySelector("link[rel*='icon']") ||
document.createElement('link')
link['rel'] = 'icon'
link['href'] = faviconPath
document.getElementsByTagName('head')[0].appendChild(link)
}
}

0 comments on commit 2e5e813

Please sign in to comment.