refactor: remove redundant code
This commit is contained in:
parent
3bf802c9c2
commit
41d13e1edb
@ -16,7 +16,7 @@ type AlbumPreview struct {
|
|||||||
type Album struct {
|
type Album struct {
|
||||||
AlbumPreview
|
AlbumPreview
|
||||||
Artist ArtistPreview
|
Artist ArtistPreview
|
||||||
About [2]string
|
About string
|
||||||
|
|
||||||
Tracks []Track
|
Tracks []Track
|
||||||
}
|
}
|
||||||
@ -70,8 +70,7 @@ func (a *Album) parseAlbumData(doc *goquery.Document) error {
|
|||||||
}
|
}
|
||||||
a.Name = albumData.Name
|
a.Name = albumData.Name
|
||||||
a.Image = albumData.Image
|
a.Image = albumData.Image
|
||||||
a.About[0] = albumData.Description
|
a.About = albumData.Description
|
||||||
a.About[1] = truncateText(albumData.Description)
|
|
||||||
|
|
||||||
for _, track := range albumMetadataFromPage.AlbumAppearances {
|
for _, track := range albumMetadataFromPage.AlbumAppearances {
|
||||||
url := strings.Replace(track.Song.Url, "https://genius.com", "", -1)
|
url := strings.Replace(track.Song.Url, "https://genius.com", "", -1)
|
||||||
|
@ -15,7 +15,7 @@ type Song struct {
|
|||||||
Image string
|
Image string
|
||||||
Lyrics string
|
Lyrics string
|
||||||
Credits map[string]string
|
Credits map[string]string
|
||||||
About [2]string
|
About string
|
||||||
Album AlbumPreview
|
Album AlbumPreview
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +94,7 @@ func (s *Song) parseSongData(doc *goquery.Document) error {
|
|||||||
s.Artist = songData.ArtistNames
|
s.Artist = songData.ArtistNames
|
||||||
s.Image = songData.Image
|
s.Image = songData.Image
|
||||||
s.Title = songData.Title
|
s.Title = songData.Title
|
||||||
s.About[0] = songData.Description.Plain
|
s.About = songData.Description.Plain
|
||||||
s.About[1] = truncateText(songData.Description.Plain)
|
|
||||||
s.Credits = make(map[string]string)
|
s.Credits = make(map[string]string)
|
||||||
s.Album.Name = songData.Album.Name
|
s.Album.Name = songData.Album.Name
|
||||||
s.Album.URL = strings.Replace(songData.Album.URL, "https://genius.com", "", -1)
|
s.Album.URL = strings.Replace(songData.Album.URL, "https://genius.com", "", -1)
|
||||||
@ -122,16 +121,6 @@ func joinNames(data []struct {
|
|||||||
return strings.Join(names, ", ")
|
return strings.Join(names, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncateText(text string) string {
|
|
||||||
textArr := strings.Split(text, "")
|
|
||||||
|
|
||||||
if len(textArr) > 250 {
|
|
||||||
return strings.Join(textArr[0:250], "") + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Song) Parse(doc *goquery.Document) error {
|
func (s *Song) Parse(doc *goquery.Document) error {
|
||||||
if err := s.parseLyrics(doc); err != nil {
|
if err := s.parseLyrics(doc); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -3,6 +3,7 @@ package views
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rramiachraf/dumb/data"
|
"github.com/rramiachraf/dumb/data"
|
||||||
|
"github.com/rramiachraf/dumb/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ AlbumPage(a data.Album) {
|
templ AlbumPage(a data.Album) {
|
||||||
@ -11,7 +12,9 @@ templ AlbumPage(a data.Album) {
|
|||||||
<div id="metadata">
|
<div id="metadata">
|
||||||
<img id="album-artwork" src={ data.ExtractImageURL(a.Image) } alt="Album image"/>
|
<img id="album-artwork" src={ data.ExtractImageURL(a.Image) } alt="Album image"/>
|
||||||
<div id="metadata-info">
|
<div id="metadata-info">
|
||||||
<a href={ templ.URL(a.Artist.URL) } id="album-artist"><h2>{ a.Artist.Name }</h2></a>
|
<a href={ templ.URL(a.Artist.URL) } id="album-artist">
|
||||||
|
<h2>{ a.Artist.Name }</h2>
|
||||||
|
</a>
|
||||||
<h1>{ a.Name }</h1>
|
<h1>{ a.Name }</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -23,12 +26,12 @@ templ AlbumPage(a data.Album) {
|
|||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
if a.About[0] != "" {
|
if a.About != "" {
|
||||||
<div id="info">
|
<div id="info">
|
||||||
<div id="description" dir="auto">
|
<div id="description" dir="auto">
|
||||||
<h1 id="title">About</h1>
|
<h1 id="title">About</h1>
|
||||||
<p class="hidden" id="full">{ a.About[0] }</p>
|
<p class="hidden" id="full">{ a.About }</p>
|
||||||
<p id="summary">{ a.About[1] }</p>
|
<p id="summary">{ utils.TrimText(a.About, 250) }</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package views
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rramiachraf/dumb/data"
|
"github.com/rramiachraf/dumb/data"
|
||||||
|
"github.com/rramiachraf/dumb/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ LyricsPage(s data.Song) {
|
templ LyricsPage(s data.Song) {
|
||||||
@ -23,11 +24,11 @@ templ LyricsPage(s data.Song) {
|
|||||||
@templ.Raw(s.Lyrics)
|
@templ.Raw(s.Lyrics)
|
||||||
</div>
|
</div>
|
||||||
<div id="info">
|
<div id="info">
|
||||||
if s.About[0] != "?" {
|
if s.About != "?" {
|
||||||
<div id="description" dir="auto">
|
<div id="description" dir="auto">
|
||||||
<h1 id="title">About</h1>
|
<h1 id="title">About</h1>
|
||||||
<p class="hidden" id="full">{ s.About[0] }</p>
|
<p class="hidden" id="full">{ s.About }</p>
|
||||||
<p id="summary">{ s.About[1] }</p>
|
<p id="summary">{ utils.TrimText(s.About, 250) }</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
if len(s.Credits) > 0 {
|
if len(s.Credits) > 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user