mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +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>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<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="csrf-token" content="{{ .CSRF.Token }}" />
|
||||
<meta property="build-info" content="{{ .BuildInfo }}" />
|
||||
@ -23,6 +23,7 @@
|
||||
<meta property="experiments" content="{{ .Experiments }}" />
|
||||
<meta property="regions" content="{{ .Regions }}" />
|
||||
<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 -->
|
||||
<link
|
||||
rel="alternate icon"
|
||||
|
20
site/site.go
20
site/site.go
@ -232,6 +232,9 @@ type htmlState struct {
|
||||
CSRF csrfState
|
||||
|
||||
// Below are HTML escaped JSON strings of the respective structs.
|
||||
ApplicationName string
|
||||
LogoURL string
|
||||
|
||||
BuildInfo string
|
||||
User string
|
||||
Entitlements string
|
||||
@ -313,6 +316,14 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
|
||||
SessionTokenFunc: 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)
|
||||
}
|
||||
|
||||
@ -368,6 +379,8 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
|
||||
appearance, err := json.Marshal(cfg)
|
||||
if err == nil {
|
||||
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
|
||||
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