Skip to content

Commit cc5e2f2

Browse files
committed
feat: Add UI configuration for custom favicon
Adds new node `favicon` to `ui` configuration with properties that allow to overwrite the three favicons which are currently in use in the index.html template. Closes #174 Signed-off-by: Mateusz Łoskot <[email protected]>
1 parent e2f06e9 commit cc5e2f2

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ If you want to test it locally, see [Docker](#docker).
264264
| `ui.header` | Header at the top of the dashboard. | `Gatus` |
265265
| `ui.logo` | URL to the logo to display. | `""` |
266266
| `ui.link` | Link to open when the logo is clicked. | `""` |
267+
| `ui.favicon.default` | Favourite default icon to display in web browser tab or address bar. | `/favicon.ico` |
268+
| `ui.favicon.size16x16` | Favourite icon to display in web browser for 16x16 size. | `/favicon-16x16.png` |
269+
| `ui.favicon.size32x32` | Favourite icon to display in web browser for 32x32 size. | `/favicon-32x32.png` |
267270
| `ui.buttons` | List of buttons to display below the header. | `[]` |
268271
| `ui.buttons[].name` | Text to display on the button. | Required `""` |
269272
| `ui.buttons[].link` | Link to open when the button is clicked. | Required `""` |

config/ui/ui.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
defaultCustomCSS = ""
1919
defaultSortBy = "name"
2020
defaultFilterBy = "none"
21+
defaultFavicon = "/favicon.ico"
22+
defaultFavicon16 = "/favicon-16x16.png"
23+
defaultFavicon32 = "/favicon-32x32.png"
2124
)
2225

2326
var (
@@ -40,6 +43,7 @@ type Config struct {
4043
DarkMode *bool `yaml:"dark-mode,omitempty"` // DarkMode is a flag to enable dark mode by default
4144
DefaultSortBy string `yaml:"default-sort-by,omitempty"` // DefaultSortBy is the default sort option ('name', 'group', 'health')
4245
DefaultFilterBy string `yaml:"default-filter-by,omitempty"` // DefaultFilterBy is the default filter option ('none', 'failing', 'unstable')
46+
Favicon Favicon `yaml:"favicon,omitempty"` // Favourite icon to display in web browser tab or address bar
4347

4448
//////////////////////////////////////////////
4549
// Non-configurable - used for UI rendering //
@@ -68,6 +72,12 @@ func (btn *Button) Validate() error {
6872
return nil
6973
}
7074

75+
type Favicon struct {
76+
Default string `yaml:"default,omitempty"` // URL or path to default favourite icon.
77+
Size16x16 string `yaml:"size16x16,omitempty"` // URL or path to favourite icon for 16x16 size.
78+
Size32x32 string `yaml:"size32x32,omitempty"` // URL or path to favourite icon for 32x32 size.
79+
}
80+
7181
// GetDefaultConfig returns a Config struct with the default values
7282
func GetDefaultConfig() *Config {
7383
return &Config{
@@ -81,6 +91,11 @@ func GetDefaultConfig() *Config {
8191
DefaultSortBy: defaultSortBy,
8292
DefaultFilterBy: defaultFilterBy,
8393
MaximumNumberOfResults: storage.DefaultMaximumNumberOfResults,
94+
Favicon: Favicon{
95+
Default: defaultFavicon,
96+
Size16x16: defaultFavicon16,
97+
Size32x32: defaultFavicon32,
98+
},
8499
}
85100
}
86101

@@ -117,6 +132,15 @@ func (cfg *Config) ValidateAndSetDefaults() error {
117132
} else if cfg.DefaultFilterBy != "none" && cfg.DefaultFilterBy != "failing" && cfg.DefaultFilterBy != "unstable" {
118133
return ErrInvalidDefaultFilterBy
119134
}
135+
if len(cfg.Favicon.Default) == 0 {
136+
cfg.Favicon.Default = defaultFavicon
137+
}
138+
if len(cfg.Favicon.Size16x16) == 0 {
139+
cfg.Favicon.Size16x16 = defaultFavicon16
140+
}
141+
if len(cfg.Favicon.Size32x32) == 0 {
142+
cfg.Favicon.Size32x32 = defaultFavicon32
143+
}
120144
for _, btn := range cfg.Buttons {
121145
if err := btn.Validate(); err != nil {
122146
return err

config/ui/ui_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ func TestConfig_ValidateAndSetDefaults(t *testing.T) {
3232
if cfg.DefaultFilterBy != defaultFilterBy {
3333
t.Errorf("expected defaultFilterBy to be %s, got %s", defaultFilterBy, cfg.DefaultFilterBy)
3434
}
35+
if cfg.Favicon.Default != defaultFavicon {
36+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon, cfg.Favicon.Default)
37+
}
38+
if cfg.Favicon.Size16x16 != defaultFavicon16 {
39+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon16, cfg.Favicon.Size16x16)
40+
}
41+
if cfg.Favicon.Size32x32 != defaultFavicon32 {
42+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon32, cfg.Favicon.Size32x32)
43+
}
3544
}
3645

3746
func TestButton_Validate(t *testing.T) {

web/app/public/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
2020
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
2121
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
22-
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
23-
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
22+
<link rel="icon" type="image/png" sizes="32x32" href="{{ .UI.Favicon.Size32x23 }}" />
23+
<link rel="icon" type="image/png" sizes="16x16" href="{{ .UI.Favicon.Size16x16 }}" />
2424
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
25-
<link rel="shortcut icon" href="/favicon.ico" />
25+
<link rel="shortcut icon" href="{{ .UI.Favicon.Default }}" />
2626
<link rel="stylesheet" href="/css/custom.css" />
2727
<meta name="description" content="{{ .UI.Description }}" />
2828
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

web/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
} else {
99
document.documentElement.classList.remove('dark');
1010
}
11-
})();</script><title>{{ .UI.Title }}</title><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"/><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"/><link rel="shortcut icon" href="/favicon.ico"/><link rel="stylesheet" href="/css/custom.css"/><meta name="description" content="{{ .UI.Description }}"/><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/><meta name="apple-mobile-web-app-title" content="{{ .UI.Title }}"/><meta name="application-name" content="{{ .UI.Title }}"/><meta name="theme-color" content="#f7f9fb"/><script defer="defer" src="/js/chunk-vendors.js"></script><script defer="defer" src="/js/app.js"></script><link href="/css/app.css" rel="stylesheet"></head><body><noscript><strong>Enable JavaScript to view this page.</strong></noscript><div id="app"></div></body></html>
11+
})();</script><title>{{ .UI.Title }}</title><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="{{ .UI.Favicon.Size32x32 }}"/><link rel="icon" type="image/png" sizes="16x16" href="{{ .UI.Favicon.Size16x16 }}"/><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"/><link rel="shortcut icon" href="{{ .UI.Favicon.Default }}"/><link rel="stylesheet" href="/css/custom.css"/><meta name="description" content="{{ .UI.Description }}"/><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/><meta name="apple-mobile-web-app-title" content="{{ .UI.Title }}"/><meta name="application-name" content="{{ .UI.Title }}"/><meta name="theme-color" content="#f7f9fb"/><script defer="defer" src="/js/chunk-vendors.js"></script><script defer="defer" src="/js/app.js"></script><link href="/css/app.css" rel="stylesheet"></head><body><noscript><strong>Enable JavaScript to view this page.</strong></noscript><div id="app"></div></body></html>

0 commit comments

Comments
 (0)