update track API and lyrics fixes
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
05e16a0867
commit
f276ef1ff2
|
@ -33,23 +33,32 @@ func Handler() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
type IndexData struct {
|
||||
type (
|
||||
Track struct {
|
||||
*musicModel.Track
|
||||
Lyrics template.HTML
|
||||
// Number int
|
||||
}
|
||||
IndexData struct {
|
||||
Releases []*musicModel.Release
|
||||
Artists []*musicModel.Artist
|
||||
Tracks []*musicModel.Track
|
||||
Tracks []Track
|
||||
}
|
||||
)
|
||||
|
||||
var orphan_tracks = []*musicModel.Track{}
|
||||
|
||||
var tracks = []Track{}
|
||||
for _, track := range global.Tracks {
|
||||
if track.Release == nil {
|
||||
orphan_tracks = append(orphan_tracks, track)
|
||||
}
|
||||
tracks = append(tracks, Track{
|
||||
Track: track,
|
||||
Lyrics: template.HTML(strings.Replace(track.Lyrics, "\n", "<br>", -1)),
|
||||
})
|
||||
}
|
||||
|
||||
serveTemplate("index.html", IndexData{
|
||||
Releases: global.Releases,
|
||||
Artists: global.Artists,
|
||||
Tracks: global.Tracks,
|
||||
Tracks: tracks,
|
||||
}).ServeHTTP(w, r)
|
||||
}))
|
||||
|
||||
|
|
|
@ -226,13 +226,39 @@ a:hover {
|
|||
}
|
||||
|
||||
h2.track-title {
|
||||
margin: 0
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.track-album {
|
||||
margin-left: auto;
|
||||
font-style: italic;
|
||||
font-size: .75em;
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.track-album.empty {
|
||||
color: #ff2020;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.track-description {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.track-lyrics {
|
||||
max-height: 10em;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.track .empty {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 520px) {
|
||||
body {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,8 +55,7 @@ func UpdateTrackDB(db *sqlx.DB, track *model.Track) error {
|
|||
_, err := db.Exec(
|
||||
"UPDATE musictrack "+
|
||||
"SET title=$2, description=$3, lyrics=$4, preview_url=$5 "+
|
||||
"WHERE id=$1"+
|
||||
"RETURNING id",
|
||||
"WHERE id=$1",
|
||||
track.ID,
|
||||
track.Title,
|
||||
track.Description,
|
||||
|
|
|
@ -3,7 +3,9 @@ package view
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"arimelody.me/arimelody.me/admin"
|
||||
"arimelody.me/arimelody.me/global"
|
||||
|
@ -52,6 +54,7 @@ func ServeGateway() http.Handler {
|
|||
type (
|
||||
GatewayTrack struct {
|
||||
*model.Track
|
||||
Lyrics template.HTML
|
||||
Number int
|
||||
}
|
||||
|
||||
|
@ -72,6 +75,7 @@ func ServeGateway() http.Handler {
|
|||
for i, track := range release.Tracks {
|
||||
tracks = append([]GatewayTrack{GatewayTrack{
|
||||
Track: track,
|
||||
Lyrics: template.HTML(strings.Replace(track.Lyrics, "\n", "<br>", -1)),
|
||||
Number: len(release.Tracks) - i,
|
||||
}}, tracks...)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,14 @@
|
|||
<div class="card tracks">
|
||||
{{range $Track := .Tracks}}
|
||||
<div class="track">
|
||||
<h2 class="track-title">{{$Track.Title}}</h2>
|
||||
<h2 class="track-title">
|
||||
{{$Track.Title}}
|
||||
{{if $Track.Release}}
|
||||
<small class="track-album">{{$Track.Release.Title}}</small>
|
||||
{{else}}
|
||||
<small class="track-album empty">(no album)</small>
|
||||
{{end}}
|
||||
</h2>
|
||||
{{if $Track.Description}}
|
||||
<p class="track-description">{{$Track.Description}}</p>
|
||||
{{else}}
|
||||
|
|
Loading…
Reference in a new issue