feat(ui): Allow configuring meta description (#342)

* feat: add description prop to HTML template

* feat: add desc property to backend config validation

* test: add desc field to ui config test

* chore: add default description text

* test: add test for description default

* docs: add description config option explanation

* Update README.md

* Update config/ui/ui_test.go

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
David Wheatley 2022-11-01 05:33:19 +01:00 committed by GitHub
parent fe4d9821f3
commit 22d74a5ea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 66 deletions

View File

@ -158,7 +158,7 @@ If you want to test it locally, see [Docker](#docker).
## Configuration ## Configuration
| Parameter | Description | Default | | Parameter | Description | Default |
|:------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------| | :---------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------- |
| `debug` | Whether to enable debug logs. | `false` | | `debug` | Whether to enable debug logs. | `false` |
| `metrics` | Whether to expose metrics at /metrics. | `false` | | `metrics` | Whether to expose metrics at /metrics. | `false` |
| `storage` | [Storage configuration](#storage) | `{}` | | `storage` | [Storage configuration](#storage) | `{}` |
@ -197,6 +197,7 @@ If you want to test it locally, see [Docker](#docker).
| `web.port` | Port to listen on. | `8080` | | `web.port` | Port to listen on. | `8080` |
| `ui` | UI configuration. | `{}` | | `ui` | UI configuration. | `{}` |
| `ui.title` | [Title of the document](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title). | `Health Dashboard ǀ Gatus` | | `ui.title` | [Title of the document](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title). | `Health Dashboard ǀ Gatus` |
| `ui.description` | Meta description for the page. | `Gatus is an advanced...`. |
| `ui.header` | Header at the top of the dashboard. | `Health Status` | | `ui.header` | Header at the top of the dashboard. | `Health Status` |
| `ui.logo` | URL to the logo to display. | `""` | | `ui.logo` | URL to the logo to display. | `""` |
| `ui.link` | Link to open when the logo is clicked. | `""` | | `ui.link` | Link to open when the logo is clicked. | `""` |
@ -205,7 +206,6 @@ If you want to test it locally, see [Docker](#docker).
| `ui.buttons[].link` | Link to open when the button is clicked. | Required `""` | | `ui.buttons[].link` | Link to open when the button is clicked. | Required `""` |
| `maintenance` | [Maintenance configuration](#maintenance). | `{}` | | `maintenance` | [Maintenance configuration](#maintenance). | `{}` |
### Conditions ### Conditions
Here are some examples of conditions you can use: Here are some examples of conditions you can use:

View File

@ -10,6 +10,7 @@ import (
const ( const (
defaultTitle = "Health Dashboard | Gatus" defaultTitle = "Health Dashboard | Gatus"
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"
defaultHeader = "Health Status" defaultHeader = "Health Status"
defaultLogo = "" defaultLogo = ""
defaultLink = "" defaultLink = ""
@ -22,6 +23,7 @@ var (
// Config is the configuration for the UI of Gatus // Config is the configuration for the UI of Gatus
type Config struct { type Config struct {
Title string `yaml:"title,omitempty"` // Title of the page Title string `yaml:"title,omitempty"` // Title of the page
Description string `yaml:"description,omitempty"` // Meta description of the page
Header string `yaml:"header,omitempty"` // Header is the text at the top of the page Header string `yaml:"header,omitempty"` // Header is the text at the top of the page
Logo string `yaml:"logo,omitempty"` // Logo to display on the page Logo string `yaml:"logo,omitempty"` // Logo to display on the page
Link string `yaml:"link,omitempty"` // Link to open when clicking on the logo Link string `yaml:"link,omitempty"` // Link to open when clicking on the logo
@ -46,6 +48,7 @@ func (btn *Button) Validate() error {
func GetDefaultConfig() *Config { func GetDefaultConfig() *Config {
return &Config{ return &Config{
Title: defaultTitle, Title: defaultTitle,
Description: defaultDescription,
Header: defaultHeader, Header: defaultHeader,
Logo: defaultLogo, Logo: defaultLogo,
Link: defaultLink, Link: defaultLink,
@ -57,6 +60,9 @@ func (cfg *Config) ValidateAndSetDefaults() error {
if len(cfg.Title) == 0 { if len(cfg.Title) == 0 {
cfg.Title = defaultTitle cfg.Title = defaultTitle
} }
if len(cfg.Description) == 0 {
cfg.Description = defaultDescription
}
if len(cfg.Header) == 0 { if len(cfg.Header) == 0 {
cfg.Header = defaultHeader cfg.Header = defaultHeader
} }

View File

@ -8,6 +8,7 @@ import (
func TestConfig_ValidateAndSetDefaults(t *testing.T) { func TestConfig_ValidateAndSetDefaults(t *testing.T) {
cfg := &Config{ cfg := &Config{
Title: "", Title: "",
Description: "",
Header: "", Header: "",
Logo: "", Logo: "",
Link: "", Link: "",
@ -18,6 +19,9 @@ func TestConfig_ValidateAndSetDefaults(t *testing.T) {
if cfg.Title != defaultTitle { if cfg.Title != defaultTitle {
t.Errorf("expected title to be %s, got %s", defaultTitle, cfg.Title) t.Errorf("expected title to be %s, got %s", defaultTitle, cfg.Title)
} }
if cfg.Description != defaultDescription {
t.Errorf("expected description to be %s, got %s", defaultDescription, cfg.Description)
}
if cfg.Header != defaultHeader { if cfg.Header != defaultHeader {
t.Errorf("expected header to be %s, got %s", defaultHeader, cfg.Header) t.Errorf("expected header to be %s, got %s", defaultHeader, cfg.Header)
} }

View File

@ -11,7 +11,7 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.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="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico" />
<meta property="description" content="Gatus is an advanced automated status page that lets you monitor your applications and configure alerts to notify you if there's an issue" /> <meta property="description" content="{{ .Description }}" />
</head> </head>
<body class="dark:bg-gray-900"> <body class="dark:bg-gray-900">
<noscript><strong>Enable JavaScript to view this page.</strong></noscript> <noscript><strong>Enable JavaScript to view this page.</strong></noscript>