jekyll-hive 1.0.0 → 1.1.1

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: 1a498c5b88a46e157b96371105a23234fe02fbdc595ffe332615f92c5d8dbfb4
4
- data.tar.gz: e34b162f75d5225851831bb24239be567ca3e336d58d29d6549d17481b1ad356
3
+ metadata.gz: 9961c6674e4ae1f94142229767b36b906805ff0a387a09b300e9fa20e9741438
4
+ data.tar.gz: 17cea2edda4038ff804c389ff275610e0ce70db793ac234c0458345f11116d1c
5
5
  SHA512:
6
- metadata.gz: 7ba17593792b5d8f17339e20ba4ef1a6b77297ede9ced3925fa25d3b860dd70c78133df802024065b647e436df83ce9f9b07ad065c95f87c19af31fb531deaf7
7
- data.tar.gz: f4529f539627e83f5e0e063cd5ab1892671c51c8756356c0b042cb405a3fc701899238289048fc192a6151458abb749cbe48e66d53153b2fa57d4f56783436ea
6
+ metadata.gz: 8e604ce1d31b67600ab0f1be7dc159328911dcefa4a6ea8fed5128e5e19d7a0a3d53087fc5727ec624e6fa62ed85bf3ea7f15f40a0d6f091897ac2ce1328f26a
7
+ data.tar.gz: 10cce64b8f7cdedc47f35dd2f3a0dfb0f5f5bd720d5b6c4051d844406da498f720fb095a9d73fb96fe7cfc7e9b11d1c1741bf835e7f061559aaf562ffdd31448
data/README.md CHANGED
@@ -42,6 +42,14 @@ Use the tag as follows in your Jekyll pages, posts and collections:
42
42
  ```
43
43
  This will place the associated content on the page.
44
44
 
45
+ ## Note About Turbolinks
46
+
47
+ If you're using Turbolinks on your Jekyll site, you should consider adding the following line to your main includes, e.g. `_includes/head.html`:
48
+
49
+ ```html
50
+ <script src='https://unpkg.com/steem-content-renderer'></script>
51
+ ```
52
+
45
53
  ## Jekyll Build
46
54
 
47
55
  When building your site with jekyll, you can continue to use the default command:
@@ -56,6 +64,41 @@ If you would like to provide an alternate node:
56
64
  NODE_URL=https://anyx.io jekyll build
57
65
  ```
58
66
 
67
+ ## Jekyll Clean
68
+
69
+ To completely rebuild your site without cache:
70
+
71
+ ```bash
72
+ rm -rf .jekyll-hive-cache && jekyll clean && jekyll build
73
+ ```
74
+
75
+ ## Troubleshooting
76
+
77
+ #### I saw several messages like:
78
+
79
+ ```
80
+ Retrying: stoodkev/how-to-use-hivejs-or-other-modules-referencing-core-node-js-modules-on-react-native (Failed to open TCP connection to api.hive.blog:443 (getaddrinfo: nodename nor servname provided, or not known))
81
+ Retrying: stoodkev/how-to-use-hivejs-or-other-modules-referencing-core-node-js-modules-on-react-native (Failed to open TCP connection to api.openhive.network:443 (getaddrinfo: nodename nor servname provided, or not known))
82
+ .
83
+ .
84
+ .
85
+ Gave up on: stoodkev/how-to-use-hivejs-or-other-modules-referencing-core-node-js-modules-on-react-native
86
+ ```
87
+
88
+ Check your internet connection or provide an alternate node:
89
+
90
+ ```
91
+ NODE_URL=https://anyx.io jekyll build
92
+ ```
93
+
94
+ #### The post has changed on the blockchain, but `jekyll-hive` won't update to the latest post revision.
95
+
96
+ The cached copy is out of date. Try deleting the related post from the cache or remove the entire cache:
97
+
98
+ ```
99
+ rm -rf .jekyll-hive-cache
100
+ ```
101
+
59
102
  ## Contributing
60
103
 
61
104
  1. Fork it ( https://github.com/inertia186/jekyll-hive/fork )
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cgi'
4
- require 'steem'
4
+ require 'hive'
5
+ require 'open-uri'
6
+ require 'fileutils'
5
7
 
6
8
  Net::OpenTimeout = Class.new(RuntimeError) unless Net.const_defined?(:OpenTimeout)
7
9
  Net::ReadTimeout = Class.new(RuntimeError) unless Net.const_defined?(:ReadTimeout)
@@ -19,8 +21,48 @@ module Jekyll
19
21
 
20
22
  if (tag_contents = determine_arguments(@markup.strip))
21
23
  hive_slug = tag_contents[0]
24
+ attempts = 0
25
+ content = nil
26
+ rebuild = ENV.fetch("JEKYLL_HIVE_REBUILD", 'false') == 'true'
22
27
 
23
- hive_tag(hive_slug)
28
+ loop do
29
+ warn "Attempts for #{hive_slug}: #{attempts}" if attempts > 0
30
+
31
+ if attempts > 4
32
+ warn "Gave up on: #{hive_slug}"
33
+ delete_content_cache(hive_slug)
34
+ break
35
+ end
36
+
37
+ begin
38
+ attempts = attempts + 1
39
+
40
+ if !!rebuild && !!content_cache(hive_slug)
41
+ if content_age(hive_slug) > 9000
42
+ # TODO quickly check if the cache should be cleared
43
+
44
+ warn "Checking for changes: #{hive_slug}"
45
+
46
+ if content_changed?(hive_slug)
47
+ warn "Refreshing: #{hive_slug}"
48
+ delete_content_cache(hive_slug)
49
+ end
50
+ end
51
+
52
+ content_touch(hive_slug)
53
+ end
54
+
55
+ content = content_cache(hive_slug) || hive_tag(hive_slug)
56
+
57
+ break
58
+ rescue => e
59
+ warn "Retrying: #{hive_slug} (#{e})"
60
+ @api = nil
61
+ sleep 3
62
+ end
63
+ end
64
+
65
+ content_cache(hive_slug, content)
24
66
  else
25
67
  raise ArgumentError, <<~ERROR
26
68
  Syntax error in tag 'hive' while parsing the following markup:
@@ -32,20 +74,105 @@ module Jekyll
32
74
  end
33
75
  end
34
76
  private
77
+ def cache_dir_path
78
+ ENV.fetch('JEKYLL_HIVE_CACHE', '.jekyll-hive-cache')
79
+ end
80
+
81
+ def parse_key(hive_slug)
82
+ hive_slug.gsub('/', '-')
83
+ end
84
+
85
+ def cached_file(hive_slug)
86
+ key = parse_key(hive_slug)
87
+
88
+ cache_dir_path + "/#{key}"
89
+ end
90
+
91
+ def content_cache(hive_slug, value = nil)
92
+ key = parse_key(hive_slug)
93
+
94
+ unless !!@content_cache
95
+ @content_cache ||= {}
96
+
97
+ FileUtils.mkdir_p(cache_dir_path)
98
+
99
+ Dir.glob("#{cache_dir_path}/*") do |filename|
100
+ next if File.directory? filename
101
+
102
+ @content_cache[filename.split('/').last] = File.open(filename).read
103
+ end
104
+ end
105
+
106
+ if !!value && value != ''
107
+ @content_cache[key] ||= value
108
+
109
+ File.open(cached_file(hive_slug), 'wb') do |cache_file|
110
+ cache_file.write(value)
111
+ end
112
+ end
113
+
114
+ if @content_cache[key] == ''
115
+ delete_content_cache(hive_slug)
116
+
117
+ nil
118
+ else
119
+ @content_cache[key]
120
+ end
121
+ end
122
+
123
+ def content_age(hive_slug)
124
+ age = Time.now - File.mtime(cached_file(hive_slug)) rescue 0
125
+ warn "Age for #{hive_slug}: #{age}"
126
+
127
+ age
128
+ end
129
+
130
+ def content_touch(hive_slug)
131
+ FileUtils.touch(cached_file(hive_slug))
132
+ end
133
+
134
+ def delete_content_cache(hive_slug)
135
+ File.delete(cached_file(hive_slug)) rescue false
136
+ end
137
+
35
138
  def determine_arguments(input)
36
139
  return unless input =~ /@?[^\/]+\/[^\/]+/i
37
140
 
38
141
  [input]
39
142
  end
40
143
 
41
- def hive_tag(hive_slug)
144
+ def api
145
+ url = ENV.fetch('NODE_URL', 'https://api.hive.blog,https://api.openhive.network').split(',').sample
146
+
147
+ @api ||= ::Hive::CondenserApi.new(url: url)
148
+ end
149
+
150
+ def parse_slug(hive_slug)
42
151
  hive_slug = hive_slug.split('@').last
43
152
  hive_slug = hive_slug.split('/')
44
153
  author = hive_slug[0]
45
154
  permlink = hive_slug[1..-1].join('/')
46
155
  permlink = permlink.split('?').first
47
156
  permlink = permlink.split('#').first
48
- api = ::Steem::CondenserApi.new(url: ENV.fetch('NODE_URL', 'https://api.openhive.network'))
157
+
158
+ [author, permlink]
159
+ end
160
+
161
+ def content_changed?(hive_slug)
162
+ author, permlink = parse_slug(hive_slug)
163
+ cached_created = File.mtime(cached_file(hive_slug)) rescue Time.now
164
+
165
+ # TODO find a better way to get the `created` timestamp, this is really
166
+ # no faster than just parsing the content.
167
+ api.get_content(author, permlink) do |content|
168
+ created = Time.parse(content.created + 'Z')
169
+
170
+ cached_created > created
171
+ end
172
+ end
173
+
174
+ def hive_tag(hive_slug)
175
+ author, permlink = parse_slug(hive_slug)
49
176
 
50
177
  api.get_content(author, permlink) do |content|
51
178
  body = content.body
@@ -57,24 +184,82 @@ module Jekyll
57
184
 
58
185
  body = body.gsub(/https:\/\/steemitimages.com\/[0-9]+x0\/https:\/\//, 'https://')
59
186
  body = body.gsub(/https:\/\/images.hive.blog\/[0-9]+x0\/https:\/\//, 'https://')
187
+ body = body.gsub(/https:\/\/images.esteem.app\/[0-9]+x0\/https:\/\//, 'https://')
60
188
 
61
- # Although it works on hive.blog and many other markdown interpretors,
62
- # kramdown doesn't like this, so we have to fix it:
63
- #
64
- # <div>
65
- # This *won't* work.
66
- # </div>
67
- #
68
- # See: https://stackoverflow.blog/2008/06/25/three-markdown-gotcha/
69
-
70
- body = body.gsub(/<([^\/].+)>(.+)<\/\1>/m) do
71
- match = Regexp.last_match
72
- html = Kramdown::Document.new(match[2]).to_html
73
-
74
- "<#{match[1]}>#{html.gsub("\n", "<br />")}</#{match[1]}>"
189
+ scrape = URI::open(canonical_url).read
190
+
191
+ if scrape.include? 'rel="canonical"'
192
+ canonical_url = scrape.split('rel="canonical"')[1].split('"')[1]
75
193
  end
76
-
77
- body + <<~DONE
194
+
195
+ "<div id=\"content-#{author}-#{permlink}\">" + body + <<~DONE
196
+ </div>
197
+ <script crossorigin='anonymous' integrity='sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=' src='https://code.jquery.com/jquery-3.5.1.slim.min.js'></script>
198
+ <script src='https://unpkg.com/steem-content-renderer'></script>
199
+ <!-- <script src="https://cdn.jsdelivr.net/npm/hive-content-renderer/dist/hive-content-renderer.min.js"></script> -->
200
+ <script>
201
+ $(document).ready(function() {
202
+ try {
203
+ const renderer = new SteemContentRenderer.DefaultRenderer({
204
+ // const renderer = new HiveContentRenderer({
205
+ baseUrl: "https://hive.blog/",
206
+ breaks: true,
207
+ skipSanitization: false,
208
+ allowInsecureScriptTags: false,
209
+ addNofollowToLinks: true,
210
+ doNotShowImages: false,
211
+ ipfsPrefix: "",
212
+ assetsWidth: 640,
213
+ assetsHeight: 480,
214
+ imageProxyFn: (url) => url,
215
+ usertagUrlFn: (account) => "/@#{author}",
216
+ hashtagUrlFn: (hashtag) => "/#{permlink}",
217
+ isLinkSafeFn: (url) => true,
218
+ });
219
+
220
+ const inputElem = $('#content-#{author}-#{permlink}').html();
221
+ const outputElem = $('#content-#{author}-#{permlink}');
222
+ const output = renderer.render(inputElem);
223
+
224
+ outputElem.html(output);
225
+ } catch(e) {
226
+ console.log(e);
227
+ }
228
+ });
229
+ </script>
230
+ <style>
231
+ #content-#{author}-#{permlink} {
232
+ padding: 0 3rem;
233
+ color: #444444;
234
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
235
+ font-size: 16px;
236
+ line-height: 1.8;
237
+ text-shadow: 0 1px 0 #ffffff;
238
+ padding: 0.5rem;
239
+ }
240
+ #content-#{author}-#{permlink} code {
241
+ background: white;
242
+ }
243
+ #content-#{author}-#{permlink} a {
244
+ border-bottom: 1px solid #444444; color: #444444; text-decoration: none;
245
+ }
246
+ #content-#{author}-#{permlink} a:hover {
247
+ border-bottom: 0;
248
+ }
249
+ #content-#{author}-#{permlink} h1 {
250
+ font-size: 2.2em;
251
+ }
252
+ #content-#{author}-#{permlink} h2, h3, h4, h5 {
253
+ margin-bottom: 0;
254
+ }
255
+ #content-#{author}-#{permlink} header small {
256
+ color: #999;
257
+ font-size: 50%;
258
+ }
259
+ #content-#{author}-#{permlink} img {
260
+ max-width: 100%;
261
+ }
262
+ </style>
78
263
  \n<hr />
79
264
  <p>
80
265
  See: <a href="#{canonical_url}">#{content.title}</a>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Hive
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,156 +1,160 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2026-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: steem-ruby
14
+ name: hive-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: '1.0'
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.9'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: jekyll
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '3.5'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
48
37
  type: :development
49
38
  prerelease: false
50
39
  version_requirements: !ruby/object:Gem::Requirement
51
40
  requirements:
52
41
  - - ">="
53
42
  - !ruby/object:Gem::Version
54
- version: '0'
43
+ version: '3.5'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: rake
57
49
  requirement: !ruby/object:Gem::Requirement
58
50
  requirements:
59
- - - ">="
51
+ - - "~>"
60
52
  - !ruby/object:Gem::Version
61
- version: '0'
53
+ version: '13.0'
62
54
  type: :development
63
55
  prerelease: false
64
56
  version_requirements: !ruby/object:Gem::Requirement
65
57
  requirements:
66
- - - ">="
58
+ - - "~>"
67
59
  - !ruby/object:Gem::Version
68
- version: '0'
60
+ version: '13.0'
69
61
  - !ruby/object:Gem::Dependency
70
62
  name: rspec
71
63
  requirement: !ruby/object:Gem::Requirement
72
64
  requirements:
73
65
  - - ">="
74
66
  - !ruby/object:Gem::Version
75
- version: '0'
67
+ version: '3.0'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '4.0'
76
71
  type: :development
77
72
  prerelease: false
78
73
  version_requirements: !ruby/object:Gem::Requirement
79
74
  requirements:
80
75
  - - ">="
81
76
  - !ruby/object:Gem::Version
82
- version: '0'
77
+ version: '3.0'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '4.0'
83
81
  - !ruby/object:Gem::Dependency
84
82
  name: rubocop-jekyll
85
83
  requirement: !ruby/object:Gem::Requirement
86
84
  requirements:
87
- - - "~>"
85
+ - - ">="
88
86
  - !ruby/object:Gem::Version
89
87
  version: '0.4'
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - "~>"
95
+ - - ">="
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0.4'
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.0'
97
101
  - !ruby/object:Gem::Dependency
98
102
  name: webmock
99
103
  requirement: !ruby/object:Gem::Requirement
100
104
  requirements:
101
- - - ">="
105
+ - - "~>"
102
106
  - !ruby/object:Gem::Version
103
- version: '0'
107
+ version: '3.0'
104
108
  type: :development
105
109
  prerelease: false
106
110
  version_requirements: !ruby/object:Gem::Requirement
107
111
  requirements:
108
- - - ">="
112
+ - - "~>"
109
113
  - !ruby/object:Gem::Version
110
- version: '0'
114
+ version: '3.0'
111
115
  - !ruby/object:Gem::Dependency
112
116
  name: vcr
113
117
  requirement: !ruby/object:Gem::Requirement
114
118
  requirements:
115
- - - ">="
119
+ - - "~>"
116
120
  - !ruby/object:Gem::Version
117
- version: '0'
121
+ version: '6.0'
118
122
  type: :development
119
123
  prerelease: false
120
124
  version_requirements: !ruby/object:Gem::Requirement
121
125
  requirements:
122
- - - ">="
126
+ - - "~>"
123
127
  - !ruby/object:Gem::Version
124
- version: '0'
128
+ version: '6.0'
125
129
  - !ruby/object:Gem::Dependency
126
130
  name: simplecov
127
131
  requirement: !ruby/object:Gem::Requirement
128
132
  requirements:
129
- - - ">="
133
+ - - "~>"
130
134
  - !ruby/object:Gem::Version
131
- version: '0'
135
+ version: '0.22'
132
136
  type: :development
133
137
  prerelease: false
134
138
  version_requirements: !ruby/object:Gem::Requirement
135
139
  requirements:
136
- - - ">="
140
+ - - "~>"
137
141
  - !ruby/object:Gem::Version
138
- version: '0'
142
+ version: '0.22'
139
143
  - !ruby/object:Gem::Dependency
140
144
  name: yard
141
145
  requirement: !ruby/object:Gem::Requirement
142
146
  requirements:
143
- - - ">="
147
+ - - "~>"
144
148
  - !ruby/object:Gem::Version
145
- version: '0'
149
+ version: '0.9'
146
150
  type: :development
147
151
  prerelease: false
148
152
  version_requirements: !ruby/object:Gem::Requirement
149
153
  requirements:
150
- - - ">="
154
+ - - "~>"
151
155
  - !ruby/object:Gem::Version
152
- version: '0'
153
- description:
156
+ version: '0.9'
157
+ description:
154
158
  email:
155
159
  - jekyll-hive@martin-studio.com
156
160
  executables: []
@@ -166,7 +170,7 @@ homepage: https://github.com/inertia186/jekyll-hive
166
170
  licenses:
167
171
  - CC0-1.0
168
172
  metadata: {}
169
- post_install_message:
173
+ post_install_message:
170
174
  rdoc_options: []
171
175
  require_paths:
172
176
  - lib
@@ -181,9 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
185
  - !ruby/object:Gem::Version
182
186
  version: '0'
183
187
  requirements: []
184
- rubyforge_project:
185
- rubygems_version: 2.7.10
186
- signing_key:
188
+ rubygems_version: 3.4.19
189
+ signing_key:
187
190
  specification_version: 4
188
191
  summary: Liquid tag for displaying Hive content in Jekyll sites.
189
192
  test_files: []