Template of a custom feed generator service for the Bluesky network in Ruby
1require_relative 'feed'
2
3class LinuxFeed < Feed
4 REGEXPS = [
5 /linux/i, /debian/i, /ubuntu/i, /\bredhat\b/i, /\bRHEL\b/, /\bSUSE\b/, /\bCentOS\b/, /\bopensuse\b/i,
6 /\bslackware\b/i, /\bKDE\b/, /\bGTK\d?\b/, /#GNOME\b/, /\bGNOME\s?\d+/, /\bkde plasma\b/i,
7 /apt\-get/, /\bflatpak\b/i, /\b[Xx]org\b/
8 ]
9
10 EXCLUDE = [
11 /\bmastos?\b/i, /mast[oa]d[oa]n/i, /\bfederat(ion|ed)\b/i, /fediverse/i, /at\s?protocol/i,
12 /social (media|networks?)/i, /microblogging/i, /\bthreads\b/i, /\bnostr\b/i,
13 /the linux of/i, /linux (bros|nerds)/i, /ubuntu tv/i
14 ]
15
16 LINK_EXCLUDES = [
17 /\bamzn\.to\b/i, /\bwww\.amazon\.com\b/i, /\bmercadolivre\.com\b/i,
18 ]
19
20 MUTED_PROFILES = [
21 'did:plc:35c6qworuvguvwnpjwfq3b5p', # Linux Kernel Releases
22 'did:plc:ppuqidjyabv5iwzeoxt4fq5o', # GitHub Trending JS/TS
23 'did:plc:eidn2o5kwuaqcss7zo7ivye5', # GitHub Trending
24 'did:plc:lontmsdex36tfjyxjlznnea7', # RustTrending
25 'did:plc:myutg2pwkjbukv7pq2hp5mtl', # CVE Alerts
26 ]
27
28 def feed_id
29 2
30 end
31
32 def display_name
33 "Linux"
34 end
35
36 def description
37 "All posts on Bluesky about Linux and its popular distributions & desktop environments"
38 end
39
40 def avatar_file
41 "images/linux_tux.png"
42 end
43
44 def post_matches?(post)
45 return false if MUTED_PROFILES.include?(post.repo)
46
47 REGEXPS.any? { |r| post.text =~ r } && !(EXCLUDE.any? { |r| post.text =~ r }) && !has_forbidden_links?(post)
48 end
49
50 def has_forbidden_links?(post)
51 if embed = post.record['embed']
52 if link = (embed['external'] || embed['media'] && embed['media']['external'])
53 return true if LINK_EXCLUDES.any? { |r| r =~ link['uri'] }
54 end
55 end
56
57 return false
58 end
59
60 def colored_text(t)
61 text = t.dup
62
63 EXCLUDE.each { |r| text.gsub!(r) { |s| Rainbow(s).red }}
64 LINK_EXCLUDES.each { |r| text.gsub!(r) { |s| Rainbow(s).red }}
65 REGEXPS.each { |r| text.gsub!(r) { |s| Rainbow(s).green }}
66
67 text
68 end
69end