Files
soundcloak/templates/playlist.templ
2025-02-03 19:43:16 +02:00

98 lines
2.6 KiB
Plaintext

package templates
import (
"git.maid.zone/stuff/soundcloak/lib/cfg"
"git.maid.zone/stuff/soundcloak/lib/sc"
"net/url"
"strconv"
"strings"
)
templ PlaylistHeader(p sc.Playlist) {
<meta name="og:site_name" content={ p.Author.Username + " ~ soundcloak" }/>
<meta name="og:title" content={ p.Title }/>
<meta name="og:description" content={ p.FormatDescription() }/>
<meta name="og:image" content={ p.Artwork }/>
<link rel="icon" type="image/x-icon" href={ p.Artwork }/>
}
func playlist(t sc.Track, p sc.Playlist) string {
return t.Href() + "?playlist=" + p.Href()[1:]
}
templ PlaylistItem(playlist *sc.Playlist, showUsername bool) {
<a class="listing" href={ templ.SafeURL(playlist.Href()) }>
if playlist.Artwork != "" {
<img src={ playlist.Artwork }/>
} else {
<img src="/_/static/placeholder.jpg"/>
}
<div class="meta">
<h3>{ playlist.Title }</h3>
if showUsername {
<span>{ playlist.Author.Username }</span>
}
<p>{ strconv.FormatInt(playlist.TracksCount(), 10) } tracks</p>
</div>
</a>
}
templ Playlist(prefs cfg.Preferences, p sc.Playlist) {
if p.Artwork != "" {
<img src={ p.Artwork } width="300px"/>
}
<h1>{ p.Title }</h1>
@UserItem(&p.Author)
<div style="display: flex;">
<a class="btn" href={ templ.SafeURL("https://soundcloud.com" + p.Href()) }>view on soundcloud</a>
</div>
<br/>
@Description(prefs, p.Description, nil)
<p>{ strconv.FormatInt(p.TracksCount(), 10) } tracks</p>
<br/>
<br/>
<div>
for _, track := range p.Tracks {
if *prefs.AutoplayNextTrack {
@TrackItem(&track, true, playlist(track, p))
} else {
@TrackItem(&track, true, "")
}
}
</div>
if len(p.MissingTracks) != 0 {
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(p.MissingTracks)) } rel="noreferrer">more tracks</a>
}
<div>
if p.TagList != "" {
<p>Tags: { strings.Join(sc.TagListParser(p.TagList), ", ") }</p>
}
<p>{ strconv.FormatInt(p.Likes, 10) } likes</p>
<br/>
if p.CreatedAt != "" {
<p>Created: { p.CreatedAt }</p>
}
if p.LastModified != "" {
<p>Last modified: { p.LastModified }</p>
}
</div>
}
templ SearchPlaylists(p *sc.Paginated[*sc.Playlist]) {
<span>Found { strconv.FormatInt(p.Total, 10) } playlists</span>
<br/>
<br/>
if len(p.Collection) == 0 {
if p.Total != 0 {
<p>no more results</p>
}
} else {
for _, playlist := range p.Collection {
@PlaylistItem(playlist, true)
}
if p.Next != "" && len(p.Collection) != int(p.Total) {
<a class="btn" href={ templ.SafeURL("?type=playlists&pagination=" + url.QueryEscape(p.Next[sc.H+len("/search/playlists"):])) } rel="noreferrer">more playlists</a>
}
}
}