jekyll-bluesky 0.10.0 → 0.12.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: 85f2af2d74ed6e880920b931d53b83e48dd060426762265193a44a10ac6d0441
4
- data.tar.gz: e0a54a887ab33a4639600e6ecd00099661a81198dddbaf5859210a1bae2644c2
3
+ metadata.gz: b99ca50ea8fe4e2638f5a302deacf09e97bcbecd8069e361d781cd8fa19b8179
4
+ data.tar.gz: 5631fd6df6e75c4da2837bd58e254412a428f130237cae9f42b89242f869d2e4
5
5
  SHA512:
6
- metadata.gz: 54b30a60736bc6b5812a7a283c87ffa336022d3ed5f6c3f80da66f0ac7658a247f3677e1e0f95fc7defc3a16f0c5d06abc72bea695aa2470f0ec690bd15f0318
7
- data.tar.gz: 6e273c19b4a1a60a37e58b93b2f81d3cd3069bb0a56227ef17cf5f7f9540130220979e0dd5a4b476631bfdc89275f5575e2cd8dee91982d94d5757bdd665c6af
6
+ metadata.gz: 249d7ddba3aa9cba3ad066149ffda4debe5ad89f428dd7267153176ba55bd1eec1586159058d345d7bbb03b0a76fc24dcd01cf20f83d3f9804e82046e9629de6
7
+ data.tar.gz: 9d1ede5999d1848f6aa3e216435a0afc6c0c0984f8fa847451717019024e617ff049391fc4eafa2ca4d4a2ee3e77b9ad0c02041103f6682e26bf0a9fb7c1cbfa
@@ -1,6 +1,6 @@
1
1
  # lib/jekyll-bluesky/version.rb
2
2
  module Jekyll
3
3
  module Bluesky
4
- VERSION = "0.10.0"
4
+ VERSION = "0.12.0"
5
5
  end
6
6
  end
@@ -0,0 +1,131 @@
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
19
+
20
+ def render(context)
21
+ Jekyll.logger.debug "Rendering bluesky tag..."
22
+ bluesky_posts = fetch_posts
23
+ bluesky_posts
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 = 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
+ class Client
47
+ API_URL = "https://public.api.bsky.app"
48
+
49
+ def self.fetch_post(actor, limit)
50
+ response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
51
+ if response.status.success?
52
+ data = JSON.parse(response.body)
53
+ format_post(data)
54
+ else
55
+ "Error fetching post from Bluesky."
56
+ end
57
+ end
58
+
59
+ def self.format_post(data)
60
+ posts = data["feed"]
61
+ posts.map do |post|
62
+ post_data = post["post"]
63
+ author = post_data["author"]
64
+ record = post_data["record"]
65
+ embed = post_data["embed"]
66
+
67
+ text = record["text"]
68
+ author_name = author["displayName"]
69
+ author_handle = author["handle"]
70
+
71
+ image_html = ""
72
+ if embed && embed["$type"] == "app.bsky.embed.images#view"
73
+ image_html = embed["images"].map do |image|
74
+ <<~HTML
75
+ <img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
76
+ HTML
77
+ end.join
78
+ end
79
+
80
+ <<~HTML
81
+ <div class="bluesky-post">
82
+ <div class="bluesky-author">
83
+ <img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
84
+ <div class="bluesky-author-info">
85
+ <strong>#{author_name}</strong>
86
+ <small>@#{author_handle}</small>
87
+ </div>
88
+ </div>
89
+ <div class="bluesky-content">
90
+ <p>#{text}</p>
91
+ #{image_html}
92
+ </div>
93
+ <div class="bluesky-stats">
94
+ <span>❤️ #{post_data["likeCount"]}</span>
95
+ <span>🔁 #{post_data["repostCount"]}</span>
96
+ <span>💬 #{post_data["replyCount"]}</span>
97
+ </div>
98
+ </div>
99
+ HTML
100
+ end.join("\n")
101
+ end
102
+ end
103
+
104
+ class FileCache
105
+ def initialize(path)
106
+ @cache_folder = File.expand_path path
107
+ FileUtils.mkdir_p @cache_folder
108
+ end
109
+
110
+ def read(key)
111
+ file_to_read = cache_file(key)
112
+ File.read(file_to_read) if File.exist?(file_to_read)
113
+ end
114
+
115
+ def write(key, data)
116
+ file_to_write = cache_file(key)
117
+ File.open(file_to_write, "w") do |f|
118
+ f.write(data)
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def cache_file(key)
125
+ File.join(@cache_folder, "#{key}.cache")
126
+ end
127
+ end
128
+ end
129
+
130
+ # Register the Liquid tag
131
+ 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.10.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Dias
@@ -47,9 +47,8 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - lib/jekyll-bluesky/bluesky.rb
50
+ - lib/jekyll-bluesky.rb
51
51
  - lib/jekyll-bluesky/version.rb
52
- - lib/jekyll_bluesky.rb
53
52
  homepage: https://github.com/fdoliv/jekyll-bluesky
54
53
  licenses:
55
54
  - MIT
@@ -1,67 +0,0 @@
1
- # lib/jekyll-bluesky/bluesky.rb
2
- module Jekyll
3
- module Bluesky
4
- class Client
5
- API_URL = "https://public.api.bsky.app" # Substitua pela URL correta da API do Bluesky
6
-
7
- def self.fetch_post(actor, limit)
8
- response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
9
- if response.status.success?
10
- data = JSON.parse(response.body)
11
- format_post(data)
12
- else
13
- "Error fetching post from Bluesky."
14
- end
15
- end
16
-
17
- def self.format_post(data)
18
- posts = data["feed"] # Acessa a lista de posts
19
- posts.map do |post|
20
- post_data = post["post"]
21
- author = post_data["author"]
22
- record = post_data["record"]
23
- embed = post_data["embed"]
24
-
25
- # Extrai o texto do post
26
- text = record["text"]
27
-
28
- # Formata o nome do autor e o handle
29
- author_name = author["displayName"]
30
- author_handle = author["handle"]
31
-
32
- # Extrai a imagem (se houver)
33
- image_html = ""
34
- if embed && embed["$type"] == "app.bsky.embed.images#view"
35
- image_html = embed["images"].map do |image|
36
- <<~HTML
37
- <img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
38
- HTML
39
- end.join
40
- end
41
-
42
- # Gera o HTML do post
43
- <<~HTML
44
- <div class="bluesky-post">
45
- <div class="bluesky-author">
46
- <img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
47
- <div class="bluesky-author-info">
48
- <strong>#{author_name}</strong>
49
- <small>@#{author_handle}</small>
50
- </div>
51
- </div>
52
- <div class="bluesky-content">
53
- <p>#{text}</p>
54
- #{image_html}
55
- </div>
56
- <div class="bluesky-stats">
57
- <span>❤️ #{post_data["likeCount"]}</span>
58
- <span>🔁 #{post_data["repostCount"]}</span>
59
- <span>💬 #{post_data["replyCount"]}</span>
60
- </div>
61
- </div>
62
- HTML
63
- end.join("\n")
64
- end
65
- end
66
- end
67
- end
@@ -1,131 +0,0 @@
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 sucessfuly!"
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
-
20
- def render(context)
21
- Jekyll.logger.debug "Rendering bluesky tag..."
22
- bluesky_posts = fetch_posts
23
- bluesky_posts
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 = 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
- class Client
47
- API_URL = "https://public.api.bsky.app"
48
-
49
- def self.fetch_post(actor, limit)
50
- response = HTTP.get("#{API_URL}/xrpc/app.bsky.feed.getAuthorFeed?actor=#{actor}&limit=#{limit}&filter=posts_and_author_threads")
51
- if response.status.success?
52
- data = JSON.parse(response.body)
53
- format_post(data)
54
- else
55
- "Error fetching post from Bluesky."
56
- end
57
- end
58
-
59
- def self.format_post(data)
60
- posts = data["feed"]
61
- posts.map do |post|
62
- post_data = post["post"]
63
- author = post_data["author"]
64
- record = post_data["record"]
65
- embed = post_data["embed"]
66
-
67
- text = record["text"]
68
- author_name = author["displayName"]
69
- author_handle = author["handle"]
70
-
71
- image_html = ""
72
- if embed && embed["$type"] == "app.bsky.embed.images#view"
73
- image_html = embed["images"].map do |image|
74
- <<~HTML
75
- <img src="#{image['thumb']}" alt="#{image['alt']}" class="bluesky-image" />
76
- HTML
77
- end.join
78
- end
79
-
80
- <<~HTML
81
- <div class="bluesky-post">
82
- <div class="bluesky-author">
83
- <img src="#{author['avatar']}" alt="#{author_name}" class="bluesky-avatar" />
84
- <div class="bluesky-author-info">
85
- <strong>#{author_name}</strong>
86
- <small>@#{author_handle}</small>
87
- </div>
88
- </div>
89
- <div class="bluesky-content">
90
- <p>#{text}</p>
91
- #{image_html}
92
- </div>
93
- <div class="bluesky-stats">
94
- <span>❤️ #{post_data["likeCount"]}</span>
95
- <span>🔁 #{post_data["repostCount"]}</span>
96
- <span>💬 #{post_data["replyCount"]}</span>
97
- </div>
98
- </div>
99
- HTML
100
- end.join("\n")
101
- end
102
- end
103
- end
104
-
105
- class FileCache
106
- def initialize(path)
107
- @cache_folder = File.expand_path path
108
- FileUtils.mkdir_p @cache_folder
109
- end
110
-
111
- def read(key)
112
- file_to_read = cache_file(key)
113
- File.read(file_to_read) if File.exist?(file_to_read)
114
- end
115
-
116
- def write(key, data)
117
- file_to_write = cache_file(key)
118
- File.open(file_to_write, "w") do |f|
119
- f.write(data)
120
- end
121
- end
122
-
123
- private
124
-
125
- def cache_file(key)
126
- File.join(@cache_folder, "#{key}.cache")
127
- end
128
- end
129
- end
130
-
131
- Liquid::Template.register_tag "bluesky", self