diff --git a/content/static/html/pages/overview.tmpl b/content/static/html/pages/overview.tmpl index fe6f3fe43..d8afd19f8 100644 --- a/content/static/html/pages/overview.tmpl +++ b/content/static/html/pages/overview.tmpl @@ -19,12 +19,12 @@

Source Code

diff --git a/internal/frontend/server.go b/internal/frontend/server.go index 451ff57da..88558544f 100644 --- a/internal/frontend/server.go +++ b/internal/frontend/server.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" "sync" "time" @@ -437,6 +438,20 @@ func executeTemplate(ctx context.Context, templateName string, tmpl *template.Te return buf.Bytes(), nil } +// removeURLScheme removes schemes from the URL +func removeURLScheme(urlString string) (string, error) { + baseURL, err := url.Parse(urlString) + if err != nil { + return baseURL.String(), fmt.Errorf("Error parsing URL: %q", baseURL.String()) + } + scheme := baseURL.Scheme + if len(scheme) > 0 { + urlWithoutScheme := strings.Replace(baseURL.String(), scheme, "", 1) + return strings.Replace(urlWithoutScheme, "://", "", 1), nil + } + return baseURL.String(), nil +} + // parsePageTemplates parses html templates contained in the given base // directory in order to generate a map of Name->*template.Template. // @@ -477,6 +492,7 @@ func parsePageTemplates(base template.TrustedSource) (map[string]*template.Templ "commaseparate": func(s []string) string { return strings.Join(s, ", ") }, + "removeURLScheme": removeURLScheme, }).ParseFilesFromTrustedSources(join(base, tsc("base.tmpl"))) if err != nil { return nil, fmt.Errorf("ParseFiles: %v", err)