jekyll-activity-pub 0.2.4 → 0.2.6

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: 9694a2d1df46c23e5c6ca51bfa88fb80a7df0709014be6fc0d48cae3e3e4cc6f
4
- data.tar.gz: 3f844b85c3e200db65e7d1de6cfd25ee59b8450b18bad191bd4036731443e1ee
3
+ metadata.gz: 9b0dd7df568e8344f4d9c0c3e41cfe2cf3a2384737800d0c3b3b5120f447ed63
4
+ data.tar.gz: 8974b30de62eda46a8aa375a04f4a037ce81741f8a99181003823726c1076f10
5
5
  SHA512:
6
- metadata.gz: 95cfe56875a41b933d99cecc6788cb44823bad551e88ac152ad6c5bb3d33742945be3b14d75ac4f4e23bc85d961c8b97bb27663ebf10da4c36b0dfd3c1d279c1
7
- data.tar.gz: f44349daeaed27d6e7d8ac8ff53a55a5b5925b635ca40785a156a1a58d83de4e7b65844d202e7d4138ff9046680863b1bb314855d70f7452247f2a5707f86336
6
+ metadata.gz: dd1358be16b0324bd309e13c8c98d69166a3991025139f0929e2103ab63d2a914287a3bccec89c85ff3eb556932c63dd4150b68ee259114095f3a4f01477f949
7
+ data.tar.gz: 79a769c926dbf3dc4f6371da235e9d2b06dde561f80ececcb8ce54789e343603f04d7d9e3f852c8a219e9694af1b730eab3a5d22c8b66e6a02f5112b799394db
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implement FEP-1042 Peer to Peer Fediverse Activities by creating new
4
+ # activities and actors under supported protocols/schemes.
5
+ #
6
+ # Priority is low so it's the last thing we do. If you need to modify
7
+ # the original activities after this plugins runs, use priority lower
8
+ # than 8.
9
+ #
10
+ # The hook runs on post render so we can add the extra pages after
11
+ # activity generation but before write.
12
+ require_relative 'jekyll-activity-pub-fep-fffd'
13
+
14
+ Jekyll::Hooks.register %i[actor activity], :post_init, priority: 8 do |page|
15
+ Jekyll.logger.info 'FEP 1042:', 'Generating'
16
+
17
+ site = page.site
18
+
19
+ # @param uri [URI,Addressable::URI]
20
+ # @param protocol [String]
21
+ # @return [URI,Addressable::URI]
22
+ def add_protocol_to_uri(uri, protocol)
23
+ uri.scheme = protocol
24
+
25
+ if protocol != 'https' && uri.path.end_with?('.jsonld')
26
+ uri.path = uri.path.sub('.jsonld', ".#{protocol}.jsonld")
27
+ end
28
+
29
+ uri
30
+ end
31
+
32
+ # Changes the URLs from a base URL to have a different scheme
33
+ #
34
+ # @param object [Any]
35
+ # @param base_url [String]
36
+ # @param scheme [String]
37
+ def convert_uris(object, base_url, scheme)
38
+ case object
39
+ when Hash
40
+ object.transform_values do |value|
41
+ convert_uris(value, base_url, scheme)
42
+ end
43
+ when Array
44
+ object.map do |value|
45
+ convert_uris(value, base_url, scheme)
46
+ end
47
+ when String
48
+ if object.start_with? base_url
49
+ add_protocol_to_uri(Addressable::URI.parse(object), scheme).to_s
50
+ else
51
+ object
52
+ end
53
+ when Nokogiri::HTML5::DocumentFragment
54
+ object.dup.tap do |html|
55
+ html.css('[src]').each do |element|
56
+ element['src'] = convert_uris(element['src'], base_url, scheme)
57
+ end
58
+ end
59
+ when Jekyll::ActivityPub::Helper
60
+ convert_uris(object.data, base_url, scheme)
61
+ else
62
+ object
63
+ end
64
+ end
65
+
66
+ url = page.data['url']
67
+ formats = ['application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'application/activity+json']
68
+ data = page.pruned_data
69
+
70
+ # TODO: Fetch enabled protocols from DP API
71
+ %w[https ipns hyper bittorrent].each do |protocol|
72
+ uri = Addressable::URI.parse(page.data['id'])
73
+ add_protocol_to_uri(uri, protocol)
74
+
75
+ formats.each do |format|
76
+ url << Jekyll::ActivityPub::Link.new(site, uri.to_s, 'alternate', format)
77
+ end
78
+ end
79
+
80
+ %w[ipns hyper bittorrent].each do |protocol|
81
+ uri = Addressable::URI.parse(page.data['id'])
82
+ add_protocol_to_uri(uri, protocol)
83
+
84
+ Jekyll.logger.debug 'FEP 1042:', "Generating #{uri.path} (#{protocol})"
85
+
86
+ json = convert_uris(data, site.config['url'], protocol)
87
+ json['url'] = url
88
+ json['id'] = uri.to_s
89
+
90
+ # XXX: Only works on forward slash OSes
91
+ path = uri.path.sub(%r{\A/}, '')
92
+
93
+ Jekyll::PageWithoutAFile.new(site, site.source, File.dirname(path), File.basename(path)).tap do |alternate|
94
+ site.pages << alternate
95
+ alternate.content = json.to_json
96
+ end
97
+ end
98
+
99
+ Jekyll.logger.info 'FEP 1042:', 'Generated'
100
+ end
@@ -1,86 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Implement FEP-fffd Proxy Objects for Distributed Press by creating new
4
- # activities and actors under supported protocols/schemes.
5
- #
6
- # Priority is low so it's the last thing we do. If you need to modify
7
- # the original activities after this plugins runs, use priority 0.
8
- #
9
- # The hook runs on post render so we can add the extra pages after
10
- # activity generation but before write.
11
- Jekyll::Hooks.register :site, :post_render, priority: 1 do |site|
12
- require 'jekyll/activity_pub/link'
13
-
14
- # Changes the URLs from a base URL to have a different scheme
15
- #
16
- # @param object [Any]
17
- # @param base_url [String]
18
- # @param scheme [String]
19
- def convert_uris(object, base_url, scheme)
20
- case object
21
- when Hash
22
- object.transform_values do |value|
23
- convert_uris(value, base_url, scheme)
24
- end
25
- when Array
26
- object.map do |value|
27
- convert_uris(value, base_url, scheme)
28
- end
29
- when String
30
- if object.start_with? base_url
31
- Addressable::URI.parse(object).tap do |uri|
32
- uri.scheme = scheme
33
- end.to_s
34
- else
35
- object
36
- end
37
- when Nokogiri::HTML5::DocumentFragment
38
- object.dup.tap do |html|
39
- html.css('[src]').each do |element|
40
- element['src'] = convert_uris(element['src'], base_url, scheme)
41
- end
42
- end
43
- when Jekyll::ActivityPub::Helper
44
- convert_uris(object.data, base_url, scheme)
45
- else
46
- object
47
- end
48
- end
49
-
50
- site.pages.each do |page|
51
- case page
52
- when Jekyll::ActivityPub::Activity, Jekyll::ActivityPub::Actor
53
- uri = Addressable::URI.parse page.data['id']
54
- url = [ Jekyll::ActivityPub::Link.new(site, page.data['url'], 'canonical', 'text/html') ]
55
-
56
- %w[https ipns hyper bittorrent].each do |protocol|
57
- uri.scheme = protocol
58
- url <<
59
- Jekyll::ActivityPub::Link.new(site, uri.to_s, 'alternate', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"')
60
- url <<
61
- Jekyll::ActivityPub::Link.new(site, uri.to_s, 'alternate', 'application/activity+json')
62
- end
63
-
64
- %w[ipns hyper bittorrent].each do |protocol|
65
- json = convert_uris(page.pruned_data, site.config['url'], protocol)
66
- json['url'] = url
67
-
68
- uri = Addressable::URI.parse(json['id'])
69
- uri.path = uri.path.sub('.jsonld', ".#{protocol}.jsonld")
70
- json['id'] = uri.to_s
71
- path = uri.path.sub(%r{\A/}, '')
72
-
73
- Jekyll::PageWithoutAFile.new(site, site.source, File.dirname(path), File.basename(path)).tap do |alternate|
74
- site.pages << alternate
75
-
76
- alternate.output = alternate.content = json.to_json
77
- end
78
- end
79
-
80
- page.data['url'] = url
81
- page.output = page.content
82
-
83
- Jekyll.logger.info 'FEP fffd:', 'Generated'
84
- end
85
- end
86
- end
3
+ require_relative 'jekyll-activity-pub-fep-1042'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'jekyll-activity-pub-fep-fffd'
4
+
5
+ # Add a license to each activity by finding a page/post with layout
6
+ # "license"
7
+ Jekyll::Hooks.register :activity, :post_init, priority: 9 do |activity|
8
+ Jekyll.logger.info 'FEP fffd:', 'Adding license'
9
+
10
+ site = activity.site
11
+
12
+ # Look for a page or a post
13
+ license = site.pages.find do |page|
14
+ page.data['layout'] == 'license'
15
+ end
16
+
17
+ # Find the first one in case there are several
18
+ license ||= activity.renderer.payload['site']['posts'].find do |post|
19
+ post.data['layout'] == 'license'
20
+ end
21
+
22
+ if license
23
+ Jekyll.logger.info 'FEP fffd:', "License \"#{license.data['title']}\" found"
24
+ else
25
+ Jekyll.logger.info 'FEP fffd:', 'License not found, skipping...'
26
+ next
27
+ end
28
+
29
+ activity.data['url'] << Jekyll::ActivityPub::Link.new(site, activity.absolute_url(license.url), 'license', 'text/html')
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implement FEP-fffd Proxy Objects by changing the url attribute to an
4
+ # array of Link objects.
5
+ #
6
+ # Priority is low so it's the last thing we do. If you need to modify
7
+ # the original activities after this plugins runs, use priority lower
8
+ # than 10.
9
+ Jekyll::Hooks.register %i[actor activity], :post_init, priority: :low do |page|
10
+ require 'jekyll/activity_pub/link'
11
+
12
+ site = page.site
13
+
14
+ Jekyll.logger.info 'FEP fffd:', 'Generating'
15
+
16
+ page.data['url'] = [ Jekyll::ActivityPub::Link.new(site, page.data['url'], 'canonical', 'text/html') ]
17
+
18
+ Jekyll.logger.info 'FEP fffd:', 'Generated'
19
+ end
20
+
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.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sutty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: distributed-press-api-client
@@ -141,7 +141,10 @@ files:
141
141
  - README.md
142
142
  - lib/jekyll-activity-pub-absolute-assets.rb
143
143
  - lib/jekyll-activity-pub-assets-as-attachments.rb
144
+ - lib/jekyll-activity-pub-fep-1042.rb
144
145
  - lib/jekyll-activity-pub-fep-fffd-distributed-press.rb
146
+ - lib/jekyll-activity-pub-fep-fffd-license.rb
147
+ - lib/jekyll-activity-pub-fep-fffd.rb
145
148
  - lib/jekyll-activity-pub-link-iframes.rb
146
149
  - lib/jekyll-activity-pub-nokogiri.rb
147
150
  - lib/jekyll-activity-pub.rb