Template of a custom feed generator service for the Bluesky network in Ruby

replaced build in public feed with Kit feed

Changed files
+51 -48
app
images
+1 -1
app/config.rb
··· 9 9 # see Feed#get_posts(params, visitor_did) in app/feeds/feed.rb 10 10 # BlueFactory.set :enable_unsafe_auth, true 11 11 12 - BlueFactory.add_feed 'build', BuildInPublicFeed.new 12 + BlueFactory.add_feed 'kit', KitFeed.new 13 13 BlueFactory.add_feed 'linux', LinuxFeed.new 14 14 BlueFactory.add_feed 'starwars', StarWarsFeed.new
-47
app/feeds/build_in_public_feed.rb
··· 1 - require_relative 'feed' 2 - 3 - class BuildInPublicFeed < Feed 4 - REGEXPS = [/\bbuild\s?in\s?public\b/i] 5 - 6 - def feed_id 7 - 3 8 - end 9 - 10 - def display_name 11 - "#buildinpublic" 12 - end 13 - 14 - def description 15 - "Indie hackers and entrepreneurs building things in public - use #buildinpublic hashtag" 16 - end 17 - 18 - def post_matches?(post) 19 - all_text = matched_text(post) 20 - 21 - REGEXPS.any? { |x| all_text =~ x } 22 - end 23 - 24 - def matched_text(post) 25 - lines = [post.text] 26 - 27 - if embed = post.record['embed'] 28 - if images = (embed['images'] || embed['media'] && embed['media']['images']) 29 - lines += images.map { |i| i['alt'] }.compact 30 - end 31 - 32 - if link = embed['external'] 33 - lines += [link['uri'], link['title'], link['description']].compact 34 - end 35 - end 36 - 37 - lines.join("\n") 38 - end 39 - 40 - def colored_text(t) 41 - text = t.dup 42 - 43 - REGEXPS.each { |r| text.gsub!(r) { |s| Rainbow(s).green }} 44 - 45 - text 46 - end 47 - end
+50
app/feeds/kit_feed.rb
··· 1 + require_relative 'feed' 2 + 3 + class KitFeed < Feed 4 + KIT_REGEX = [/\bkit\b/i] 5 + CAT_REGEX = [/\bcat\b/i, /\bkitty\b/i] 6 + 7 + PAUL = 'did:plc:ragtjsm2j2vknwkz3zp4oxrd' 8 + 9 + def feed_id 10 + 3 11 + end 12 + 13 + def display_name 14 + "Kit Feed" 15 + end 16 + 17 + def description 18 + "Photos of Paul's lovely cat Kit 🐱" 19 + end 20 + 21 + def avatar_file 22 + "images/kitkat.jpg" 23 + end 24 + 25 + def post_matches?(post) 26 + return false unless post.repo == PAUL 27 + 28 + alt = embed_text(post) 29 + return false if alt.nil? 30 + 31 + KIT_REGEX.any? { |r| alt =~ r } || (CAT_REGEX.any? { |r| alt =~ r } && KIT_REGEX.any? { |r| post.text =~ r }) 32 + end 33 + 34 + def embed_text(post) 35 + if embed = post.record['embed'] 36 + if images = (embed['images'] || embed['media'] && embed['media']['images']) 37 + images.map { |i| i['alt'] }.compact.join("\n") 38 + end 39 + end 40 + end 41 + 42 + def colored_text(t) 43 + text = t.dup 44 + 45 + KIT_REGEX.each { |r| text.gsub!(r) { |s| Rainbow(s).green }} 46 + CAT_REGEX.each { |r| text.gsub!(r) { |s| Rainbow(s).bright.orange }} 47 + 48 + text 49 + end 50 + end
images/kitkat.jpg

This is a binary file and will not be displayed.