jekyll-bluesky 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-bluesky/version.rb +1 -1
- data/lib/jekyll-bluesky.rb +117 -114
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c5b3f484918d660520da321ca09b220497ced696841a9e0cafe216f22725047
|
4
|
+
data.tar.gz: faf7bb2fbd96b20fbba64ee28addccc2f0cc35683098e44931901ed2ff85ee65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83310e7a345a7b0204048ce5a368822bc3b2f682215e8307af46207b018f7883a8ae8d5b1ce2207aebdba4527ca9acb26e63e07d0855923a6fa9d8600477a57d
|
7
|
+
data.tar.gz: a3e76e9f49623d7d452637e0d356095b4568313a532b48eb028c21cf317820196605ee02ff2a198ad3964ee4e10c5a8794a4979a954e933e0a8390996992f3af
|
data/lib/jekyll-bluesky.rb
CHANGED
@@ -1,137 +1,140 @@
|
|
1
|
-
# lib/jekyll_bluesky.rb
|
2
|
-
require 'jekyll'
|
3
|
-
require 'http'
|
4
|
-
require 'json'
|
5
|
-
require 'digest'
|
6
|
-
require 'fileutils' # Needed for FileCache
|
7
|
-
|
8
|
-
puts 'Plugin jekyll-bluesky load successfully!'
|
9
|
-
|
10
|
-
module Jekyll
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# lib/jekyll_bluesky.rb
|
2
|
+
require 'jekyll'
|
3
|
+
require 'http'
|
4
|
+
require 'json'
|
5
|
+
require 'digest'
|
6
|
+
require 'fileutils' # Needed for FileCache
|
7
|
+
|
8
|
+
puts 'Plugin jekyll-bluesky load successfully!'
|
9
|
+
|
10
|
+
module Jekyll
|
11
|
+
class BlueskyPlugin < Liquid::Tag
|
12
|
+
def initialize(tag_name, text, tokens)
|
13
|
+
super
|
14
|
+
args = text.strip.split
|
15
|
+
@actor = args[0]
|
16
|
+
@limit = args[1] || '10'
|
17
|
+
Jekyll.logger.debug "Initializing tag bluesky with actor: #{@actor}, limit: #{@limit}"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def render(context)
|
21
|
+
Jekyll.logger.debug 'Rendering bluesky tag...'
|
22
|
+
fetch_posts
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
private
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def fetch_posts
|
28
|
+
cache_key = Digest::MD5.hexdigest("#{@actor}-#{@limit}")
|
29
|
+
cached_response = cache.read(cache_key)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
if cached_response
|
32
|
+
cached_response
|
33
|
+
else
|
34
|
+
response = Jekyll::Client.fetch_post(@actor, @limit) # Updated to use Jekyll::Client
|
35
|
+
cache.write(cache_key, response)
|
36
|
+
response
|
37
|
+
end
|
37
38
|
end
|
38
|
-
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Client
|
46
|
-
API_URL = 'https://public.api.bsky.app'
|
47
|
-
|
48
|
-
def self.fetch_post(actor, limit)
|
49
|
-
response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
|
50
|
-
if response.status.success?
|
51
|
-
data = JSON.parse(response.body)
|
52
|
-
format_post(data)
|
53
|
-
else
|
54
|
-
error_details =
|
55
|
-
begin
|
56
|
-
JSON.parse(response.body)
|
57
|
-
rescue JSON::ParserError
|
58
|
-
response.body.to_s
|
59
|
-
end
|
60
|
-
|
61
|
-
"Error fetching post from Bluesky (status: #{response.status}). Details: #{error_details}"
|
40
|
+
def cache
|
41
|
+
@cache ||= FileCache.new('./.bluesky-cache')
|
62
42
|
end
|
63
43
|
end
|
64
44
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
HTML
|
83
|
-
end.join
|
45
|
+
class Client
|
46
|
+
API_URL = 'https://public.api.bsky.app'
|
47
|
+
|
48
|
+
def self.fetch_post(actor, limit)
|
49
|
+
response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
|
50
|
+
if response.status.success?
|
51
|
+
data = JSON.parse(response.body)
|
52
|
+
format_post(data)
|
53
|
+
else
|
54
|
+
error_details =
|
55
|
+
begin
|
56
|
+
JSON.parse(response.body)
|
57
|
+
rescue JSON::ParserError
|
58
|
+
response.body.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
"Error fetching post from Bluesky (status: #{response.status}). Details: #{error_details}"
|
84
62
|
end
|
63
|
+
end
|
85
64
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
65
|
+
def self.format_post(data)
|
66
|
+
posts = data['feed']
|
67
|
+
posts.map do |post|
|
68
|
+
post_data = post['post']
|
69
|
+
author = post_data['author']
|
70
|
+
record = post_data['record']
|
71
|
+
embed = post_data['embed']
|
72
|
+
|
73
|
+
text = record['text'].gsub("\n", "<br>")
|
74
|
+
author_name = author['displayName']
|
75
|
+
author_handle = author['handle']
|
76
|
+
post_time = "3h" # Estático por enquanto
|
77
|
+
|
78
|
+
image_html = ''
|
79
|
+
if embed && embed['$type'] == 'app.bsky.embed.images#view'
|
80
|
+
image_html = embed['images'].map do |image|
|
81
|
+
<<~HTML
|
82
|
+
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
83
|
+
HTML
|
84
|
+
end.join
|
85
|
+
end
|
86
|
+
|
87
|
+
<<~HTML
|
88
|
+
<div class="bluesky-post">
|
89
|
+
<div class="bluesky-header">
|
90
|
+
<img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
|
91
|
+
<div class="bluesky-author-info">
|
92
|
+
<span class="author-name">#{author_name}</span>
|
93
|
+
<span class="author-handle">@#{author_handle} · #{post_time}</span>
|
94
|
+
</div>
|
95
|
+
</div>
|
96
|
+
<div class="bluesky-content">
|
97
|
+
<p>#{text}</p>
|
98
|
+
#{image_html}
|
99
|
+
</div>
|
100
|
+
<div class="bluesky-footer">
|
101
|
+
<span class="icon">💬 #{post_data['replyCount']}</span>
|
102
|
+
<span class="icon">🔁 #{post_data['repostCount']}</span>
|
103
|
+
<span class="icon">❤️ #{post_data['likeCount']}</span>
|
104
|
+
<span class="icon">···</span>
|
93
105
|
</div>
|
94
106
|
</div>
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
<div class="bluesky-stats">
|
100
|
-
<span>❤️ #{post_data['likeCount']}</span>
|
101
|
-
<span>🔁 #{post_data['repostCount']}</span>
|
102
|
-
<span>💬 #{post_data['replyCount']}</span>
|
103
|
-
</div>
|
104
|
-
</div>
|
105
|
-
HTML
|
106
|
-
end.join("\n")
|
107
|
+
HTML
|
108
|
+
end.join("\n")
|
109
|
+
end
|
110
|
+
|
107
111
|
end
|
108
|
-
end
|
109
112
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
113
|
+
class FileCache
|
114
|
+
def initialize(path)
|
115
|
+
@cache_folder = File.expand_path path
|
116
|
+
FileUtils.mkdir_p @cache_folder
|
117
|
+
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
def read(key)
|
120
|
+
file_to_read = cache_file(key)
|
121
|
+
File.read(file_to_read) if File.exist?(file_to_read)
|
122
|
+
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
def write(key, data)
|
125
|
+
file_to_write = cache_file(key)
|
126
|
+
File.open(file_to_write, 'w') do |f|
|
127
|
+
f.write(data)
|
128
|
+
end
|
125
129
|
end
|
126
|
-
end
|
127
130
|
|
128
|
-
|
131
|
+
private
|
129
132
|
|
130
|
-
|
131
|
-
|
133
|
+
def cache_file(key)
|
134
|
+
File.join(@cache_folder, "#{key}.cache")
|
135
|
+
end
|
132
136
|
end
|
133
137
|
end
|
134
|
-
end
|
135
138
|
|
136
|
-
# Register the Liquid tag
|
137
|
-
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|
139
|
+
# Register the Liquid tag
|
140
|
+
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|