Skip to content

Commit 42a3ad7

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 fc8868d commit 42a3ad7

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
@@ -238,6 +238,9 @@ If you want to test it locally, see [Docker](#docker).
238238
| `ui.title` | [Title of the document](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title). | `Health Dashboard ǀ Gatus` |
239239
| `ui.description` | Meta description for the page. | `Gatus is an advanced...`. |
240240
| `ui.header` | Header at the top of the dashboard. | `Health Status` |
241+
| `ui.favicon.default` | Favourite default icon to display in web browser tab or address bar. | `/favicon.ico` |
242+
| `ui.favicon.size16x16` | Favourite icon to display in web browser for 16x16 size. | `/favicon-16x16.png` |
243+
| `ui.favicon.size32x32` | Favourite icon to display in web browser for 32x32 size. | `/favicon-32x32.png` |
241244
| `ui.logo` | URL to the logo to display. | `""` |
242245
| `ui.link` | Link to open when the logo is clicked. | `""` |
243246
| `ui.buttons` | List of buttons to display below the header. | `[]` |

config/ui/ui.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const (
1212
defaultTitle = "Health Dashboard | Gatus"
1313
defaultDescription = "Gatus is an advanced automated status page that lets you monitor your applications and configure alerts to notify you if there's an issue"
1414
defaultHeader = "Health Status"
15+
defaultFavicon = "/favicon.ico"
16+
defaultFavicon16 = "/favicon-16x16.png"
17+
defaultFavicon32 = "/favicon-32x32.png"
1518
defaultLogo = ""
1619
defaultLink = ""
1720
defaultCustomCSS = ""
@@ -28,6 +31,7 @@ type Config struct {
2831
Title string `yaml:"title,omitempty"` // Title of the page
2932
Description string `yaml:"description,omitempty"` // Meta description of the page
3033
Header string `yaml:"header,omitempty"` // Header is the text at the top of the page
34+
Favicon Favicon `yaml:"favicon,omitempty"` // Favourite icon to display in web browser tab or address bar
3135
Logo string `yaml:"logo,omitempty"` // Logo to display on the page
3236
Link string `yaml:"link,omitempty"` // Link to open when clicking on the logo
3337
Buttons []Button `yaml:"buttons,omitempty"` // Buttons to display below the header
@@ -56,6 +60,12 @@ func (btn *Button) Validate() error {
5660
return nil
5761
}
5862

63+
type Favicon struct {
64+
Default string `yaml:"default,omitempty"` // URL or path to default favourite icon.
65+
Size16x16 string `yaml:"size16x16,omitempty"` // URL or path to favourite icon for 16x16 size.
66+
Size32x32 string `yaml:"size32x32,omitempty"` // URL or path to favourite icon for 32x32 size.
67+
}
68+
5969
// GetDefaultConfig returns a Config struct with the default values
6070
func GetDefaultConfig() *Config {
6171
return &Config{
@@ -66,6 +76,11 @@ func GetDefaultConfig() *Config {
6676
Link: defaultLink,
6777
CustomCSS: defaultCustomCSS,
6878
DarkMode: &defaultDarkMode,
79+
Favicon: Favicon{
80+
Default: defaultFavicon,
81+
Size16x16: defaultFavicon16,
82+
Size32x32: defaultFavicon32,
83+
},
6984
}
7085
}
7186

@@ -80,6 +95,15 @@ func (cfg *Config) ValidateAndSetDefaults() error {
8095
if len(cfg.Header) == 0 {
8196
cfg.Header = defaultHeader
8297
}
98+
if len(cfg.Favicon.Default) == 0 {
99+
cfg.Favicon.Default = defaultFavicon
100+
}
101+
if len(cfg.Favicon.Size16x16) == 0 {
102+
cfg.Favicon.Size16x16 = defaultFavicon16
103+
}
104+
if len(cfg.Favicon.Size32x32) == 0 {
105+
cfg.Favicon.Size32x32 = defaultFavicon32
106+
}
83107
if len(cfg.Logo) == 0 {
84108
cfg.Logo = defaultLogo
85109
}

config/ui/ui_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ func TestConfig_ValidateAndSetDefaults(t *testing.T) {
2525
if cfg.Header != defaultHeader {
2626
t.Errorf("expected header to be %s, got %s", defaultHeader, cfg.Header)
2727
}
28+
if cfg.Favicon.Default != defaultFavicon {
29+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon, cfg.Favicon.Default)
30+
}
31+
if cfg.Favicon.Size16x16 != defaultFavicon16 {
32+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon16, cfg.Favicon.Size16x16)
33+
}
34+
if cfg.Favicon.Size32x32 != defaultFavicon32 {
35+
t.Errorf("expected favicon to be %s, got %s", defaultFavicon32, cfg.Favicon.Size32x32)
36+
}
2837
}
2938

3039
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
@@ -9,10 +9,10 @@
99
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
1010
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
1111
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
12-
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
13-
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
12+
<link rel="icon" type="image/png" sizes="32x32" href="{{ .UI.Favicon.Size32x23 }}" />
13+
<link rel="icon" type="image/png" sizes="16x16" href="{{ .UI.Favicon.Size16x16 }}" />
1414
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
15-
<link rel="shortcut icon" href="/favicon.ico" />
15+
<link rel="shortcut icon" href="{{ .UI.Favicon.Default }}" />
1616
<link rel="stylesheet" href="/css/custom.css" />
1717
<meta name="description" content="{{ .UI.Description }}" />
1818
<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
@@ -1 +1 @@
1-
<!doctype html><html lang="en" class="{{ .Theme }}"><head><meta charset="utf-8"/><script>window.config = {logo: "{{ .UI.Logo }}", header: "{{ .UI.Header }}", link: "{{ .UI.Link }}", buttons: []};{{- range .UI.Buttons}}window.config.buttons.push({name:"{{ .Name }}",link:"{{ .Link }}"});{{end}}</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 class="dark:bg-gray-900"><noscript><strong>Enable JavaScript to view this page.</strong></noscript><div id="app"></div></body></html>
1+
<!doctype html><html lang="en" class="{{ .Theme }}"><head><meta charset="utf-8"/><script>window.config = {logo: "{{ .UI.Logo }}", header: "{{ .UI.Header }}", link: "{{ .UI.Link }}", buttons: []};{{- range .UI.Buttons}}window.config.buttons.push({name:"{{ .Name }}",link:"{{ .Link }}"});{{end}}</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 class="dark:bg-gray-900"><noscript><strong>Enable JavaScript to view this page.</strong></noscript><div id="app"></div></body></html>

0 commit comments

Comments
 (0)