Template of a custom feed generator service for the Bluesky network in Ruby
1require 'blue_factory'
2
3module Server
4 def self.configure
5 self.instance_method(:run).bind_call(BlueFactory::Server)
6 end
7
8 def run
9 # do any additional config & customization on BlueFactory::Server here
10 # see Sinatra docs for more info: https://sinatrarb.com/intro.html
11 # e.g.:
12 #
13 # disable :logging
14 # enable :static
15 # set :views, File.expand_path('views', __dir__)
16 # set :default_encoding, 'cp1250'
17 #
18 # before do
19 # headers "X-Powered-By" => "BlueFactory/#{BlueFactory::VERSION}"
20 # end
21 #
22 # get '/' do
23 # erb :index
24 # end
25
26 get '/' do
27 content_type 'text/html'
28
29 html = %(
30 <style>
31 body { width: 960px; margin: 40px auto; } li { margin: 5px 0px; }
32 a { text-decoration: none; color: #00e; } a:hover { text-decoration: underline; } a:visited { color: #00e; }
33 </style>
34 <h2>Bluesky Feed Server at #{request.host}</h2>
35 <p>This is an AT Protocol XRPC service hosting a Bluesky custom feed generator.</p>
36 <p>Available feeds:</p>
37 <ul>
38 )
39
40 BlueFactory.feed_keys.each do |k|
41 feed = BlueFactory.get_feed(k)
42 title = feed.display_name
43 html << %(<li><a href="https://bsky.app/profile/#{BlueFactory.publisher_did}/feed/#{k}">#{title}</a></li>\n)
44 end
45
46 html << %(
47 </ul>
48 <p>Powered by Ruby and <a href="https://github.com/mackuba/blue_factory">BlueFactory</a>.</p>
49 )
50
51 html
52 end
53 end
54end