Created
August 17, 2018 05:46
-
-
Save ckolderup/35eb7f518ddad8674ed802bff7882180 to your computer and use it in GitHub Desktop.
at the time they're displayed, change spotify and apple music links into song.link URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 96550c3a9a9ce307924f0d60246a514380a9d503 Mon Sep 17 00:00:00 2001 | |
From: Casey Kolderup <[email protected]> | |
Date: Fri, 17 Aug 2018 05:23:05 +0000 | |
Subject: [PATCH] change itunes and spotify links into song.links | |
--- | |
app/lib/formatter.rb | 12 ++++++++++++ | |
app/serializers/rest/preview_card_serializer.rb | 10 ++++++++++ | |
2 files changed, 22 insertions(+) | |
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb | |
index e1ab05c..3a4733f 100644 | |
--- a/app/lib/formatter.rb | |
+++ b/app/lib/formatter.rb | |
@@ -32,6 +32,7 @@ class Formatter | |
html = raw_content | |
html = "RT @#{prepend_reblog} #{html}" if prepend_reblog | |
+ html = make_song_links(html) | |
html = encode_and_link_urls(html, linkable_accounts) | |
html = encode_custom_emojis(html, status.emojis) if options[:custom_emojify] | |
html = simple_format(html, {}, sanitize: false) | |
@@ -80,6 +81,17 @@ class Formatter | |
html.html_safe # rubocop:disable Rails/OutputSafety | |
end | |
+ def make_song_links(text) | |
+ text = text.gsub( | |
+ /https*:\/\/open.spotify.com/, | |
+ 'https://song.link/https://open.spotify.com' | |
+ ) | |
+ text = text.gsub( | |
+ /https*:\/\/itunes.apple.com/, | |
+ 'https://song.link/https://itunes.apple.com' | |
+ ) | |
+ end | |
+ | |
def linkify(text) | |
html = encode_and_link_urls(text) | |
html = simple_format(html, {}, sanitize: false) | |
diff --git a/app/serializers/rest/preview_card_serializer.rb b/app/serializers/rest/preview_card_serializer.rb | |
index 2df9d07..de774a2 100644 | |
--- a/app/serializers/rest/preview_card_serializer.rb | |
+++ b/app/serializers/rest/preview_card_serializer.rb | |
@@ -8,6 +8,16 @@ class REST::PreviewCardSerializer < ActiveModel::Serializer | |
:provider_url, :html, :width, :height, | |
:image, :embed_url | |
+ def url | |
+ object.url.gsub( | |
+ /https*:\/\/open.spotify.com/, | |
+ 'https://song.link/https://open.spotify.com' | |
+ ).gsub( | |
+ /https*:\/\/itunes.apple.com/, | |
+ 'https://song.link/https://itunes.apple.com' | |
+ ) | |
+ end | |
+ | |
def image | |
object.image? ? full_asset_url(object.image.url(:original)) : nil | |
end | |
-- | |
2.7.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment