jekyll-bluesky 0.18.0 → 0.20.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 +178 -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: f3b8dede391e73193464afae55bbd33955d6a3b46adefff62cd139487bcaf826
|
4
|
+
data.tar.gz: 94a912988e99f333255be4cff19465ff4b8a13c8123625eba3b27aa50e8e3d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6770bd8963df069aa835b6d34b34623e2ee12f8c9eefc20af01ad480d43ae5e1131b56b8ffbc0af6868c9c9f11ef9f98b318de7edd1f2a8ea269beaa440435fe
|
7
|
+
data.tar.gz: 13a67389c954961e08aec904176edb3a538a4333a9adf0f83c7df2a498200e89d20b7e590b2b9e570ccf78b09d105d1da3699b7d459ad6ec6b55d76f0812dbbe
|
data/lib/jekyll-bluesky.rb
CHANGED
@@ -1,137 +1,201 @@
|
|
1
|
-
# lib/jekyll_bluesky.rb
|
2
|
-
require 'jekyll'
|
3
|
-
require 'http'
|
4
|
-
require 'json'
|
5
|
-
require 'digest'
|
6
|
-
require 'fileutils'
|
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'
|
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
|
-
|
40
|
-
def cache
|
41
|
-
@cache ||= FileCache.new('./.bluesky-cache')
|
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
39
|
|
61
|
-
|
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
|
+
styles = <<~HTML
|
68
|
+
<style>
|
69
|
+
@font-face {
|
70
|
+
font-family: 'InterVariable';
|
71
|
+
src: url("https://web-cdn.bsky.app/static/media/InterVariable.c504db5c06caaf7cdfba.woff2") format('woff2');
|
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
|
+
margin-bottom: 8px;
|
88
|
+
}
|
89
|
+
.bluesky-avatar {
|
90
|
+
width: 40px;
|
91
|
+
height: 40px;
|
92
|
+
border-radius: 50%;
|
93
|
+
margin-right: 8px;
|
94
|
+
}
|
95
|
+
.bluesky-author-info {
|
96
|
+
display: flex;
|
97
|
+
flex-direction: column;
|
98
|
+
}
|
99
|
+
.author-name {
|
100
|
+
font-weight: bold;
|
101
|
+
font-size: 14px;
|
102
|
+
color: #000;
|
103
|
+
}
|
104
|
+
.author-handle {
|
105
|
+
font-size: 12px;
|
106
|
+
color: #657786;
|
107
|
+
}
|
108
|
+
.bluesky-content {
|
109
|
+
font-size: 14px;
|
110
|
+
line-height: 1.5;
|
111
|
+
color: #14171A;
|
112
|
+
}
|
113
|
+
.bluesky-footer {
|
114
|
+
display: flex;
|
115
|
+
justify-content: space-between;
|
116
|
+
font-size: 12px;
|
117
|
+
color: #657786;
|
118
|
+
margin-top: 10px;
|
119
|
+
}
|
120
|
+
.icon {
|
121
|
+
cursor: pointer;
|
122
|
+
}
|
123
|
+
</style>
|
124
|
+
HTML
|
125
|
+
|
126
|
+
formatted_posts = posts.map do |post|
|
127
|
+
post_data = post['post']
|
128
|
+
author = post_data['author']
|
129
|
+
record = post_data['record']
|
130
|
+
embed = post_data['embed']
|
131
|
+
|
132
|
+
text = record['text'].gsub("\n", "<br>")
|
133
|
+
author_name = author['displayName']
|
134
|
+
author_handle = author['handle']
|
135
|
+
post_time = "3h"
|
136
|
+
|
137
|
+
image_html = ''
|
138
|
+
if embed && embed['$type'] == 'app.bsky.embed.images#view'
|
139
|
+
image_html = embed['images'].map do |image|
|
140
|
+
<<~HTML
|
141
|
+
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
142
|
+
HTML
|
143
|
+
end.join
|
144
|
+
end
|
145
|
+
|
146
|
+
<<~HTML
|
147
|
+
<div class="bluesky-post">
|
148
|
+
<div class="bluesky-header">
|
149
|
+
<img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
|
150
|
+
<div class="bluesky-author-info">
|
151
|
+
<span class="author-name">#{author_name}</span>
|
152
|
+
<span class="author-handle">@#{author_handle} · #{post_time}</span>
|
153
|
+
</div>
|
154
|
+
</div>
|
155
|
+
<div class="bluesky-content">
|
156
|
+
<p>#{text}</p>
|
157
|
+
#{image_html}
|
158
|
+
</div>
|
159
|
+
<div class="bluesky-footer">
|
160
|
+
<span class="icon">💬 #{post_data['replyCount']}</span>
|
161
|
+
<span class="icon">🔁 #{post_data['repostCount']}</span>
|
162
|
+
<span class="icon">❤️ #{post_data['likeCount']}</span>
|
163
|
+
<span class="icon">···</span>
|
93
164
|
</div>
|
94
165
|
</div>
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
<span>🔁 #{post_data['repostCount']}</span>
|
102
|
-
<span>💬 #{post_data['replyCount']}</span>
|
103
|
-
</div>
|
104
|
-
</div>
|
105
|
-
HTML
|
106
|
-
end.join("\n")
|
166
|
+
HTML
|
167
|
+
end.join("\n")
|
168
|
+
|
169
|
+
styles + formatted_posts
|
170
|
+
end
|
171
|
+
|
107
172
|
end
|
108
|
-
end
|
109
173
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
174
|
+
class FileCache
|
175
|
+
def initialize(path)
|
176
|
+
@cache_folder = File.expand_path path
|
177
|
+
FileUtils.mkdir_p @cache_folder
|
178
|
+
end
|
115
179
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
180
|
+
def read(key)
|
181
|
+
file_to_read = cache_file(key)
|
182
|
+
File.read(file_to_read) if File.exist?(file_to_read)
|
183
|
+
end
|
120
184
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
185
|
+
def write(key, data)
|
186
|
+
file_to_write = cache_file(key)
|
187
|
+
File.open(file_to_write, 'w') do |f|
|
188
|
+
f.write(data)
|
189
|
+
end
|
125
190
|
end
|
126
|
-
end
|
127
191
|
|
128
|
-
|
192
|
+
private
|
129
193
|
|
130
|
-
|
131
|
-
|
194
|
+
def cache_file(key)
|
195
|
+
File.join(@cache_folder, "#{key}.cache")
|
196
|
+
end
|
132
197
|
end
|
133
198
|
end
|
134
|
-
end
|
135
199
|
|
136
|
-
# Register the Liquid tag
|
137
|
-
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|
200
|
+
# Register the Liquid tag
|
201
|
+
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|