jekyll-web_monetization 0.1.0 → 0.2.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: 66a55b8794510dcfdd63abdb8da667e883c099a59aa4994e81e14f824669591a
4
- data.tar.gz: 1c2b20c342db264420198ff77dbe92e861ebf5c22c8d4d6a651d1a3ec37acca6
3
+ metadata.gz: a26bb61c7ad97c32462eff966235ee259b18fe851c0ddc68ea9dd395609dc794
4
+ data.tar.gz: '0213983c7ff52d7fbf830bf7d31a27c55efdd7a0015ee0370c145e05d37466f1'
5
5
  SHA512:
6
- metadata.gz: 3390c1ebd6477037b79b1a96349688119fc5d2d0693ecc37f56af48b88f74131da3d1b16c7004180aa1aa355eca13e0d08e5c26742a75ff53f57525beb72eb3f
7
- data.tar.gz: 291f25d54bfbd7a9309777931bf8bc9b9c51d92d8ab4eb2717c62fd15e795a0f9cf3e92a1b1c4595c0af394918d14ba2f795c0b934b194d6c0704f4add210b74
6
+ metadata.gz: 8bcb264668de2d62b92ff8ea951b5816f4b506dcb3caeda80395fe1fe114a27235f6691baf2701edbb3567de81b1d2d4ab2614125d57d3071637fe81cf31c31a
7
+ data.tar.gz: 93fc971c1ebf79afa4a3448505dddbe8258193221c8d3ca94518896b791bd7c7a828891a5b7ff470039f370c80683444b3d268875f86b26e0a315e04fb3ac838
data/.gitignore CHANGED
@@ -10,4 +10,6 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
- .jekyll-cache
13
+ .jekyll-cache
14
+
15
+ Gemfile.lock
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## Ongoing [☰](https://github.com/philnash/jekyll-brotli/compare/v2.2.1...master)
4
+
5
+ ...
6
+
7
+ ## 0.2.0 (2020-06-08) [☰](https://github.com/philnash/jekyll-web_monetization/compare/v0.1.0...v0.2.0)
8
+
9
+ ### Added
10
+
11
+ - If the payment pointer in the config or front matter is set to an array or hash, the liquid tag will produce JavaScript that will choose a payment pointer on page load
12
+
13
+ ## 0.1.0 (2020-06-02) [☰](https://github.com/philnash/jekyll-web_monetization/commits/v0.1.0)
14
+
15
+ ### Added
16
+
17
+ - Liquid tag that puts a Web Monetization meta tag on the page if it has a payment pointer in the site config or page front matter
data/README.md CHANGED
@@ -66,6 +66,38 @@ payment_pointer: $securewallet.example/~bob
66
66
  ---
67
67
  ```
68
68
 
69
+ ### Probabilistic Revenue Sharing
70
+
71
+ A site, page or post may be the work of more than one person. This plugin supports providing more than one payment pointer to enable [probabilistic revenue sharing](https://webmonetization.org/docs/probabilistic-rev-sharing).
72
+
73
+ If, in your `_config.yml` or front matter for any page, you provide an array of payment pointers or a hash of payment pointers and weights, then the plugin will generate JavaScript to choose a payment pointer on each page load.
74
+
75
+ #### Array of payment pointers
76
+
77
+ You can define an array of payment pointers like this:
78
+
79
+ ```yml
80
+ payment_pointer:
81
+ - $securewallet.example/~alice
82
+ - $securewallet.example/~bob
83
+ ```
84
+
85
+ Each payment pointer will be given an equal chance of appearing on the page each page load.
86
+
87
+ #### Hash of payment pointers and weights
88
+
89
+ You can also give payment pointers different weights. They will then appear on the page in a ratio based on the total weights.
90
+
91
+ You define this hash of payment pointers and weights like this:
92
+
93
+ ```yml
94
+ payment_pointer:
95
+ $securewallet.example/~alice: 20
96
+ $securewallet.example/~bob: 10
97
+ ```
98
+
99
+ In this case, Alice's pointer will be added to the page twice as often as Bob's.
100
+
69
101
  ## Development
70
102
 
71
103
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require "json"
2
3
 
3
4
  module Jekyll
4
5
  module WebMonetization
@@ -6,10 +7,48 @@ module Jekyll
6
7
  def render(context)
7
8
  site_payment_pointer = context.registers[:site].config["payment_pointer"]
8
9
  page_payment_pointer = context.registers[:page]["payment_pointer"] || site_payment_pointer
9
- if page_payment_pointer
10
+ if page_payment_pointer.is_a?(Array)
11
+ pointers_with_weights = array_to_object(page_payment_pointer)
12
+ return javascript(pointers_with_weights)
13
+ elsif page_payment_pointer.is_a?(Hash)
14
+ return javascript(page_payment_pointer)
15
+ elsif page_payment_pointer.is_a?(String)
10
16
  "<meta name='monetization' content='#{page_payment_pointer}'>"
11
17
  end
12
18
  end
19
+
20
+ private
21
+
22
+ def array_to_object(pointers)
23
+ pointers.reduce({}) { |acc, pointer| acc[pointer] = 1; acc }
24
+ end
25
+
26
+ def javascript(pointers_with_weights)
27
+ sum = pointers_with_weights.reduce(0) { |acc, (pointer, weight)| acc + weight }
28
+ pointers = JSON.generate(pointers_with_weights)
29
+ script = <<~JAVASCRIPT
30
+ <script>
31
+ (function() {
32
+ function pickPointer(pointers, sum) {
33
+ let choice = Math.random() * sum;
34
+ for (const pointer in pointers) {
35
+ const weight = pointers[pointer];
36
+ if ((choice -= weight) <= 0) {
37
+ return pointer;
38
+ }
39
+ }
40
+ }
41
+
42
+ window.addEventListener("load", function() {
43
+ const tag = document.createElement("meta");
44
+ tag.name = "monetization";
45
+ tag.content = pickPointer(#{pointers}, #{sum});
46
+ document.head.appendChild(tag);
47
+ });
48
+ })();
49
+ </script>
50
+ JAVASCRIPT
51
+ end
13
52
  end
14
53
  end
15
54
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module WebMonetization
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-web_monetization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -69,9 +69,9 @@ files:
69
69
  - ".gitignore"
70
70
  - ".rspec"
71
71
  - ".travis.yml"
72
+ - CHANGELOG.md
72
73
  - CODE_OF_CONDUCT.md
73
74
  - Gemfile
74
- - Gemfile.lock
75
75
  - LICENSE.txt
76
76
  - README.md
77
77
  - Rakefile
@@ -1,90 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll-web_monetization (0.1.0)
5
- jekyll (>= 3.0, < 5.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.7.0)
11
- public_suffix (>= 2.0.2, < 5.0)
12
- colorator (1.1.0)
13
- concurrent-ruby (1.1.6)
14
- diff-lcs (1.3)
15
- em-websocket (0.5.1)
16
- eventmachine (>= 0.12.9)
17
- http_parser.rb (~> 0.6.0)
18
- eventmachine (1.2.7)
19
- ffi (1.13.0)
20
- forwardable-extended (2.6.0)
21
- http_parser.rb (0.6.0)
22
- i18n (1.8.2)
23
- concurrent-ruby (~> 1.0)
24
- jekyll (4.1.0)
25
- addressable (~> 2.4)
26
- colorator (~> 1.0)
27
- em-websocket (~> 0.5)
28
- i18n (~> 1.0)
29
- jekyll-sass-converter (~> 2.0)
30
- jekyll-watch (~> 2.0)
31
- kramdown (~> 2.1)
32
- kramdown-parser-gfm (~> 1.0)
33
- liquid (~> 4.0)
34
- mercenary (~> 0.4.0)
35
- pathutil (~> 0.9)
36
- rouge (~> 3.0)
37
- safe_yaml (~> 1.0)
38
- terminal-table (~> 1.8)
39
- jekyll-sass-converter (2.1.0)
40
- sassc (> 2.0.1, < 3.0)
41
- jekyll-watch (2.2.1)
42
- listen (~> 3.0)
43
- kramdown (2.2.1)
44
- rexml
45
- kramdown-parser-gfm (1.1.0)
46
- kramdown (~> 2.0)
47
- liquid (4.0.3)
48
- listen (3.2.1)
49
- rb-fsevent (~> 0.10, >= 0.10.3)
50
- rb-inotify (~> 0.9, >= 0.9.10)
51
- mercenary (0.4.0)
52
- pathutil (0.16.2)
53
- forwardable-extended (~> 2.6)
54
- public_suffix (4.0.5)
55
- rake (12.3.3)
56
- rb-fsevent (0.10.4)
57
- rb-inotify (0.10.1)
58
- ffi (~> 1.0)
59
- rexml (3.2.4)
60
- rouge (3.19.0)
61
- rspec (3.9.0)
62
- rspec-core (~> 3.9.0)
63
- rspec-expectations (~> 3.9.0)
64
- rspec-mocks (~> 3.9.0)
65
- rspec-core (3.9.2)
66
- rspec-support (~> 3.9.3)
67
- rspec-expectations (3.9.2)
68
- diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.9.0)
70
- rspec-mocks (3.9.1)
71
- diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.9.0)
73
- rspec-support (3.9.3)
74
- safe_yaml (1.0.5)
75
- sassc (2.4.0)
76
- ffi (~> 1.9)
77
- terminal-table (1.8.0)
78
- unicode-display_width (~> 1.1, >= 1.1.1)
79
- unicode-display_width (1.7.0)
80
-
81
- PLATFORMS
82
- ruby
83
-
84
- DEPENDENCIES
85
- jekyll-web_monetization!
86
- rake (~> 12.0)
87
- rspec (~> 3.0)
88
-
89
- BUNDLED WITH
90
- 2.1.4