do our best to trim the domain str
Jes Olson j3s@c3f.net
Mon, 20 Mar 2023 21:49:32 -0700
1 files changed,
7 insertions(+),
3 deletions(-)
jump to
M
site.go
→
site.go
@@ -307,10 +307,14 @@ // prints the base domain, otherwise returning the
// unmodified string func (s *Site) printDomain(rawURL string) string { parsedURL, err := url.Parse(rawURL) - if err != nil { - return "" + if err == nil { + return parsedURL.Hostname() } - return parsedURL.Hostname() + // do our best to trim it manually if url parsing fails + trimmedStr := strings.TrimPrefix(rawURL, "http://") + trimmedStr = strings.TrimPrefix(trimmedStr, "https://") + + return strings.Split(trimmedStr, "/")[0] } // renderErr sets the correct http status in the header,