jekyll-bluesky 0.15.0 → 0.17.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 +2 -2
- data/lib/jekyll-bluesky.rb +37 -32
- 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: 0bf0291aa34cde18207f4d47bddd9422227e774428dbe7c75274df6cfeb7ab7c
|
4
|
+
data.tar.gz: 6ecf41a487fa282c2bc42b2dd23bb0aed2ab0b7a41cc67eaf1e7393f30e91419
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2a5df6e1a03bcb9210724a400e2d7292431d52e19429d3d3dca9785fc0d37147525c12952b2d4d48948ccebefe740068917793e9d8093f48744d54b2e99fab
|
7
|
+
data.tar.gz: 2003c829bd738a950ac81f9a7360ffd99396c3e9e77721c5baf2de48027af9814d650be0999cd31479a77127f04d63f89f6180f197c0c226ca7889ed64e622e4
|
data/lib/jekyll-bluesky.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# lib/jekyll_bluesky.rb
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
2
|
+
require 'jekyll'
|
3
|
+
require 'http'
|
4
|
+
require 'json'
|
5
|
+
require 'digest'
|
6
|
+
require 'fileutils' # Needed for FileCache
|
7
7
|
|
8
|
-
puts
|
8
|
+
puts 'Plugin jekyll-bluesky load successfully!'
|
9
9
|
|
10
10
|
module Jekyll
|
11
11
|
class BlueskyPlugin < Liquid::Tag
|
@@ -13,14 +13,13 @@ module Jekyll
|
|
13
13
|
super
|
14
14
|
args = text.strip.split
|
15
15
|
@actor = args[0]
|
16
|
-
@limit = args[1] ||
|
16
|
+
@limit = args[1] || '10'
|
17
17
|
Jekyll.logger.debug "Initializing tag bluesky with actor: #{@actor}, limit: #{@limit}"
|
18
18
|
end
|
19
19
|
|
20
20
|
def render(context)
|
21
|
-
Jekyll.logger.debug
|
22
|
-
|
23
|
-
bluesky_posts
|
21
|
+
Jekyll.logger.debug 'Rendering bluesky tag...'
|
22
|
+
fetch_posts
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
@@ -39,12 +38,12 @@ module Jekyll
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def cache
|
42
|
-
@cache ||= FileCache.new(
|
41
|
+
@cache ||= FileCache.new('./.bluesky-cache')
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
45
|
class Client
|
47
|
-
API_URL =
|
46
|
+
API_URL = 'https://public.api.bsky.app'
|
48
47
|
|
49
48
|
def self.fetch_post(actor, limit)
|
50
49
|
response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
|
@@ -52,26 +51,32 @@ module Jekyll
|
|
52
51
|
data = JSON.parse(response.body)
|
53
52
|
format_post(data)
|
54
53
|
else
|
55
|
-
|
56
|
-
|
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}"
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def self.format_post(data)
|
61
|
-
posts = data[
|
66
|
+
posts = data['feed']
|
62
67
|
posts.map do |post|
|
63
|
-
post_data = post[
|
64
|
-
author = post_data[
|
65
|
-
record = post_data[
|
66
|
-
embed = post_data[
|
67
|
-
|
68
|
-
text = record[
|
69
|
-
author_name = author[
|
70
|
-
author_handle = author[
|
71
|
-
|
72
|
-
image_html =
|
73
|
-
if embed && embed[
|
74
|
-
image_html = embed[
|
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']
|
74
|
+
author_name = author['displayName']
|
75
|
+
author_handle = author['handle']
|
76
|
+
|
77
|
+
image_html = ''
|
78
|
+
if embed && embed['$type'] == 'app.bsky.embed.images#view'
|
79
|
+
image_html = embed['images'].map do |image|
|
75
80
|
<<~HTML
|
76
81
|
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
77
82
|
HTML
|
@@ -92,9 +97,9 @@ module Jekyll
|
|
92
97
|
#{image_html}
|
93
98
|
</div>
|
94
99
|
<div class="bluesky-stats">
|
95
|
-
<span>❤️ #{post_data[
|
96
|
-
<span>🔁 #{post_data[
|
97
|
-
<span>💬 #{post_data[
|
100
|
+
<span>❤️ #{post_data['likeCount']}</span>
|
101
|
+
<span>🔁 #{post_data['repostCount']}</span>
|
102
|
+
<span>💬 #{post_data['replyCount']}</span>
|
98
103
|
</div>
|
99
104
|
</div>
|
100
105
|
HTML
|
@@ -115,7 +120,7 @@ module Jekyll
|
|
115
120
|
|
116
121
|
def write(key, data)
|
117
122
|
file_to_write = cache_file(key)
|
118
|
-
File.open(file_to_write,
|
123
|
+
File.open(file_to_write, 'w') do |f|
|
119
124
|
f.write(data)
|
120
125
|
end
|
121
126
|
end
|
@@ -129,4 +134,4 @@ module Jekyll
|
|
129
134
|
end
|
130
135
|
|
131
136
|
# Register the Liquid tag
|
132
|
-
Liquid::Template.register_tag
|
137
|
+
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|