Browse Source

add discogs and musicbrainz links to artists, closes #7

master
Inhji Y. 11 months ago
parent
commit
7662ff8e05
2 changed files with 47 additions and 0 deletions
  1. +9
    -0
      lib/dagon_web/templates/artist/show.html.eex
  2. +38
    -0
      lib/dagon_web/views/artist_view.ex

+ 9
- 0
lib/dagon_web/templates/artist/show.html.eex View File

@@ -31,6 +31,15 @@
</div>
</div>
</div>
<div class="field is-grouped">
<p class="control">
<a href="<%= musicbrainz_url(@artist) %>" class="button <%= musicbrainz_style(@artist) %>">Musicbrainz</a>
</p>
<p class="control">
<a href="<%= discogs_url(@artist) %>" class="button <%= discogs_style(@artist) %>">Discogs</a>
</p>
</div>
</div>
</div>



+ 38
- 0
lib/dagon_web/views/artist_view.ex View File

@@ -1,3 +1,41 @@
defmodule DagonWeb.ArtistView do
use DagonWeb, :view

def encode_artist(artist) do
artist.name
|> URI.encode_www_form()
|> String.downcase()
end

def musicbrainz_url(artist) do
case artist.mbid do
nil ->
"https://musicbrainz.org/search?query=#{encode_artist(artist)}&type=artist&method=indexed"
mbid ->
"https://musicbrainz.org/artist/#{mbid}"
end
end

def musicbrainz_style(artist) do
case artist.mbid do
nil -> "is-light"
_ -> "is-success"
end
end

def discogs_url(artist) do
case artist.discogs_id do
invalid when invalid in [nil, -1] ->
"https://www.discogs.com/search/?q=#{encode_artist(artist)}&type=artist"
discogs_id ->
"https://www.discogs.com/artist/#{discogs_id}"
end
end

def discogs_style(artist) do
case artist.discogs_id do
invalid when invalid in [nil, -1] -> "is-light"
discogs_id -> "is-success"
end
end
end

Loading…
Cancel
Save