Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set favicon default url to /favicon.ico and allow to customize it #713

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/datafeeder/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"tsConfig": "apps/datafeeder/tsconfig.app.json",
"aot": true,
"assets": [
"apps/datafeeder/src/favicon.ico",
"apps/datafeeder/src/assets",
{
"glob": "*",
Expand Down
1 change: 0 additions & 1 deletion apps/datafeeder/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<title>Datafeeder</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=Permanent+Marker&display=swap"
Expand Down
1 change: 0 additions & 1 deletion apps/datahub/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"polyfills": "apps/datahub/src/polyfills.ts",
"tsConfig": "apps/datahub/tsconfig.app.json",
"assets": [
"apps/datahub/src/favicon.ico",
"apps/datahub/src/assets",
{
"glob": "*",
Expand Down
11 changes: 9 additions & 2 deletions apps/datahub/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Component } from '@angular/core'
import { Component, OnInit } from '@angular/core'
import { getThemeConfig } from '@geonetwork-ui/util/app-config'
import { ThemeService } from '@geonetwork-ui/util/shared'

@Component({
selector: 'datahub-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {}
export class AppComponent implements OnInit {
ngOnInit(): void {
const favicon = getThemeConfig().FAVICON
if (favicon) ThemeService.setFavicon(favicon)
}
}
Binary file removed apps/datahub/src/assets/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion apps/datahub/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<title>Datahub</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down
4 changes: 4 additions & 0 deletions conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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']


### VISUAL THEME

# All parameters are expressed in CSS format, see:
Expand Down Expand Up @@ -61,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
2 changes: 2 additions & 0 deletions libs/util/app-config/src/lib/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export function loadAppConfig() {
'fonts_stylesheet_url',
'thumbnail_placeholder',
'header_background',
'favicon',
],
warnings,
errors
Expand All @@ -204,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
1 change: 1 addition & 0 deletions libs/util/app-config/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,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)
}
}
Loading