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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6219088df98f489f5c7e8b8132c917e132d253db30a3444cef295559612c7328
4
- data.tar.gz: 8b5bd0081a8aa13960460bad495236ba24dcf71bd8950a4cc1d00702f9a3dca6
3
+ metadata.gz: f3b8dede391e73193464afae55bbd33955d6a3b46adefff62cd139487bcaf826
4
+ data.tar.gz: 94a912988e99f333255be4cff19465ff4b8a13c8123625eba3b27aa50e8e3d64
5
5
  SHA512:
6
- metadata.gz: 8c614a1a78d19919256521dd7c016bd114d25565ffb3fac3b7c0c139df48fd8b574b1e2b05b7f856cb69b224356a9cae91797715b2c780dfe6042d638992814a
7
- data.tar.gz: d193bfab19c7b2e8640a6a051742b912dac74495d6cbc16c61acd3a7b9a2b27157bac056f3c3f9b108cddccad0afc473f6f732506744e4139fbb93abbf2695eb
6
+ metadata.gz: 6770bd8963df069aa835b6d34b34623e2ee12f8c9eefc20af01ad480d43ae5e1131b56b8ffbc0af6868c9c9f11ef9f98b318de7edd1f2a8ea269beaa440435fe
7
+ data.tar.gz: 13a67389c954961e08aec904176edb3a538a4333a9adf0f83c7df2a498200e89d20b7e590b2b9e570ccf78b09d105d1da3699b7d459ad6ec6b55d76f0812dbbe
@@ -1,6 +1,6 @@
1
1
  # lib/jekyll-bluesky/version.rb
2
2
  module Jekyll
3
3
  module Bluesky
4
- VERSION = '0.18.0'
4
+ VERSION = '0.20.0'
5
5
  end
6
6
  end
@@ -1,137 +1,201 @@
1
- # lib/jekyll_bluesky.rb
2
- require 'jekyll'
3
- require 'http'
4
- require 'json'
5
- require 'digest'
6
- require 'fileutils' # Needed for FileCache
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
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
- def render(context)
21
- Jekyll.logger.debug 'Rendering bluesky tag...'
22
- fetch_posts
23
- end
20
+ def render(context)
21
+ Jekyll.logger.debug 'Rendering bluesky tag...'
22
+ fetch_posts
23
+ end
24
24
 
25
- private
25
+ private
26
26
 
27
- def fetch_posts
28
- cache_key = Digest::MD5.hexdigest("#{@actor}-#{@limit}")
29
- cached_response = cache.read(cache_key)
27
+ def fetch_posts
28
+ cache_key = Digest::MD5.hexdigest("#{@actor}-#{@limit}")
29
+ cached_response = cache.read(cache_key)
30
30
 
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
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
- "Error fetching post from Bluesky (status: #{response.status}). Details: #{error_details}"
40
+ def cache
41
+ @cache ||= FileCache.new('./.bluesky-cache')
62
42
  end
63
43
  end
64
44
 
65
- def self.format_post(data)
66
- posts = data['feed']
67
- posts.map do |post|
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|
80
- <<~HTML
81
- <img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
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
- <<~HTML
87
- <div class="bluesky-post">
88
- <div class="bluesky-author">
89
- <img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
90
- <div class="bluesky-author-info">
91
- <strong>#{author_name}</strong>
92
- <small>@#{author_handle}</small>
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
- <div class="bluesky-content">
96
- <p>#{text}</p>
97
- #{image_html}
98
- </div>
99
- <div class="bluesky-stats">
100
- <span>❤️ #{post_data['likeCount']}</span>
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
- class FileCache
111
- def initialize(path)
112
- @cache_folder = File.expand_path path
113
- FileUtils.mkdir_p @cache_folder
114
- end
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
- def read(key)
117
- file_to_read = cache_file(key)
118
- File.read(file_to_read) if File.exist?(file_to_read)
119
- end
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
- def write(key, data)
122
- file_to_write = cache_file(key)
123
- File.open(file_to_write, 'w') do |f|
124
- f.write(data)
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
- private
192
+ private
129
193
 
130
- def cache_file(key)
131
- File.join(@cache_folder, "#{key}.cache")
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
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.18.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Dias