jekyll-bluesky 0.23.0 → 0.26.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 +196 -179
- 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: 70502d86000ce3a9b17cca6b53bac4f094d35521bae4df9f52f709a1c967c642
|
4
|
+
data.tar.gz: 42c2d83f6962f541b3bd4b4ad2e2933cf9f3abbb43d859bdd2ef19297f027450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a0e0a586524cfe0e0dce1053ffd2ef60a96badf9dde858b8b76ecb96b19548933c88683508dc8db0db3f35c49ce8e1c542812ef313124ce4d2761f23b22ed38
|
7
|
+
data.tar.gz: c02076e610e77bf95f10b6d4b67a1bb0a2cf0ffafc4e9139b2020aa7fb13ada24c2e7ae141244f96c1a0db44d9740274b04e599eb67235179efef725c2790e59
|
data/lib/jekyll-bluesky.rb
CHANGED
@@ -1,203 +1,220 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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'
|
7
|
+
require 'time' # Necessário para manipulação de datas
|
8
|
+
|
9
|
+
puts 'Plugin jekyll-bluesky load successfully!'
|
10
|
+
|
11
|
+
module Jekyll
|
12
|
+
class BlueskyPlugin < Liquid::Tag
|
13
|
+
def initialize(tag_name, text, tokens)
|
14
|
+
super
|
15
|
+
args = text.strip.split
|
16
|
+
@actor = args[0]
|
17
|
+
@limit = args[1] || '10'
|
18
|
+
Jekyll.logger.debug "Initializing tag bluesky with actor: #{@actor}, limit: #{@limit}"
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def render(context)
|
22
|
+
Jekyll.logger.debug 'Rendering bluesky tag...'
|
23
|
+
fetch_posts
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
private
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def fetch_posts
|
29
|
+
cache_key = Digest::MD5.hexdigest("#{@actor}-#{@limit}")
|
30
|
+
cached_response = cache.read(cache_key)
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
32
|
+
if cached_response
|
33
|
+
cached_response
|
34
|
+
else
|
35
|
+
response = Jekyll::Client.fetch_post(@actor, @limit)
|
36
|
+
cache.write(cache_key, response)
|
37
|
+
response
|
38
38
|
end
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
def cache
|
42
|
+
@cache ||= FileCache.new('./.bluesky-cache')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Client
|
47
|
+
API_URL = 'https://public.api.bsky.app'
|
48
|
+
|
49
|
+
def self.fetch_post(actor, limit)
|
50
|
+
response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
|
51
|
+
if response.status.success?
|
52
|
+
data = JSON.parse(response.body)
|
53
|
+
format_post(data)
|
54
|
+
else
|
55
|
+
error_details =
|
56
|
+
begin
|
57
|
+
JSON.parse(response.body)
|
58
|
+
rescue JSON::ParserError
|
59
|
+
response.body.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
"Error fetching post from Bluesky (status: #{response.status}). Details: #{error_details}"
|
42
63
|
end
|
43
64
|
end
|
44
65
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
66
|
+
def self.format_post(data)
|
67
|
+
posts = data['feed']
|
68
|
+
styles = <<~HTML
|
69
|
+
<style>
|
70
|
+
@font-face {
|
71
|
+
font-family: 'InterVariable';
|
72
|
+
src: url("https://web-cdn.bsky.app/static/media/InterVariable.c504db5c06caaf7cdfba.woff2") format('woff2');
|
73
|
+
font-weight: 300 1000;
|
74
|
+
font-style: normal;
|
75
|
+
font-display: swap;
|
76
|
+
}
|
77
|
+
.bluesky-post {
|
78
|
+
border-bottom: 1px solid #e1e8ed;
|
79
|
+
padding: 12px;
|
80
|
+
width: 500px;
|
81
|
+
font-family: 'InterVariable', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Liberation Sans', Helvetica, Arial, sans-serif;
|
82
|
+
background: #fff;
|
83
|
+
margin-bottom: 10px;
|
84
|
+
}
|
85
|
+
.bluesky-header {
|
86
|
+
display: flex;
|
87
|
+
align-items: center;
|
88
|
+
justify-content: flex-start;
|
89
|
+
gap: 8px;
|
90
|
+
}
|
91
|
+
.bluesky-avatar {
|
92
|
+
width: 40px;
|
93
|
+
height: 40px;
|
94
|
+
border-radius: 50%;
|
95
|
+
}
|
96
|
+
.bluesky-author-info {
|
97
|
+
display: flex;
|
98
|
+
flex-direction: column;
|
99
|
+
align-items: flex-start;
|
100
|
+
}
|
101
|
+
.author-name {
|
102
|
+
font-weight: bold;
|
103
|
+
font-size: 14px;
|
104
|
+
color: #000;
|
105
|
+
}
|
106
|
+
.author-handle {
|
107
|
+
font-size: 12px;
|
108
|
+
color: #657786;
|
109
|
+
}
|
110
|
+
.bluesky-content {
|
111
|
+
font-size: 14px;
|
112
|
+
line-height: 1.5;
|
113
|
+
color: #14171A;
|
114
|
+
margin-top: 8px;
|
115
|
+
}
|
116
|
+
.bluesky-footer {
|
117
|
+
display: flex;
|
118
|
+
justify-content: space-between;
|
119
|
+
font-size: 12px;
|
120
|
+
color: #657786;
|
121
|
+
margin-top: 10px;
|
122
|
+
}
|
123
|
+
.icon {
|
124
|
+
cursor: pointer;
|
125
|
+
}
|
126
|
+
</style>
|
127
|
+
HTML
|
128
|
+
|
129
|
+
formatted_posts = posts.map do |post|
|
130
|
+
post_data = post['post']
|
131
|
+
author = post_data['author']
|
132
|
+
record = post_data['record']
|
133
|
+
embed = post_data['embed']
|
134
|
+
|
135
|
+
text = record['text'].gsub("\n", "<br>")
|
136
|
+
author_name = author['displayName']
|
137
|
+
author_handle = author['handle']
|
138
|
+
post_time = calculate_post_time(record['createdAt']) # Calcula o tempo do post
|
139
|
+
|
140
|
+
image_html = ''
|
141
|
+
if embed && embed['$type'] == 'app.bsky.embed.images#view'
|
142
|
+
image_html = embed['images'].map do |image|
|
143
|
+
<<~HTML
|
144
|
+
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
145
|
+
HTML
|
146
|
+
end.join
|
62
147
|
end
|
63
|
-
end
|
64
148
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
font-weight: 300 1000;
|
73
|
-
font-style: normal;
|
74
|
-
font-display: swap;
|
75
|
-
}
|
76
|
-
.bluesky-post {
|
77
|
-
border-bottom: 1px solid #e1e8ed;
|
78
|
-
padding: 12px;
|
79
|
-
width: 500px;
|
80
|
-
font-family: 'InterVariable', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Liberation Sans', Helvetica, Arial, sans-serif;
|
81
|
-
background: #fff;
|
82
|
-
margin-bottom: 10px;
|
83
|
-
}
|
84
|
-
.bluesky-header {
|
85
|
-
display: flex;
|
86
|
-
align-items: center;
|
87
|
-
justify-content: flex-start; /* Alinha tudo à esquerda */
|
88
|
-
gap: 8px; /* Espaço entre a foto e o nome */
|
89
|
-
}
|
90
|
-
.bluesky-avatar {
|
91
|
-
width: 40px;
|
92
|
-
height: 40px;
|
93
|
-
border-radius: 50%;
|
94
|
-
}
|
95
|
-
.bluesky-author-info {
|
96
|
-
display: flex;
|
97
|
-
flex-direction: column;
|
98
|
-
align-items: flex-start;
|
99
|
-
}
|
100
|
-
.author-name {
|
101
|
-
font-weight: bold;
|
102
|
-
font-size: 14px;
|
103
|
-
color: #000;
|
104
|
-
}
|
105
|
-
.author-handle {
|
106
|
-
font-size: 12px;
|
107
|
-
color: #657786;
|
108
|
-
}
|
109
|
-
.bluesky-content {
|
110
|
-
font-size: 14px;
|
111
|
-
line-height: 1.5;
|
112
|
-
color: #14171A;
|
113
|
-
}
|
114
|
-
.bluesky-footer {
|
115
|
-
display: flex;
|
116
|
-
justify-content: space-between;
|
117
|
-
font-size: 12px;
|
118
|
-
color: #657786;
|
119
|
-
margin-top: 10px;
|
120
|
-
}
|
121
|
-
.icon {
|
122
|
-
cursor: pointer;
|
123
|
-
}
|
124
|
-
</style>
|
125
|
-
HTML
|
126
|
-
|
127
|
-
formatted_posts = posts.map do |post|
|
128
|
-
post_data = post['post']
|
129
|
-
author = post_data['author']
|
130
|
-
record = post_data['record']
|
131
|
-
embed = post_data['embed']
|
132
|
-
|
133
|
-
text = record['text'].gsub("\n", "<br>")
|
134
|
-
author_name = author['displayName']
|
135
|
-
author_handle = author['handle']
|
136
|
-
post_time = "3h"
|
137
|
-
|
138
|
-
image_html = ''
|
139
|
-
if embed && embed['$type'] == 'app.bsky.embed.images#view'
|
140
|
-
image_html = embed['images'].map do |image|
|
141
|
-
<<~HTML
|
142
|
-
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
143
|
-
HTML
|
144
|
-
end.join
|
145
|
-
end
|
146
|
-
|
147
|
-
<<~HTML
|
148
|
-
<div class="bluesky-post">
|
149
|
-
<div class="bluesky-header">
|
150
|
-
<img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
|
151
|
-
<div class="bluesky-author-info">
|
152
|
-
<span class="author-name">#{author_name}</span>
|
153
|
-
<span class="author-handle">@#{author_handle} · #{post_time}</span>
|
154
|
-
</div>
|
155
|
-
</div>
|
156
|
-
<div class="bluesky-content">
|
157
|
-
<p>#{text}</p>
|
158
|
-
#{image_html}
|
159
|
-
</div>
|
160
|
-
<div class="bluesky-footer">
|
161
|
-
<span class="icon">💬 #{post_data['replyCount']}</span>
|
162
|
-
<span class="icon">🔁 #{post_data['repostCount']}</span>
|
163
|
-
<span class="icon">❤️ #{post_data['likeCount']}</span>
|
164
|
-
<span class="icon">···</span>
|
149
|
+
<<~HTML
|
150
|
+
<div class="bluesky-post">
|
151
|
+
<div class="bluesky-header">
|
152
|
+
<img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
|
153
|
+
<div class="bluesky-author-info">
|
154
|
+
<span class="author-name">#{author_name}</span>
|
155
|
+
<span class="author-handle">@#{author_handle} · #{post_time}</span>
|
165
156
|
</div>
|
166
157
|
</div>
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
158
|
+
<div class="bluesky-content">
|
159
|
+
<p>#{text}</p>
|
160
|
+
#{image_html}
|
161
|
+
</div>
|
162
|
+
<div class="bluesky-footer">
|
163
|
+
<span class="icon">💬 #{post_data['replyCount']}</span>
|
164
|
+
<span class="icon">🔁 #{post_data['repostCount']}</span>
|
165
|
+
<span class="icon">❤️ #{post_data['likeCount']}</span>
|
166
|
+
<span class="icon">···</span>
|
167
|
+
</div>
|
168
|
+
</div>
|
169
|
+
HTML
|
170
|
+
end.join("\n")
|
171
|
+
|
172
|
+
styles + formatted_posts
|
174
173
|
end
|
175
174
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
175
|
+
# Método para calcular o tempo do post
|
176
|
+
def self.calculate_post_time(created_at)
|
177
|
+
post_time = Time.parse(created_at) # Converte a string para um objeto Time
|
178
|
+
current_time = Time.now
|
179
|
+
difference_in_seconds = (current_time - post_time).round
|
180
|
+
|
181
|
+
if difference_in_seconds < 60
|
182
|
+
"#{difference_in_seconds}s"
|
183
|
+
elsif difference_in_seconds < 3600
|
184
|
+
"#{(difference_in_seconds / 60).round}m"
|
185
|
+
elsif difference_in_seconds < 86400
|
186
|
+
"#{(difference_in_seconds / 3600).round}h"
|
187
|
+
else
|
188
|
+
"#{(difference_in_seconds / 86400).round}d"
|
180
189
|
end
|
190
|
+
end
|
191
|
+
end
|
181
192
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
193
|
+
class FileCache
|
194
|
+
def initialize(path)
|
195
|
+
@cache_folder = File.expand_path path
|
196
|
+
FileUtils.mkdir_p @cache_folder
|
197
|
+
end
|
186
198
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
199
|
+
def read(key)
|
200
|
+
file_to_read = cache_file(key)
|
201
|
+
File.read(file_to_read) if File.exist?(file_to_read)
|
202
|
+
end
|
203
|
+
|
204
|
+
def write(key, data)
|
205
|
+
file_to_write = cache_file(key)
|
206
|
+
File.open(file_to_write, 'w') do |f|
|
207
|
+
f.write(data)
|
192
208
|
end
|
209
|
+
end
|
193
210
|
|
194
|
-
|
211
|
+
private
|
195
212
|
|
196
|
-
|
197
|
-
|
198
|
-
end
|
213
|
+
def cache_file(key)
|
214
|
+
File.join(@cache_folder, "#{key}.cache")
|
199
215
|
end
|
200
216
|
end
|
217
|
+
end
|
201
218
|
|
202
|
-
|
203
|
-
|
219
|
+
# Register the Liquid tag
|
220
|
+
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|