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