Skip to content

Commit dae528f

Browse files
authored
feat: expose application name and logo url via meta properties (#9900)
1 parent 2d1b353 commit dae528f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

site/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<title>Coder</title>
1414
<meta name="viewport" content="width=device-width, initial-scale=1" />
1515
<meta name="theme-color" content="#17172E" />
16-
<meta name="application-name" content="Coder" />
16+
<meta name="application-name" content="{{ .ApplicationName }}" />
1717
<meta property="og:type" content="website" />
1818
<meta property="csrf-token" content="{{ .CSRF.Token }}" />
1919
<meta property="build-info" content="{{ .BuildInfo }}" />
@@ -23,6 +23,7 @@
2323
<meta property="experiments" content="{{ .Experiments }}" />
2424
<meta property="regions" content="{{ .Regions }}" />
2525
<meta property="docs-url" content="{{ .DocsURL }}" />
26+
<meta property="logo-url" content="{{ .LogoURL }}" />
2627
<!-- We need to set data-react-helmet to be able to override it in the workspace page -->
2728
<link
2829
rel="alternate icon"

site/site.go

+20
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ type htmlState struct {
232232
CSRF csrfState
233233

234234
// Below are HTML escaped JSON strings of the respective structs.
235+
ApplicationName string
236+
LogoURL string
237+
235238
BuildInfo string
236239
User string
237240
Entitlements string
@@ -313,6 +316,14 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
313316
SessionTokenFunc: nil,
314317
})
315318
if !ok || apiKey == nil || actor == nil {
319+
var cfg codersdk.AppearanceConfig
320+
if h.AppearanceFetcher != nil {
321+
// nolint:gocritic // User is not expected to be signed in.
322+
ctx := dbauthz.AsSystemRestricted(r.Context())
323+
cfg, _ = h.AppearanceFetcher(ctx)
324+
}
325+
state.ApplicationName = applicationNameOrDefault(cfg)
326+
state.LogoURL = cfg.LogoURL
316327
return execTmpl(tmpl, state)
317328
}
318329

@@ -368,6 +379,8 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
368379
appearance, err := json.Marshal(cfg)
369380
if err == nil {
370381
state.Appearance = html.EscapeString(string(appearance))
382+
state.ApplicationName = applicationNameOrDefault(cfg)
383+
state.LogoURL = cfg.LogoURL
371384
}
372385
}
373386
}()
@@ -841,3 +854,10 @@ func (b *binHashCache) getHash(name string) (string, error) {
841854
//nolint:forcetypeassert
842855
return strings.ToLower(v.(string)), nil
843856
}
857+
858+
func applicationNameOrDefault(cfg codersdk.AppearanceConfig) string {
859+
if cfg.ApplicationName != "" {
860+
return cfg.ApplicationName
861+
}
862+
return "Coder"
863+
}

0 commit comments

Comments
 (0)