mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: expose application name and logo url via meta properties (#9900)
This commit is contained in:
@ -13,7 +13,7 @@
|
|||||||
<title>Coder</title>
|
<title>Coder</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#17172E" />
|
<meta name="theme-color" content="#17172E" />
|
||||||
<meta name="application-name" content="Coder" />
|
<meta name="application-name" content="{{ .ApplicationName }}" />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="csrf-token" content="{{ .CSRF.Token }}" />
|
<meta property="csrf-token" content="{{ .CSRF.Token }}" />
|
||||||
<meta property="build-info" content="{{ .BuildInfo }}" />
|
<meta property="build-info" content="{{ .BuildInfo }}" />
|
||||||
@ -23,6 +23,7 @@
|
|||||||
<meta property="experiments" content="{{ .Experiments }}" />
|
<meta property="experiments" content="{{ .Experiments }}" />
|
||||||
<meta property="regions" content="{{ .Regions }}" />
|
<meta property="regions" content="{{ .Regions }}" />
|
||||||
<meta property="docs-url" content="{{ .DocsURL }}" />
|
<meta property="docs-url" content="{{ .DocsURL }}" />
|
||||||
|
<meta property="logo-url" content="{{ .LogoURL }}" />
|
||||||
<!-- We need to set data-react-helmet to be able to override it in the workspace page -->
|
<!-- We need to set data-react-helmet to be able to override it in the workspace page -->
|
||||||
<link
|
<link
|
||||||
rel="alternate icon"
|
rel="alternate icon"
|
||||||
|
20
site/site.go
20
site/site.go
@ -232,6 +232,9 @@ type htmlState struct {
|
|||||||
CSRF csrfState
|
CSRF csrfState
|
||||||
|
|
||||||
// Below are HTML escaped JSON strings of the respective structs.
|
// Below are HTML escaped JSON strings of the respective structs.
|
||||||
|
ApplicationName string
|
||||||
|
LogoURL string
|
||||||
|
|
||||||
BuildInfo string
|
BuildInfo string
|
||||||
User string
|
User string
|
||||||
Entitlements string
|
Entitlements string
|
||||||
@ -313,6 +316,14 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
|
|||||||
SessionTokenFunc: nil,
|
SessionTokenFunc: nil,
|
||||||
})
|
})
|
||||||
if !ok || apiKey == nil || actor == nil {
|
if !ok || apiKey == nil || actor == nil {
|
||||||
|
var cfg codersdk.AppearanceConfig
|
||||||
|
if h.AppearanceFetcher != nil {
|
||||||
|
// nolint:gocritic // User is not expected to be signed in.
|
||||||
|
ctx := dbauthz.AsSystemRestricted(r.Context())
|
||||||
|
cfg, _ = h.AppearanceFetcher(ctx)
|
||||||
|
}
|
||||||
|
state.ApplicationName = applicationNameOrDefault(cfg)
|
||||||
|
state.LogoURL = cfg.LogoURL
|
||||||
return execTmpl(tmpl, state)
|
return execTmpl(tmpl, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,6 +379,8 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
|
|||||||
appearance, err := json.Marshal(cfg)
|
appearance, err := json.Marshal(cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
state.Appearance = html.EscapeString(string(appearance))
|
state.Appearance = html.EscapeString(string(appearance))
|
||||||
|
state.ApplicationName = applicationNameOrDefault(cfg)
|
||||||
|
state.LogoURL = cfg.LogoURL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -841,3 +854,10 @@ func (b *binHashCache) getHash(name string) (string, error) {
|
|||||||
//nolint:forcetypeassert
|
//nolint:forcetypeassert
|
||||||
return strings.ToLower(v.(string)), nil
|
return strings.ToLower(v.(string)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationNameOrDefault(cfg codersdk.AppearanceConfig) string {
|
||||||
|
if cfg.ApplicationName != "" {
|
||||||
|
return cfg.ApplicationName
|
||||||
|
}
|
||||||
|
return "Coder"
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user