From 3ccf330fdf6b75478a35be4020a687638e161e67 Mon Sep 17 00:00:00 2001 From: Laptop Date: Sun, 7 Sep 2025 00:31:39 +0300 Subject: [PATCH] styled code --- lib/preferences/init.go | 2 ++ templates/base.templ | 11 +++--- templates/featured.templ | 9 +++-- templates/playlist.templ | 16 ++++----- templates/preferences.templ | 16 ++++----- templates/tags.templ | 7 ++-- templates/track.templ | 71 ++++++++++++++++++++++++------------- templates/user.templ | 44 +++++++++++++++-------- 8 files changed, 107 insertions(+), 69 deletions(-) diff --git a/lib/preferences/init.go b/lib/preferences/init.go index a75f32b..6985c76 100644 --- a/lib/preferences/init.go +++ b/lib/preferences/init.go @@ -123,6 +123,7 @@ func setPrefs(c fiber.Ctx, p *cfg.Preferences) error { cookie.SetExpire(time.Now().Add(400 * 24 * time.Hour)) cookie.SetHTTPOnly(true) cookie.SetSameSite(fasthttp.CookieSameSiteStrictMode) + cookie.SetPath("/") c.Response().Header.SetCookie(cookie) fasthttp.ReleaseCookie(cookie) @@ -251,6 +252,7 @@ func Load(r *fiber.App) { cookie.SetExpire(time.Now().Add(400 * 24 * time.Hour)) cookie.SetHTTPOnly(true) cookie.SetSameSite(fasthttp.CookieSameSiteStrictMode) + cookie.SetPath("/") c.Response().Header.SetCookie(cookie) fasthttp.ReleaseCookie(cookie) diff --git a/templates/base.templ b/templates/base.templ index d5e64b3..ae4f2ca 100644 --- a/templates/base.templ +++ b/templates/base.templ @@ -11,11 +11,12 @@ templ Base(title string, content templ.Component, head templ.Component) { - if title != "" { - { title } ~ soundcloak - } else { - soundcloak - } + + if title != "" { + { title } ~ + } + soundcloak + if head != nil { @head } diff --git a/templates/featured.templ b/templates/featured.templ index 462e974..ce2dc29 100644 --- a/templates/featured.templ +++ b/templates/featured.templ @@ -12,12 +12,11 @@ templ PlaylistOrUserItem(pl *sc.PlaylistOrUser) { if pl.Kind == "user" { img = pl.Avatar } + if img == "" { + img = "/_/static/placeholder.jpg" + } }} - if img != "" { - - } else { - - } +
if pl.Kind == "user" {

{ pl.Username }

diff --git a/templates/playlist.templ b/templates/playlist.templ index 846b4dd..c9687b5 100644 --- a/templates/playlist.templ +++ b/templates/playlist.templ @@ -22,11 +22,15 @@ func playlist(t sc.Track, p sc.Playlist) string { templ PlaylistItem(playlist *sc.Playlist, showUsername bool) { + + src={ playlist.Artwork } } else { - + src="/_/static/placeholder.jpg" } + />

{ playlist.Title }

if showUsername { @@ -69,12 +73,8 @@ templ Playlist(prefs cfg.Preferences, p sc.Playlist) { }

{ strconv.FormatInt(p.Likes, 10) } likes


- if p.CreatedAt != "" { -

Created: { p.CreatedAt }

- } - if p.LastModified != "" { -

Last modified: { p.LastModified }

- } +

Created: { p.CreatedAt }

+

Last modified: { p.LastModified }

} diff --git a/templates/preferences.templ b/templates/preferences.templ index a14b02d..f62e642 100644 --- a/templates/preferences.templ +++ b/templates/preferences.templ @@ -3,11 +3,7 @@ package templates import "git.maid.zone/stuff/soundcloak/lib/cfg" templ checkbox(name string, checked bool) { - if checked { - - } else { - - } + } type option struct { @@ -21,11 +17,11 @@ type option struct { templ sel(name string, options []option, selected string) { } diff --git a/templates/tags.templ b/templates/tags.templ index 2f028d0..b8ddc6a 100644 --- a/templates/tags.templ +++ b/templates/tags.templ @@ -9,11 +9,14 @@ import ( templ TagsButtons(current string, tag string) {

diff --git a/templates/track.templ b/templates/track.templ index 875cb9a..ae1fc0c 100644 --- a/templates/track.templ +++ b/templates/track.templ @@ -24,19 +24,23 @@ func toExt(audio string) string { templ TrackButtons(current string, track sc.Track) {
for _, b := range [...]btn{{"related tracks", "/recommended", false, false},{"in albums", "/albums", false, false},{"in playlists", "/sets", false, false},{"track station", "/discover/sets/"+track.Station, true, false},{"view on soundcloud", "https://soundcloud.com"+track.Href(), true, true}} { + { b.text } + class="btn active" } else { - if b.external { - { b.text } + class="btn" + if b.override { + href={ templ.SafeURL(b.href) } } else { - if b.override { - { b.text } - } else { - { b.text } - } + href={ templ.SafeURL(track.Href() + b.href) } + } + if b.external { + referrerpolicy="no-referrer" + rel="external nofollow noopener noreferrer" + target="_blank" } } + >{ b.text } }
} @@ -47,10 +51,8 @@ templ TrackHeader(prefs cfg.Preferences, t sc.Track, needPlayer bool) { - if needPlayer { - if *prefs.Player == cfg.HLSPlayer { - - } + if needPlayer && *prefs.Player == cfg.HLSPlayer { + } } @@ -88,27 +90,42 @@ templ TrackPlayer(prefs cfg.Preferences, track sc.Track, stream string, displayE {{ var audioPref *string }} if cfg.Restream && *prefs.Player == cfg.RestreamPlayer { {{ audioPref = prefs.RestreamAudio }} + if nextTrack != nil { - - } else { - } if *prefs.KeepPlayerFocus { } } else if stream != "" { {{ audioPref = prefs.HLSAudio }} + - } else { - + data-next={ next(&track, nextTrack, playlist, mode, "") } + volume={ volume } } + > + + src="/_/static/player_preload.js" } else { - + src="/_/static/player.js" } + > if *prefs.KeepPlayerFocus { } @@ -150,11 +167,15 @@ templ TrackItem(track *sc.Track, showUsername bool, overrideHref string) { } }} + + src={ track.Artwork } } else { - + src="/_/static/placeholder.jpg" } + />

{ track.Title }

if showUsername { @@ -256,11 +277,13 @@ templ Track(prefs cfg.Preferences, t sc.Track, stream string, displayErr string, templ Comments(comments *sc.Paginated[*sc.Comment]) { for _, c := range comments.Collection {
+ + src={ c.Author.Avatar } } else { - + src="/_/static/placeholder.jpg" } + />

{ c.Body }

diff --git a/templates/user.templ b/templates/user.templ index 5f7da94..6a54c2d 100644 --- a/templates/user.templ +++ b/templates/user.templ @@ -17,11 +17,15 @@ templ UserHeader(u sc.User) { templ UserItem(user *sc.User) { + + src={ user.Avatar } } else { - + src="/_/static/placeholder.jpg" } + />

{ user.Username }

if user.FullName != "" { @@ -34,11 +38,19 @@ templ UserItem(user *sc.User) { templ UserLinks(links []sc.Link) { for _, link := range links { if len(link.URL) > 0 { - if link.URL[0] == '/' { -

- { link.Title }

- } else { -

- { link.Title }

- } +

+ - { link.Title } +

} } } @@ -84,19 +96,21 @@ templ UserButtons(current string, user sc.User) {
// this part is the tedious one now, because formatting breaks if i space the list out with newlines for _, b := range [...]btn{{"tracks", "", false, false},{"popular tracks", "/popular-tracks", false, false},{"playlists", "/sets", false, false},{"albums", "/albums", false, false},{"reposts","/reposts", false, false},{"related", "/_/related", false, false},{"user station", "/discover/sets/"+user.Station, true, false},{"view on soundcloud", "https://soundcloud.com/"+user.Permalink, true, true}} { + { b.text } + class="btn active" } else { - if b.external { - { b.text } + class="btn" + if b.override { + href={ templ.SafeURL(b.href) } } else { - if b.override { - { b.text } - } else { - { b.text } - } + href={ templ.SafeURL("/" + user.Permalink + b.href) } + } + if b.external { + referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank" } } + >{ b.text } }
}