diff --git a/pkg/soundcloud/entities.go b/pkg/soundcloud/entities.go new file mode 100644 index 00000000..390dec19 --- /dev/null +++ b/pkg/soundcloud/entities.go @@ -0,0 +1,41 @@ +package soundcloud + +import "fmt" + +func (p *Playlist) IsMain() bool { + switch p.PlaylistType { + case "single", "album", "compilation", "ep": + return true + } + return false +} + +func (p *Playlist) Section() string { + switch p.PlaylistType { + case "album": + return "albums" + case "single", "ep": + return "singles-eps" + case "compilation": + return "appears-on" + } + return "other" +} + +func (p *Playlists) BySection(section string) []*Playlist { + out := []*Playlist{} + for _, playlist := range p.Playlists { + if playlist.Section() == section { + out = append(out, playlist) + } + } + return out +} + +func (p *Playlist) URL() string { + return fmt.Sprintf("/album/%d", p.ID) +} + +func (p *Playlist) IsExternal() bool { return true } + +func (p *Playlist) ImageURL() string { return p.ArtworkUrl } diff --git a/templates/muzik.tmpl b/templates/muzik.tmpl index 112f7651..28b3709c 100644 --- a/templates/muzik.tmpl +++ b/templates/muzik.tmpl @@ -1,5 +1,99 @@ {{define "title"}}Muzik{{end}} +{{/* +{% block title %}Des albums{% endblock %} +{% block subtitle %}pas au hasard{% endblock %} +*/}} + {{define "content"}} -Muzikkk +{{ $columns := 2 }} +{{ $grid_size := div 12 $columns }} +{{ $square_size := 250 }} + + +
+ +

Albums

+ {{ range $entry := (.playlists.BySection "albums") }} +
+ + +
+

+ {{ $entry.Title }} +

+
+ +
+
+ {{ end }} +
+ +
+

Singles & EPs

+ {{ range $entry := (.playlists.BySection "singles-eps") }} +
+ + +
+

+ {{ $entry.Title }} +

+
+ +
+
+ {{ end }} +
+ +
+

Compilations

+ {{ range $entry := (.playlists.BySection "appears-on") }} +
+ + +
+

+ {{ $entry.Title }} +

+
+ +
+
+ {{ end }} +
+ +
+

Brouillons

+ {{ range $entry := (.playlists.BySection "other") }} +
+ + +
+

+ {{ $entry.Title }} +

+
+ +
+
+ {{ end }} +
+ {{end}} diff --git a/templates/old/muzik.html b/templates/old/muzik.html deleted file mode 100644 index 5825af00..00000000 --- a/templates/old/muzik.html +++ /dev/null @@ -1,56 +0,0 @@ -{% set active_page = 'muzik' %} -{% extends "base.html" %} -{% set page_title = 'Muzik' %} -{% set columns = 2 %} -{% set square_size = 250 %} -{% set grid_size = 12 // columns %} - -{% block title %}Des albums{% endblock %} -{% block subtitle %}pas au hasard{% endblock %} - -{% block content %} -
-

Boom boom

-
- {% for album in first : %} - -
- -
-

- {{ album.title }} -

-
- -
-
- {% endfor %} -
- - -

Trucs à la con

-
- {% for album in second : %} - -
- -
-

- {{ album.title }} -

-
- -
-
- {% endfor %} -
- -{% endblock %} diff --git a/views/views.go b/views/views.go index fd0b42ba..5a3d57c1 100644 --- a/views/views.go +++ b/views/views.go @@ -89,7 +89,14 @@ func (h *handlers) homeHandler(w http.ResponseWriter, r *http.Request) { func (h *handlers) muzikHandler(w http.ResponseWriter, r *http.Request) { h.setDefaultHeaders(w) - data := renderData{"hello": "world"} + playlists, err := h.opts.Svc.SoundcloudPlaylists(r.Context(), &api.Void{}) + if err != nil { + h.renderError(w, r, err) + return + } + data := renderData{ + "playlists": playlists, + } h.render(w, r, "muzik.tmpl", data) }