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