atproto-based blog in ruby

basic listing page

+1
.gitignore
··· 1 + liblua.dylib
+9
Gemfile
··· 1 + source "https://rubygems.org" 2 + 3 + gem 'sinatra' 4 + gem 'haml' 5 + gem 'rufus-lua' 6 + gem 'minisky' 7 + 8 + gem "rackup", "~> 2.2" 9 + gem "puma", "~> 6.6"
+54
Gemfile.lock
··· 1 + GEM 2 + remote: https://rubygems.org/ 3 + specs: 4 + base64 (0.2.0) 5 + ffi (1.17.1-arm64-darwin) 6 + haml (6.3.0) 7 + temple (>= 0.8.2) 8 + thor 9 + tilt 10 + logger (1.7.0) 11 + minisky (0.5.0) 12 + base64 (~> 0.1) 13 + mustermann (3.0.3) 14 + ruby2_keywords (~> 0.0.1) 15 + nio4r (2.7.4) 16 + puma (6.6.0) 17 + nio4r (~> 2.0) 18 + rack (3.1.12) 19 + rack-protection (4.1.1) 20 + base64 (>= 0.1.0) 21 + logger (>= 1.6.0) 22 + rack (>= 3.0.0, < 4) 23 + rack-session (2.1.0) 24 + base64 (>= 0.1.0) 25 + rack (>= 3.0.0) 26 + rackup (2.2.1) 27 + rack (>= 3) 28 + ruby2_keywords (0.0.5) 29 + rufus-lua (1.1.5) 30 + ffi (~> 1.9) 31 + sinatra (4.1.1) 32 + logger (>= 1.6.0) 33 + mustermann (~> 3.0) 34 + rack (>= 3.0.0, < 4) 35 + rack-protection (= 4.1.1) 36 + rack-session (>= 2.0.0, < 3) 37 + tilt (~> 2.0) 38 + temple (0.10.3) 39 + thor (1.3.2) 40 + tilt (2.6.0) 41 + 42 + PLATFORMS 43 + arm64-darwin-22 44 + 45 + DEPENDENCIES 46 + haml 47 + minisky 48 + puma (~> 6.6) 49 + rackup (~> 2.2) 50 + rufus-lua 51 + sinatra 52 + 53 + BUNDLED WITH 54 + 2.4.10
+10
app/env.rb
··· 1 + require "rufus-lua" 2 + require "ostruct" 3 + 4 + module AtBlog 5 + end 6 + 7 + config = Rufus::Lua::State.new 8 + at_config_hash = config.eval(File.read(abs_path("../config.lua"))).to_h 9 + 10 + AtBlog::Config = OpenStruct.new(at_config_hash)
+21
atproto/blog.rb
··· 1 + require "minisky" 2 + 3 + class AtBlog::Blog 4 + def initialize(config) 5 + @client = Minisky.new(config.pds, nil) 6 + @config = config 7 + end 8 + 9 + attr_reader :config, :client 10 + 11 + def post_list 12 + # for now just the last 200 posts 13 + # TODO: pagination 14 + posts = @client.fetch_all( 15 + "com.atproto.repo.listRecords", 16 + { repo: @config.repo, collection: @config.post_collection }, 17 + field: "records", 18 + max_pages: 2, 19 + ) 20 + end 21 + end
+5
config.lua
··· 1 + return { 2 + pds = "pds.shreyanjain.net", 3 + repo = "did:plc:bnqkww7bjxaacajzvu5gswdf", 4 + post_collection = "app.bsky.feed.post" 5 + }
+4
extra/helpers.rb
··· 1 + def abs_path(path) 2 + caller_path = File.dirname(caller_locations(1, 1)[0].absolute_path) 3 + File.expand_path(path, caller_path) 4 + end
+15
main.rb
··· 1 + require "sinatra" 2 + 3 + require "haml" 4 + require_relative "extra/helpers" 5 + ENV["LUA_LIB"] = abs_path("./liblua.dylib") 6 + require_relative "app/env" 7 + require_relative "atproto/blog" 8 + 9 + MainBlog = AtBlog::Blog.new(AtBlog::Config) 10 + 11 + get "/" do 12 + MainBlog.post_list.to_json 13 + end 14 + 15 + Sinatra::Application.run