jekyll-activity-pub 0.3.0rc2 → 0.3.0rc4

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: 24722f4f80296b16a8e845d28e7864c001c7dde35517bb797201e503e1219fec
4
- data.tar.gz: e49e896e300c74eb27785e5dba183cd473424ead02e7453e1223ed4d97df8703
3
+ metadata.gz: bb938546e87448c714988213943b785dc80e45f8732f1467a5194d9062676155
4
+ data.tar.gz: b3bcd5a07570d8d631c80fd1572e129f7b74d907016be00f81befb48be04beab
5
5
  SHA512:
6
- metadata.gz: b8456a7a10668b22bce6ab5581b9bb47d854ba04955c8ab47711d9842cfa4f82e085a1fb03e305513628106cc24fe7bbb5c91c09f25b71e5d92ed84efb49a75a
7
- data.tar.gz: 627ccc89d7ed1bdd069eb61fb9eb15e9ce5faeeada32c28241cdf79fecc472b4de3f0dd3160da920b63afdbba9bf5b2118525fd8c70a5ebd785863c617270843
6
+ metadata.gz: 3a6ab712cf1a359bcb43a2f122b8b773899adcf63a937e4493d1e8f71d2dae11da8f0bce678f50effde0a75a363de49adc530c643605335094818fa39de04627
7
+ data.tar.gz: 1d53716211728821b983f3bcc0fb6eb2a2722a310aba0cbb52aeb76225729977ab4e22cbc5558b8e3e8b4185d4bba49a1466a4b35b8d4d8fcdf3cf70e02fc413
@@ -16,6 +16,18 @@ module Jekyll
16
16
  # Some filters needs a Liquid-like context
17
17
  StubContext = Struct.new(:registers, keyword_init: true)
18
18
 
19
+ # Convert into a dereferentiable object
20
+ #
21
+ # @return [Jekyll::Drops::ActivityDrop]
22
+ def to_liquid
23
+ @to_liquid ||=
24
+ begin
25
+ require 'jekyll/drops/activity_drop'
26
+
27
+ Jekyll::Drops::ActivityDrop.new(self)
28
+ end
29
+ end
30
+
19
31
  # Removes empty values from data
20
32
  #
21
33
  # @return [Hash]
@@ -7,6 +7,7 @@ require 'distributed_press/v1/social/client'
7
7
  require 'distributed_press/v1/social/inbox'
8
8
  require 'distributed_press/v1/social/outbox'
9
9
  require 'distributed_press/v1/social/replies'
10
+ require 'distributed_press/v1/social/dereferencer'
10
11
  require_relative 'errors'
11
12
  require_relative 'create'
12
13
  require_relative 'update'
@@ -56,11 +57,19 @@ module Jekyll
56
57
  @@site
57
58
  end
58
59
 
60
+ def dereferencer
61
+ @@dereferencer ||= DistributedPress::V1::Social::Dereferencer.new(client: client)
62
+ end
63
+
59
64
  # Announce the website?
60
65
  def announce?
61
66
  !!config['announce']
62
67
  end
63
68
 
69
+ def manually_approves_followers?
70
+ !!config['manually_approves_followers']
71
+ end
72
+
64
73
  def url
65
74
  config['url'].tap do |u|
66
75
  abort_if_missing('activity_pub.url', u, '_config.yml')
@@ -129,7 +138,7 @@ module Jekyll
129
138
  actor_object = object_for(site.in_dest_dir(actor_url.sub(site.config['url'], '')))
130
139
 
131
140
  # Create/Update inbox
132
- unless (response = inbox.create(actor_url, announce?)).ok?
141
+ unless (response = inbox.create(actor_url, announce: announce?, manually_approves_followers: manually_approves_followers?)).ok?
133
142
  raise NotificationError, "Couldn't create/update inbox (#{response.code}: #{response.message})"
134
143
  end
135
144
 
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'distributed_press/v1/social/referenced_object'
4
+ require 'jekyll/activity_pub/notifier'
5
+
6
+ class DistributedPress
7
+ module V1
8
+ module Social
9
+ module Liquid
10
+ def to_liquid
11
+ @to_liquid ||=
12
+ begin
13
+ if object.success?
14
+ Jekyll::Drops::ActivityDrop.new(object: object.parsed_response)
15
+ else
16
+ Jekyll.logger.warn 'ActivityPub:', "Couldn't download #{object.request.uri} (Status: #{object.code})"
17
+ {}
18
+ end
19
+ rescue Exception => e
20
+ Jekyll.logger.warn 'ActivityPub:', "Couldn't download (Error: #{e.message})"
21
+ {}
22
+ end
23
+ end
24
+
25
+ def to_h
26
+ if object.success?
27
+ object.parsed_response.to_json
28
+ else
29
+ Jekyll.logger.warn 'ActivityPub:', "Couldn't download #{object.request.uri} (Status: #{object.code})"
30
+
31
+ {}
32
+ end
33
+ end
34
+
35
+ def to_s
36
+ to_json
37
+ end
38
+
39
+ def to_json
40
+ if object.success?
41
+ object.parsed_response.to_json
42
+ else
43
+ Jekyll.logger.warn 'ActivityPub:', "Couldn't download #{object.request.uri} (Status: #{object.code})"
44
+
45
+ object.request.uri
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ DistributedPress::V1::Social::Reference.include DistributedPress::V1::Social::Liquid
54
+
55
+ module Jekyll
56
+ module Drops
57
+ # Converts an activity into a liquid drop that can be dereferenced on
58
+ # demand.
59
+ class ActivityDrop < Drop
60
+ extend Forwardable
61
+
62
+ mutable false
63
+
64
+ # Iterate over all items of a collection
65
+ #
66
+ # @return [Array]
67
+ def all_items
68
+ return nil unless @obj.respond_to?(:each)
69
+
70
+ @all_items ||= @obj.each.to_a
71
+ end
72
+
73
+ # This means we could dereference the object, Liquid can use it to
74
+ # check if it's possible to use it.
75
+ def available
76
+ true
77
+ end
78
+
79
+ # @todo Still no idea why Liquid/Jekyll initialize this with
80
+ # different objects
81
+ def initialize(obj)
82
+ id =
83
+ case obj
84
+ when Jekyll::Page
85
+ obj['id'] || obj.url
86
+ when DistributedPress::V1::Social::ReferencedObject
87
+ obj['id']
88
+ when Hash
89
+ obj[:object]['id']
90
+ end
91
+
92
+ raise StandardError unless id
93
+
94
+ Jekyll.logger.info 'ActivityPub:', "Referencing #{id}"
95
+
96
+ @original_obj = obj
97
+ @@objects ||= {}
98
+ @obj = @@objects[id] ||=
99
+ case obj
100
+ when Jekyll::Page
101
+ DistributedPress::V1::Social::ReferencedObject.new(object: JSON.parse(obj.to_json), dereferencer: Jekyll::ActivityPub::Notifier.dereferencer)
102
+ when DistributedPress::V1::Social::ReferencedObject
103
+ obj
104
+ when Hash
105
+ obj[:object]
106
+ else raise StandardError
107
+ end
108
+ rescue StandardError => e
109
+ Jekyll.logger.warn 'ActivityPub:', "Error"
110
+ end
111
+
112
+ def to_s
113
+ @obj.object.to_json
114
+ end
115
+
116
+ def fallback_data
117
+ @obj
118
+ end
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-activity-pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0rc2
4
+ version: 0.3.0rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sutty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: distributed-press-api-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0rc2
19
+ version: 0.5.0rc8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0rc2
26
+ version: 0.5.0rc8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jekyll
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +128,20 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: sutty-liquid
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
131
145
  description:
132
146
  email:
133
147
  - sutty@riseup.net
@@ -178,6 +192,7 @@ files:
178
192
  - lib/jekyll/command_extension.rb
179
193
  - lib/jekyll/commands/generate_keys.rb
180
194
  - lib/jekyll/commands/notify.rb
195
+ - lib/jekyll/drops/activity_drop.rb
181
196
  homepage: https://jekyll-activity-pub.sutty.nl/
182
197
  licenses:
183
198
  - Apache-2.0