Skip to content

feat: expose application name and logo url via meta properties #9900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" />
Expand All @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
}
}()
Expand Down Expand Up @@ -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"
}