From acee09aab0a8dc354ba20a507330acce7bd7dc24 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 3 Dec 2024 16:25:16 +0000 Subject: [PATCH] Format bio sections --- assets/css/app.css | 4 +++ .../live/artist_live/show.ex | 30 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index ba330741..5a92a188 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -11,3 +11,7 @@ .bio a { @apply font-semibold text-zinc-700 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200; } + +.bio .license { + @apply italic block; +} diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 6b8ffb57..315b5194 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -52,10 +52,32 @@ defmodule MusicLibraryWeb.ArtistLive.Show do defp render_bio(nil), do: gettext("Biography not available") + # Bios start with text, then a link to read more on Last.fm, followed by a license text. + # We split the bio at the read more link in order to render the license separately. + @last_fm_link_regex ~r/\.\s*/ defp render_bio(bio) do - PhoenixHTMLHelpers.Format.text_to_html(bio, - escape: false, - attributes: [class: "mt-4 text-sm/7"] - ) + case String.split(bio, @last_fm_link_regex, include_captures: true) do + [text, link, license] -> + reformatted_bio = + Enum.join( + [ + text, + link, + ~s(#{license}) + ], + "" + ) + + PhoenixHTMLHelpers.Format.text_to_html(reformatted_bio, + escape: false, + attributes: [class: "mt-2 text-sm/7"] + ) + + other -> + PhoenixHTMLHelpers.Format.text_to_html(other, + escape: false, + attributes: [class: "mt-2 text-sm/7"] + ) + end end end