jekyll-activity-pub 0.1.0rc15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85320eb7b8fa252e8e66bb733d4ab51478b379f4ebd6211c0fbc6387f425cffc
4
- data.tar.gz: 122b5349c06408910f743f255112df2acc3318cc0ede289ea5811a030fda3b65
3
+ metadata.gz: b01de6dccd0e03a7936d3c107f755e7f5d663e8d8e9622007f57a0a2ff0228d0
4
+ data.tar.gz: 4477807387c5b864b337299662f5c564f1c46407d47c213e27b264971cd3b823
5
5
  SHA512:
6
- metadata.gz: a2111ddfe7cf26d72088b000014c6ac690a731235c392e9d2cb86a7831913a53d1e27a6a6920c599a52218f275eaf29f473dc37b03b561bbc8abe64d0ddafb6c
7
- data.tar.gz: 5ec690882fbc64d533a1f02741252215e71b9a156d7697228afa5b71bbd927d4bda149d3724f88ca598bd9e58530c21f350ae5c59694e1e1a9cb0256c505be32
6
+ metadata.gz: cda61088586cd05fa26155db048fd66845a2c32e8a66c05c51d7e8624a49048e0528cb1ccb24ea1ad21ca2d71002be6b3696a12e2ad013d2d3889328ca73fd58
7
+ data.tar.gz: 7fa8b2e1c900c0e65a82b2cf96bf408574a4e40167cf9e0d0317aadcfabf7f17c2f3e05d609e4dfa3a704740b176c10adb91c97541ba4160228e09afac2583bd
@@ -72,16 +72,26 @@ module Jekyll
72
72
 
73
73
  private
74
74
 
75
+ # @return [String]
76
+ def content_warning
77
+ @content_warning ||= doc.data['content_warning'].to_s.strip
78
+ end
79
+
75
80
  # Find summary
76
81
  #
77
82
  # @return [String,nil]
78
83
  def summary
79
- @summary ||= doc.data.slice('title', 'summary').values.join(separator)
84
+ @summary ||=
85
+ if content_warning.empty?
86
+ doc.data.slice('title', 'summary').values.join(separator)
87
+ else
88
+ [content_warning, doc.data['title']].join(separator)
89
+ end
80
90
  end
81
91
 
82
92
  # Should it have a content warning?
83
93
  def sensitive?
84
- !!doc.data.fetch('sensitive', false)
94
+ !content_warning.empty? || !!doc.data.fetch('sensitive', false)
85
95
  end
86
96
 
87
97
  # Separator to join title and summary by
@@ -26,7 +26,6 @@ module Jekyll
26
26
  Notifier.actor_url = data['id']
27
27
  Notifier.actor = "@#{username}@#{hostname}"
28
28
 
29
- data['following'] = Notifier.following_url
30
29
  data['followers'] = Notifier.followers_url
31
30
 
32
31
  trigger_hooks :post_init
@@ -57,7 +56,7 @@ module Jekyll
57
56
  'icon' => icons.first,
58
57
  'image' => images.first,
59
58
  'publicKey' => nil,
60
- 'published' => date.xmlschema,
59
+ 'published' => published.xmlschema,
61
60
  'updated' => updated.xmlschema,
62
61
  'attachment' => [
63
62
  PropertyValue.new(website_name, website_link)
@@ -67,7 +66,7 @@ module Jekyll
67
66
 
68
67
  # @return [Time]
69
68
  def date
70
- @date ||= site.config.dig('activity_pub', 'published') || site.time
69
+ published
71
70
  end
72
71
 
73
72
  private
@@ -77,21 +76,6 @@ module Jekyll
77
76
  @updated ||= site.config.dig('activity_pub', 'updated') || site.time
78
77
  end
79
78
 
80
- # Finds public name
81
- #
82
- # @return [String,nil]
83
- def public_name
84
- @public_name ||= find_best_value_for(site.config, %w[activity_pub public_name], 'title') || username
85
- end
86
-
87
- # Find summary between site tagline or description, reusing fields
88
- # that are used on jekyll-seo-tag
89
- #
90
- # @return [String,nil]
91
- def summary
92
- @summary ||= find_best_value_for(site.config, %w[activity_pub summary], 'tagline', 'description')
93
- end
94
-
95
79
  # Find icons
96
80
  #
97
81
  # @return [Array]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ordered_collection'
4
+
5
+ module Jekyll
6
+ module ActivityPub
7
+ # An empty collection of followed actors
8
+ class Following < OrderedCollection
9
+ # Initialize with default data
10
+ #
11
+ # @param :site [Jekyll::Site]
12
+ # @param :actor [Jekyll::ActivityPub::Actor]
13
+ # @param :base [String]
14
+ # @param :dir [String]
15
+ # @param :name [String]
16
+ def initialize(site, actor, base = '', dir = '', name = 'following.jsonld')
17
+ super(site, base, dir, name)
18
+
19
+ actor.data['following'] = absolute_url(url)
20
+
21
+ trigger_hooks :post_init
22
+ end
23
+ end
24
+ end
25
+ end
@@ -84,6 +84,26 @@ module Jekyll
84
84
  @username ||= 'site'
85
85
  end
86
86
 
87
+ # Finds public name
88
+ #
89
+ # @return [String,nil]
90
+ def public_name
91
+ @public_name ||= find_best_value_for(site.config, %w[activity_pub public_name], 'title') || username
92
+ end
93
+
94
+ # @return [Time]
95
+ def published
96
+ @published ||= site.config.dig('activity_pub', 'published') || site.time
97
+ end
98
+
99
+ # Find summary between site tagline or description, reusing fields
100
+ # that are used on jekyll-seo-tag
101
+ #
102
+ # @return [String,nil]
103
+ def summary
104
+ @summary ||= find_best_value_for(site.config, %w[activity_pub summary], 'tagline', 'description')
105
+ end
106
+
87
107
  # Return hostname
88
108
  #
89
109
  # @return [String]
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/page'
4
+ require_relative 'helper'
5
+ require_relative 'version'
6
+
7
+ module Jekyll
8
+ module ActivityPub
9
+ # Points to site's metadata
10
+ class InstanceV1 < Jekyll::Page
11
+ include Helper
12
+
13
+ # Initialize with default data
14
+ #
15
+ # @param :site [Jekyll::Site]
16
+ # @param :base [String]
17
+ # @param :dir [String]
18
+ # @param :name [String]
19
+ def initialize(site, base = '', dir = 'api/v1', name = 'instance')
20
+ @context = StubContext.new(registers: { site: site })
21
+
22
+ super(site, base, dir, name)
23
+
24
+ trigger_hooks :post_init
25
+ end
26
+
27
+ def permalink
28
+ 'api/v1/instance/'
29
+ end
30
+
31
+ def output_ext
32
+ '.json'
33
+ end
34
+
35
+ def read_yaml(*)
36
+ self.data = {
37
+ 'uri' => hostname,
38
+ 'title' => public_name,
39
+ 'short_description' => summary,
40
+ 'description' => summary,
41
+ 'email' => email,
42
+ 'version' => Jekyll::ActivityPub::VERSION,
43
+ 'urls' => {},
44
+ 'stats' => {
45
+ 'user_count' => 1,
46
+ 'status_count' => 0,
47
+ 'domain_count' => 1
48
+ },
49
+ 'thumbnail' => conditional_absolute_url(avatar),
50
+ 'languages' => languages,
51
+ 'registrations' => false,
52
+ 'approval_required' => false,
53
+ 'invites_enabled' => false,
54
+ 'configuration' => {
55
+ 'accounts' => {},
56
+ 'statuses' => {},
57
+ 'media_attachments' => {},
58
+ 'polls' => {}
59
+ },
60
+ 'contact_account' => {
61
+ 'id' => 1,
62
+ 'username' => username,
63
+ 'acct' => username,
64
+ 'display_name' => public_name,
65
+ 'locked' => false,
66
+ 'bot' => false,
67
+ 'discoverable' => true,
68
+ 'group' => false,
69
+ 'created_at' => published.xmlschema,
70
+ 'note' => summary,
71
+ 'url' => site.config['url'],
72
+ 'uri' => site.config['url'],
73
+ 'avatar' => conditional_absolute_url(avatar),
74
+ 'avatar_static' => conditional_absolute_url(avatar),
75
+ 'header' => conditional_absolute_url(header),
76
+ 'header_static' => conditional_absolute_url(header),
77
+ 'followers_count' => 0,
78
+ 'following_count' => 0,
79
+ 'statuses_count' => 0,
80
+ 'last_status_at' => nil,
81
+ 'noindex' => false,
82
+ 'emojis' => [],
83
+ 'roles' => [],
84
+ 'fields' => []
85
+ },
86
+ 'rules' => []
87
+ }
88
+ end
89
+
90
+ def increase_local_posts_counter!
91
+ data['stats']['status_count'] += 1
92
+ data['contact_account']['statuses_count'] += 1
93
+ nil
94
+ end
95
+
96
+ def increase_last_status!(last_status)
97
+ self.last_status_at = last_status if !last_status_at || last_status_at < last_status
98
+ end
99
+
100
+ private
101
+
102
+ def last_status_at
103
+ data['contact_account']['last_status_at']
104
+ end
105
+
106
+ def last_status_at=(last_status)
107
+ data['contact_account']['last_status_at'] = last_status
108
+ end
109
+
110
+ # @return [String,nil]
111
+ def header
112
+ @header ||= [find_best_value_for(site.config, %w[activity_pub images], %w[image path])].flatten.compact.first
113
+ end
114
+
115
+ # @return [Array<String>]
116
+ def languages
117
+ @languages ||= site.config['locales'] || [locale]
118
+ end
119
+
120
+ # @return [String,nil]
121
+ def email
122
+ @email ||= find_best_value_for(site.config, %w[activity_pub email], 'email')
123
+ end
124
+
125
+ def avatar
126
+ @avatar ||= [find_best_value_for(site.config, %w[activity_pub icons], 'logo')].flatten.compact.first
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'instance_v1'
4
+
5
+ module Jekyll
6
+ module ActivityPub
7
+ # Points to site's metadata
8
+ class InstanceV2 < InstanceV1
9
+ include Helper
10
+
11
+ # Initialize with default data
12
+ #
13
+ # @param :site [Jekyll::Site]
14
+ # @param :base [String]
15
+ # @param :dir [String]
16
+ # @param :name [String]
17
+ def initialize(site, base = '', dir = 'api/v2', name = 'instance')
18
+ super(site, base, dir, name)
19
+ end
20
+
21
+ def permalink
22
+ 'api/v2/instance/'
23
+ end
24
+
25
+ def read_yaml(*)
26
+ self.data = {
27
+ 'domain' => hostname,
28
+ 'version' => Jekyll::ActivityPub::VERSION,
29
+ 'source_url' => 'https://0xacab.org/sutty/jekyll/jekyll-activity-pub',
30
+ 'title' => public_name,
31
+ 'description' => summary,
32
+ 'usage' => {
33
+ 'users' => {
34
+ 'active_month' => 1
35
+ }
36
+ },
37
+ 'thumbnail' => {
38
+ 'url' => conditional_absolute_url(avatar)
39
+ },
40
+ 'languages' => languages,
41
+ 'configuration' => {
42
+ 'urls' => {},
43
+ 'accounts' => {},
44
+ 'statuses' => {},
45
+ 'media_attachments' => {},
46
+ 'polls' => {},
47
+ 'translation' => {},
48
+ },
49
+ 'registrations' => {
50
+ 'enabled' => false,
51
+ 'approval_required' => false,
52
+ 'message' => nil
53
+ },
54
+ 'contact' => {
55
+ 'email' => email,
56
+ 'account' => {
57
+ 'id' => 1,
58
+ 'username' => username,
59
+ 'acct' => username,
60
+ 'display_name' => public_name,
61
+ 'locked' => false,
62
+ 'bot' => false,
63
+ 'discoverable' => true,
64
+ 'group' => false,
65
+ 'created_at' => published.xmlschema,
66
+ 'note' => summary,
67
+ 'url' => site.config['url'],
68
+ 'avatar' => conditional_absolute_url(avatar),
69
+ 'avatar_static' => conditional_absolute_url(avatar),
70
+ 'header' => conditional_absolute_url(header),
71
+ 'header_static' => conditional_absolute_url(header),
72
+ 'followers_count' => 0,
73
+ 'following_count' => 0,
74
+ 'statuses_count' => 0,
75
+ 'last_status_at' => nil,
76
+ 'noindex' => false,
77
+ 'emojis' => [],
78
+ 'fields' => []
79
+ },
80
+ 'rules' => []
81
+ }
82
+ }
83
+ end
84
+
85
+ def increase_local_posts_counter!
86
+ data['contact']['account']['statuses_count'] += 1
87
+ nil
88
+ end
89
+
90
+ private
91
+
92
+ def last_status_at
93
+ data['contact']['account']['last_status_at']
94
+ end
95
+
96
+ def last_status_at=(last_status)
97
+ data['contact']['account']['last_status_at'] = last_status
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/page'
4
+ require_relative 'helper'
5
+
6
+ module Jekyll
7
+ module ActivityPub
8
+ # Points to site's nodeinfo
9
+ class Nodeinfo < Jekyll::Page
10
+ include Helper
11
+
12
+ # Initialize with default data
13
+ #
14
+ # @param :site [Jekyll::Site]
15
+ # @param :nodeinfos [Array<Nodeinfo21>]
16
+ # @param :base [String]
17
+ # @param :dir [String]
18
+ # @param :name [String]
19
+ def initialize(site, nodeinfos, base = '', dir = '.well-known', name = 'webfinger')
20
+ @context = StubContext.new(registers: { site: site })
21
+ @nodeinfos = nodeinfos
22
+
23
+ super(site, base, dir, name)
24
+
25
+ trigger_hooks :post_init
26
+ end
27
+
28
+ def read_yaml(*)
29
+ self.data = { 'links' => @nodeinfos.map(&:to_jrd) }
30
+ end
31
+
32
+ # The nodeinfo file is expected to be at this location always
33
+ #
34
+ # @return [String]
35
+ def permalink
36
+ '.well-known/nodeinfo'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/page'
4
+ require_relative 'helper'
5
+ require_relative 'version'
6
+
7
+ module Jekyll
8
+ module ActivityPub
9
+ # Points to site's nodeinfo 2.0
10
+ class Nodeinfo20 < Jekyll::Page
11
+ include Helper
12
+
13
+ def version
14
+ '2.0'
15
+ end
16
+
17
+ # Initialize with default data
18
+ #
19
+ # @param :site [Jekyll::Site]
20
+ # @param :base [String]
21
+ # @param :dir [String]
22
+ # @param :name [String]
23
+ def initialize(site, base = '', dir = 'nodeinfo', name = version)
24
+ @context = StubContext.new(registers: { site: site })
25
+
26
+ super(site, base, dir, name)
27
+
28
+ trigger_hooks :post_init
29
+ end
30
+
31
+ def read_yaml(*)
32
+ self.data = {
33
+ 'version' => version,
34
+ 'software' => {
35
+ 'name' => 'sutty-distributed-press',
36
+ 'version' => Jekyll::ActivityPub::VERSION
37
+ },
38
+ 'protocols' => ['activitypub'],
39
+ 'services' => {},
40
+ 'openRegistrations' => false,
41
+ 'usage' => {
42
+ 'users' => {
43
+ 'total' => 1,
44
+ 'activeHalfyear' => 1,
45
+ 'activeMonth' => 1
46
+ },
47
+ 'localPosts' => 0,
48
+ 'localComments' => 0
49
+ },
50
+ 'metadata' => {}
51
+ }
52
+ end
53
+
54
+ # The nodeinfo file is expected to be at this location always
55
+ #
56
+ # @return [String]
57
+ def permalink
58
+ "nodeinfo/#{version}.json"
59
+ end
60
+
61
+ # @return [Hash]
62
+ def to_jrd
63
+ {
64
+ 'rel' => "http://nodeinfo.diaspora.software/ns/schema/#{version}",
65
+ 'href' => absolute_url(url)
66
+ }
67
+ end
68
+
69
+ # @return [nil]
70
+ def increase_local_posts_counter!
71
+ data['usage']['localPosts'] += 1
72
+ nil
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/page'
4
+ require_relative 'nodeinfo_20'
5
+
6
+ module Jekyll
7
+ module ActivityPub
8
+ # Points to site's nodeinfo 2.1
9
+ class Nodeinfo21 < Nodeinfo20
10
+ def version
11
+ '2.1'
12
+ end
13
+
14
+ def read_yaml(*)
15
+ super.tap do |data|
16
+ data['software']['repository'] = 'https://0xacab.org/sutty/jekyll/jekyll-activity-pub/'
17
+ data['software']['homepage'] = 'https://sutty.nl'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -64,11 +64,6 @@ module Jekyll
64
64
  "#{url}/v1/#{actor}/followers"
65
65
  end
66
66
 
67
- # @return [String]
68
- def following_url
69
- "#{url}/v1/#{actor}/following"
70
- end
71
-
72
67
  # Save the public key URL for later
73
68
  #
74
69
  # @param :url [String]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module ActivityPub
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -8,6 +8,12 @@ require_relative 'activity_pub/host_meta'
8
8
  require_relative 'activity_pub/create'
9
9
  require_relative 'activity_pub/update'
10
10
  require_relative 'activity_pub/public_key'
11
+ require_relative 'activity_pub/nodeinfo'
12
+ require_relative 'activity_pub/nodeinfo_20'
13
+ require_relative 'activity_pub/nodeinfo_21'
14
+ require_relative 'activity_pub/instance_v1'
15
+ require_relative 'activity_pub/instance_v2'
16
+ require_relative 'activity_pub/following'
11
17
 
12
18
  module Jekyll
13
19
  # ActivityPub
@@ -29,6 +29,23 @@ Jekyll::Hooks.register :site, :post_read, priority: :low do |site|
29
29
  site.pages << site.config['webfinger'] = webfinger = Jekyll::ActivityPub::WebFinger.new(site, actor)
30
30
  site.pages << site.config['outbox'] = Jekyll::ActivityPub::Outbox.new(site, actor)
31
31
  site.pages << site.config['host-meta'] = Jekyll::ActivityPub::HostMeta.new(site, webfinger)
32
+ site.pages << Jekyll::ActivityPub::Following.new(site, actor)
33
+
34
+ # Instances
35
+ site.config['instances'] = [Jekyll::ActivityPub::InstanceV1, Jekyll::ActivityPub::InstanceV2].map do |instance|
36
+ instance.new(site).tap do |i|
37
+ site.pages << i
38
+ end
39
+ end
40
+
41
+ # Nodeinfo
42
+ site.config['nodeinfos'] = [Jekyll::ActivityPub::Nodeinfo20, Jekyll::ActivityPub::Nodeinfo21].map do |nodeinfo|
43
+ nodeinfo.new(site).tap do |n|
44
+ site.pages << n
45
+ end
46
+ end
47
+
48
+ site.pages << site.config['nodeinfo'] = Jekyll::ActivityPub::Nodeinfo.new(site, site.config['nodeinfos'])
32
49
 
33
50
  # Add Actor to home page
34
51
  home = site.pages.find do |page|
@@ -85,6 +102,13 @@ Jekyll::Hooks.register(:documents, :post_convert, priority: :high) do |doc|
85
102
 
86
103
  outbox.data['totalItems'] += 1
87
104
  outbox.data['orderedItems'] << action
105
+
106
+ site.config['nodeinfos'].map(&:increase_local_posts_counter!)
107
+ site.config['instances'].each do |instance|
108
+ instance.increase_local_posts_counter!
109
+ instance.increase_last_status!(doc.date)
110
+ end
111
+
88
112
  site.pages << action
89
113
  end
90
114
 
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.1.0rc15
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sutty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2023-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: distributed-press-api-client
@@ -149,9 +149,15 @@ files:
149
149
  - lib/jekyll/activity_pub/delete.rb
150
150
  - lib/jekyll/activity_pub/document.rb
151
151
  - lib/jekyll/activity_pub/errors.rb
152
+ - lib/jekyll/activity_pub/following.rb
152
153
  - lib/jekyll/activity_pub/helper.rb
153
154
  - lib/jekyll/activity_pub/host_meta.rb
154
155
  - lib/jekyll/activity_pub/image.rb
156
+ - lib/jekyll/activity_pub/instance_v1.rb
157
+ - lib/jekyll/activity_pub/instance_v2.rb
158
+ - lib/jekyll/activity_pub/nodeinfo.rb
159
+ - lib/jekyll/activity_pub/nodeinfo_20.rb
160
+ - lib/jekyll/activity_pub/nodeinfo_21.rb
155
161
  - lib/jekyll/activity_pub/notifier.rb
156
162
  - lib/jekyll/activity_pub/ordered_collection.rb
157
163
  - lib/jekyll/activity_pub/ordered_collection_page.rb
@@ -160,18 +166,19 @@ files:
160
166
  - lib/jekyll/activity_pub/public_key.rb
161
167
  - lib/jekyll/activity_pub/tomsbtone.rb~
162
168
  - lib/jekyll/activity_pub/update.rb
169
+ - lib/jekyll/activity_pub/version.rb
163
170
  - lib/jekyll/activity_pub/webfinger.rb
164
171
  - lib/jekyll/command_extension.rb
165
172
  - lib/jekyll/commands/generate_keys.rb
166
173
  - lib/jekyll/commands/notify.rb
167
- homepage: https://0xacab.org/sutty/jekyll/jekyll-activity-pub
174
+ homepage: https://jekyll-activity-pub.sutty.nl/
168
175
  licenses:
169
176
  - Apache-2.0
170
177
  metadata:
171
- bug_tracker_uri: https://0xacab.org/sutty/jekyll/jekyll-activity-pub/issues
172
- homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-activity-pub
178
+ bug_tracker_uri: https://jekyll-activity-pub.sutty.nl//issues
179
+ homepage_uri: https://jekyll-activity-pub.sutty.nl/
173
180
  source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-activity-pub
174
- changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-activity-pub/-/blob/master/CHANGELOG.md
181
+ changelog_uri: https://jekyll-activity-pub.sutty.nl//-/blob/master/CHANGELOG.md
175
182
  documentation_uri: https://rubydoc.info/gems/jekyll-activity-pub
176
183
  post_install_message:
177
184
  rdoc_options:
@@ -191,9 +198,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
198
  version: '2.7'
192
199
  required_rubygems_version: !ruby/object:Gem::Requirement
193
200
  requirements:
194
- - - ">"
201
+ - - ">="
195
202
  - !ruby/object:Gem::Version
196
- version: 1.3.1
203
+ version: '0'
197
204
  requirements: []
198
205
  rubygems_version: 3.3.26
199
206
  signing_key: