jekyll-bluesky 0.4.0 → 0.6.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 +107 -2
- 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: cf2682b20a796d3c7bbbaa4d6688b113045a764a5107bee6c069a9b28cdf4cf4
|
4
|
+
data.tar.gz: dfb6d125fd348b2d72908d5cc4fa2bfbf58216ae00f263e8426df9fb4016a161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465e3c20991f12bbb9756eae92a3c621508e809a40310a3c092a3b80370d21e1e6c2ec8492c1033e485a169a8a1f44e0f14fd3077b716ab88772c9bc40dfbd2d
|
7
|
+
data.tar.gz: 530f2aef289cd2878c300cad460884d5dbe9e1d907ddade596b8507235d2721e53d46063e90e4d9eb345c8deb98ee48d70dbd5e8ec991a3a770ccf379f5a14af
|
data/lib/jekyll_bluesky.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require "jekyll"
|
3
3
|
require "http"
|
4
4
|
require "json"
|
5
|
-
require "
|
5
|
+
require "digest"
|
6
6
|
|
7
7
|
module Jekyll
|
8
8
|
class BlueskyPlugin < Liquid::Tag
|
@@ -14,9 +14,114 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def render(context)
|
17
|
-
bluesky_posts =
|
17
|
+
bluesky_posts = fetch_posts
|
18
18
|
bluesky_posts
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def fetch_posts
|
24
|
+
cache_key = Digest::MD5.hexdigest("#{@actor}-#{@limit}")
|
25
|
+
cached_response = cache.read(cache_key)
|
26
|
+
|
27
|
+
if cached_response
|
28
|
+
cached_response
|
29
|
+
else
|
30
|
+
response = Jekyll::Bluesky::Client.fetch_post(@actor, @limit)
|
31
|
+
cache.write(cache_key, response)
|
32
|
+
response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache
|
37
|
+
@cache ||= FileCache.new("./.bluesky-cache")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Bluesky
|
42
|
+
class Client
|
43
|
+
API_URL = "https://public.api.bsky.app"
|
44
|
+
|
45
|
+
def self.fetch_post(actor, limit)
|
46
|
+
response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
|
47
|
+
if response.status.success?
|
48
|
+
data = JSON.parse(response.body)
|
49
|
+
format_post(data)
|
50
|
+
else
|
51
|
+
"Error fetching post from Bluesky."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.format_post(data)
|
56
|
+
posts = data["feed"]
|
57
|
+
posts.map do |post|
|
58
|
+
post_data = post["post"]
|
59
|
+
author = post_data["author"]
|
60
|
+
record = post_data["record"]
|
61
|
+
embed = post_data["embed"]
|
62
|
+
|
63
|
+
text = record["text"]
|
64
|
+
author_name = author["displayName"]
|
65
|
+
author_handle = author["handle"]
|
66
|
+
|
67
|
+
image_html = ""
|
68
|
+
if embed && embed["$type"] == "app.bsky.embed.images#view"
|
69
|
+
image_html = embed["images"].map do |image|
|
70
|
+
<<~HTML
|
71
|
+
<img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
|
72
|
+
HTML
|
73
|
+
end.join
|
74
|
+
end
|
75
|
+
|
76
|
+
<<~HTML
|
77
|
+
<div class="bluesky-post">
|
78
|
+
<div class="bluesky-author">
|
79
|
+
<img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
|
80
|
+
<div class="bluesky-author-info">
|
81
|
+
<strong>#{author_name}</strong>
|
82
|
+
<small>@#{author_handle}</small>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
<div class="bluesky-content">
|
86
|
+
<p>#{text}</p>
|
87
|
+
#{image_html}
|
88
|
+
</div>
|
89
|
+
<div class="bluesky-stats">
|
90
|
+
<span>❤️ #{post_data["likeCount"]}</span>
|
91
|
+
<span>🔁 #{post_data["repostCount"]}</span>
|
92
|
+
<span>💬 #{post_data["replyCount"]}</span>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
HTML
|
96
|
+
end.join("\n")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class FileCache
|
102
|
+
def initialize(path)
|
103
|
+
@cache_folder = File.expand_path path
|
104
|
+
FileUtils.mkdir_p @cache_folder
|
105
|
+
end
|
106
|
+
|
107
|
+
def read(key)
|
108
|
+
file_to_read = cache_file(key)
|
109
|
+
File.read(file_to_read) if File.exist?(file_to_read)
|
110
|
+
end
|
111
|
+
|
112
|
+
def write(key, data)
|
113
|
+
file_to_write = cache_file(key)
|
114
|
+
|
115
|
+
File.open(file_to_write, "w") do |f|
|
116
|
+
f.write(data)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def cache_file(key)
|
123
|
+
File.join(@cache_folder, "#{key}.cache")
|
124
|
+
end
|
20
125
|
end
|
21
126
|
end
|
22
127
|
|