diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index 95ea06888..dc172c5f8 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -14,6 +14,7 @@ module ArticlesHelper article.processed_html.include?("youtube.com/embed/") || article.processed_html.include?("player.vimeo.com") || + article.processed_html.include?("clips.twitch.tv/embed") || article.comments_blob.include?("youtube") end diff --git a/app/liquid_tags/twitch_tag.rb b/app/liquid_tags/twitch_tag.rb new file mode 100644 index 000000000..1be23df5e --- /dev/null +++ b/app/liquid_tags/twitch_tag.rb @@ -0,0 +1,37 @@ +class TwitchTag < LiquidTagBase + PARTIAL = "liquids/twitch".freeze + + def initialize(_tag_name, slug, _parse_context) + super + @url = parsed_url(SiteConfig.app_domain) + @slug = parsed_slug(slug) + @width = 710 + @height = 399 + end + + def render(_context) + ApplicationController.render( + partial: PARTIAL, + locals: { + url: @url, + slug: @slug, + width: @width, + height: @height + }, + ) + end + + private + + # Strip out port number because it confuses Twitch + def parsed_url(url) + url.split(":")[0] + end + + # prevent param injection + def parsed_slug(slug) + slug.strip.split("&")[0] + end +end + +Liquid::Template.register_tag("twitch", TwitchTag) diff --git a/app/views/articles/_fitvids.html.erb b/app/views/articles/_fitvids.html.erb index 1391d8bc3..f4916b79b 100644 --- a/app/views/articles/_fitvids.html.erb +++ b/app/views/articles/_fitvids.html.erb @@ -1,9 +1,9 @@ diff --git a/app/views/liquids/_twitch.html.erb b/app/views/liquids/_twitch.html.erb new file mode 100644 index 000000000..c490d1156 --- /dev/null +++ b/app/views/liquids/_twitch.html.erb @@ -0,0 +1,6 @@ + diff --git a/app/views/pages/_editor_guide_text.html.erb b/app/views/pages/_editor_guide_text.html.erb index d2b042928..d51d5b616 100644 --- a/app/views/pages/_editor_guide_text.html.erb +++ b/app/views/pages/_editor_guide_text.html.erb @@ -186,6 +186,7 @@
{% youtube dQw4w9WgXcQ %}{% vimeo 193110695 %}{% twitch ClumsyPrettiestOilLitFam %}Just enter the full URL of the Medium article you are trying to embed.
diff --git a/app/views/pages/_editor_liquid_help.html.erb b/app/views/pages/_editor_liquid_help.html.erb index 5271695a1..c87cdcb47 100644 --- a/app/views/pages/_editor_liquid_help.html.erb +++ b/app/views/pages/_editor_liquid_help.html.erb @@ -128,6 +128,7 @@{% youtube dQw4w9WgXcQ %}{% vimeo 193110695 %}{% twitch ClumsyPrettiestOilLitFam %}Just enter the full URL of the Medium article you are trying to embed.
diff --git a/app/views/pages/markdown_basics.html.erb b/app/views/pages/markdown_basics.html.erb index 21e15e7fc..0fd4a68a4 100644 --- a/app/views/pages/markdown_basics.html.erb +++ b/app/views/pages/markdown_basics.html.erb @@ -58,6 +58,7 @@All you need is the id from the URL.
{% youtube 9z-Pdfxxdyo %}{% vimeo 193110695 %}{% twitch ClumsyPrettiestOilLitFam %}All you need is the Instagram post id from the URL.