diff --git a/lyrics.go b/lyrics.go index 4afef2a..d366d19 100644 --- a/lyrics.go +++ b/lyrics.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "path" + "strings" "text/template" "github.com/PuerkitoBio/goquery" @@ -16,7 +17,7 @@ type song struct { Image string Lyrics string Credits map[string]string - About string + About [2]string } func (s *song) parseLyrics(doc *goquery.Document) { @@ -52,7 +53,12 @@ func (s *song) parseCredits(doc *goquery.Document) { } func (s *song) parseAbout(doc *goquery.Document) { - s.About = doc.Find("[class*='SongDescription__Content']").Text() + s.About[0] = doc.Find("[class*='SongDescription__Content']").Text() + summary := strings.Split(s.About[0], "") + + if len(summary) > 250 { + s.About[1] = strings.Join(summary[0:250], "") + "..." + } } func (s *song) parse(doc *goquery.Document) { diff --git a/static/script.js b/static/script.js index ee507ae..eb3ab1c 100644 --- a/static/script.js +++ b/static/script.js @@ -1,7 +1,18 @@ +const fullAbout = document.querySelector("#about #full_about") +const summary = document.querySelector("#about #summary") + +function showAbout() { + summary.classList.toggle("hidden") + fullAbout.classList.toggle("hidden") +} + +[fullAbout, summary].forEach(item => item.onclick = showAbout) + document.querySelectorAll("#lyrics a").forEach(item => { item.addEventListener("click", getAnnotation) }) function getAnnotation(e) { e.preventDefault() + console.log(e.target.parentElement.getAttribute("href")) } diff --git a/static/style.css b/static/style.css index ce6e5b1..aca1d5e 100644 --- a/static/style.css +++ b/static/style.css @@ -99,7 +99,8 @@ a { #container { display: grid; grid-template-columns: 1fr 3fr 1fr; - padding: 2rem; + padding: 5rem 10rem; + gap: 5rem; } #credits { @@ -141,4 +142,10 @@ a { font-size: 1.4rem; color: #171717; line-height: 1.8rem; + cursor: pointer; } + +.hidden { + display: none; +} + diff --git a/views/lyrics.tmpl b/views/lyrics.tmpl index 7b9f0cc..bb646a9 100644 --- a/views/lyrics.tmpl +++ b/views/lyrics.tmpl @@ -4,7 +4,7 @@
{{.About}}
+{{index .About 0}}
+{{index .About 1}}