From 60701288f631caae0350721838c64f28a70a52ed Mon Sep 17 00:00:00 2001 From: cobodo Date: Tue, 24 Jul 2018 14:15:37 +0900 Subject: [PATCH] photo_support github --- core/plugin/photo_support/photo_support.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/plugin/photo_support/photo_support.rb b/core/plugin/photo_support/photo_support.rb index e3622cb0..ac46ca2c 100644 --- a/core/plugin/photo_support/photo_support.rb +++ b/core/plugin/photo_support/photo_support.rb @@ -5,6 +5,7 @@ require 'totoridipjp' module Plugin::PhotoSupport INSTAGRAM_PATTERN = %r{\Ahttps?://(?:instagr\.am|(?:www\.)?instagram\.com)/p/([a-zA-Z0-9_\-]+)/} + GITHUB_IMAGE_PATTERN = %r<\Ahttps://github\.com/(\w+/\w+)/blob/(.*\.(?:#{GdkPixbuf::Pixbuf.formats.flat_map do |f| f.extensions end.join '|'}))\z> class << self extend Memoist @@ -252,4 +253,12 @@ Plugin.create :photo_support do img = Plugin::PhotoSupport.d250g2(display_url) open(img) if img end + + # GitHub + defimageopener('github', Plugin::PhotoSupport::GITHUB_IMAGE_PATTERN) do |display_url| + url = Plugin::PhotoSupport::GITHUB_IMAGE_PATTERN.match(display_url) do |m| + "https://raw.githubusercontent.com/#{m[1]}/#{m[2]}" + end + open(url) if url + end end -- 2.17.1