jekyll-bluesky 0.16.0 → 0.18.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 -38
- 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: 6219088df98f489f5c7e8b8132c917e132d253db30a3444cef295559612c7328
|
4
|
+
data.tar.gz: 8b5bd0081a8aa13960460bad495236ba24dcf71bd8950a4cc1d00702f9a3dca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c614a1a78d19919256521dd7c016bd114d25565ffb3fac3b7c0c139df48fd8b574b1e2b05b7f856cb69b224356a9cae91797715b2c780dfe6042d638992814a
|
7
|
+
data.tar.gz: d193bfab19c7b2e8640a6a051742b912dac74495d6cbc16c61acd3a7b9a2b27157bac056f3c3f9b108cddccad0afc473f6f732506744e4139fbb93abbf2695eb
|
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
|
@@ -32,19 +31,19 @@ module Jekyll
|
|
32
31
|
if cached_response
|
33
32
|
cached_response
|
34
33
|
else
|
35
|
-
response =
|
34
|
+
response = Jekyll::Client.fetch_post(@actor, @limit) # Updated to use Jekyll::Client
|
36
35
|
cache.write(cache_key, response)
|
37
36
|
response
|
38
37
|
end
|
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")
|
@@ -53,31 +52,31 @@ module Jekyll
|
|
53
52
|
format_post(data)
|
54
53
|
else
|
55
54
|
error_details =
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
begin
|
56
|
+
JSON.parse(response.body)
|
57
|
+
rescue JSON::ParserError
|
58
|
+
response.body.to_s
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
61
|
+
"Error fetching post from Bluesky (status: #{response.status}). Details: #{error_details}"
|
62
|
+
end
|
64
63
|
end
|
65
64
|
|
66
65
|
def self.format_post(data)
|
67
|
-
posts = data[
|
66
|
+
posts = data['feed']
|
68
67
|
posts.map do |post|
|
69
|
-
post_data = post[
|
70
|
-
author = post_data[
|
71
|
-
record = post_data[
|
72
|
-
embed = post_data[
|
73
|
-
|
74
|
-
text = record[
|
75
|
-
author_name = author[
|
76
|
-
author_handle = author[
|
77
|
-
|
78
|
-
image_html =
|
79
|
-
if embed && embed[
|
80
|
-
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|
|
81
80
|
<<~HTML
|
82
81
|
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
83
82
|
HTML
|
@@ -98,9 +97,9 @@ module Jekyll
|
|
98
97
|
#{image_html}
|
99
98
|
</div>
|
100
99
|
<div class="bluesky-stats">
|
101
|
-
<span>❤️ #{post_data[
|
102
|
-
<span>🔁 #{post_data[
|
103
|
-
<span>💬 #{post_data[
|
100
|
+
<span>❤️ #{post_data['likeCount']}</span>
|
101
|
+
<span>🔁 #{post_data['repostCount']}</span>
|
102
|
+
<span>💬 #{post_data['replyCount']}</span>
|
104
103
|
</div>
|
105
104
|
</div>
|
106
105
|
HTML
|
@@ -121,7 +120,7 @@ module Jekyll
|
|
121
120
|
|
122
121
|
def write(key, data)
|
123
122
|
file_to_write = cache_file(key)
|
124
|
-
File.open(file_to_write,
|
123
|
+
File.open(file_to_write, 'w') do |f|
|
125
124
|
f.write(data)
|
126
125
|
end
|
127
126
|
end
|
@@ -135,4 +134,4 @@ module Jekyll
|
|
135
134
|
end
|
136
135
|
|
137
136
|
# Register the Liquid tag
|
138
|
-
Liquid::Template.register_tag
|
137
|
+
Liquid::Template.register_tag 'bluesky', Jekyll::BlueskyPlugin
|