Skip to content
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
10 changes: 2 additions & 8 deletions app/web/views/components/vapplication/list.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import (
"github.com/cloudness-io/cloudness/app/utils/routes"
"github.com/cloudness-io/cloudness/app/web/views/components/icons"
"github.com/cloudness-io/cloudness/app/web/views/shared"
"github.com/cloudness-io/cloudness/helpers"
"github.com/cloudness-io/cloudness/types"
"strings"
)

func trimProtocol(url string) string {
url = strings.TrimPrefix(url, "https://")
url = strings.TrimPrefix(url, "http://")
return strings.TrimSuffix(url, "/")
}

templ appHeaderDescription(env *types.Environment) {
<span>
You are viewing applications in <b><i>{ env.Name }</i></b> Environment
Expand Down Expand Up @@ -50,7 +44,7 @@ templ list(env *types.Environment, apps []*types.Application) {
<span onClick="event.stopPropagation()">
if app.Domain != "" {
<a class="text-foreground-light hover:text-foreground inline-flex items-center gap-1 text-xs" href={ templ.SafeURL(app.Domain) } target="_blank">
<span class="truncate max-w-40 md:max-w-72 lg:max-w-96">{ trimProtocol(app.Domain) }</span>
<span class="truncate max-w-40 md:max-w-72 lg:max-w-96">{ helpers.TrimProtocol(app.Domain) }</span>
@shared.Icon(icons.OutIcon, "size-3 shrink-0")
</a>
}
Expand Down
10 changes: 2 additions & 8 deletions app/web/views/components/vfavorite/list.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package vfavorite
import "github.com/cloudness-io/cloudness/types"
import "github.com/cloudness-io/cloudness/app/web/views/shared"
import "github.com/cloudness-io/cloudness/app/utils/routes"
import "strings"
import "github.com/cloudness-io/cloudness/app/web/views/components/icons"
import "github.com/cloudness-io/cloudness/helpers"

templ ListPlaceholder(tenant *types.Tenant) {
@shared.PageSection("Favorites", templ.NopComponent, templ.NopComponent) {
Expand Down Expand Up @@ -46,7 +46,7 @@ templ List(favs []*types.FavoriteDTO) {
<span onClick="event.stopPropagation();">
if fav.AppDomain != "" {
<a class="text-foreground-light hover:text-foreground inline-flex items-center gap-1 text-xs" href={ templ.SafeURL(fav.AppDomain) } target="_blank">
<span class="truncate max-w-40 md:max-w-72 lg:max-w-96">{ trimProtocol(fav.AppDomain) }</span>
<span class="truncate max-w-40 md:max-w-72 lg:max-w-96">{ helpers.TrimProtocol(fav.AppDomain) }</span>
@shared.Icon(icons.OutIcon, "size-3 shrink-0")
</a>
}
Expand All @@ -59,9 +59,3 @@ templ List(favs []*types.FavoriteDTO) {
</div>
}
}

func trimProtocol(url string) string {
url = strings.TrimPrefix(url, "https://")
url = strings.TrimPrefix(url, "http://")
return strings.TrimSuffix(url, "/")
}
23 changes: 23 additions & 0 deletions helpers/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ func ParseFQDN(fqdn string) (scheme string, subdomain string, domain string) {
func GenerateFQDN(schema string, subdomain string, domain string) string {
return schema + "://" + subdomain + "." + domain
}

// TrimProtocol removes http/https prefixes and any trailing slashes, preserving host and path.
func TrimProtocol(raw string) string {
trimmed := strings.TrimSpace(raw)
if trimmed == "" {
return ""
}

lower := strings.ToLower(trimmed)
switch {
case strings.HasPrefix(lower, "https://"):
trimmed = trimmed[len("https://"):]
case strings.HasPrefix(lower, "http://"):
trimmed = trimmed[len("http://"):]
default:
if u, err := url.Parse(trimmed); err == nil && u.Scheme != "" {
// Fallback for other schemes (keeps host/path, drops scheme)
trimmed = strings.TrimPrefix(trimmed, u.Scheme+"://")
}
}

return strings.TrimRight(trimmed, "/")
}
Loading