jekyll-kroki 0.4.0 → 0.5.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: 50b7f01538196d5f83bb7d6a53c39ec6f4ea3e341081805564e1bafe3e3aa380
4
- data.tar.gz: fad323a88f082cc7bfddb35078246569d1b58e9ffa5a391f1344f4b9f55b5304
3
+ metadata.gz: 39c2c3f9463c5788864d00c4ed80e9aa826a1aa1d1380dbff2be92407958f0e5
4
+ data.tar.gz: 38340a5a1deaa705a0b7cde596e5eb007da3d84526b2641e9cad6e9f38e86809
5
5
  SHA512:
6
- metadata.gz: fcba83e90f609bddd69e368f1089a0a0fc399647cc8801eee6a021e2c2fd9eb80abdc66805e811d41b26fd3738d595b561a1ae883d0037d6d8ea5e1e5aba383e
7
- data.tar.gz: 1a425cdfcfc65488e0f8014a3dcefd7486943ad4d91a71d9e28915b4fe84fef357826614a642acb93d91401b8822d270c2dea20547c14a11c9fb81a648943f5b
6
+ metadata.gz: dbedea8bbf380c047c91cee38bc7fade0c9a6a0e3aa8735b7a18e3361219cb796fb3b89b17583db402f0b03bf083f13892d53a7677cc904d12f6be6990bfee98
7
+ data.tar.gz: 6c3cf11ca513c6b16331547bcd69003b77dd62c3a09b46c52e440684a5001f8c47318962037faa3a0bce5cf1e99c2dfe4a2f5f4e00f4bc0eb893ef0fb174efa6
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ plugins:
5
5
 
6
6
  AllCops:
7
7
  NewCops: enable
8
- TargetRubyVersion: 2.6
8
+ TargetRubyVersion: 2.7
9
9
 
10
10
  Gemspec/DevelopmentDependencies:
11
11
  EnforcedStyle: gemspec
@@ -23,4 +23,4 @@ Layout/LineLength:
23
23
  Metrics/ClassLength:
24
24
  Max: 120
25
25
  Metrics/MethodLength:
26
- Max: 14
26
+ Max: 16
data/README.md CHANGED
@@ -49,15 +49,25 @@ The server-side nature of Kroki means that you don't have to deal with installin
49
49
  Kroki is available either as a free service or self-hosted using Docker. Organisations that frequently build large Jekyll sites with many diagrams or want maximum control over their data have the option of running their own Kroki instance to provide consistency and use compute resources efficiently.
50
50
 
51
51
  ### Configuration
52
- You can specify the URL of the Kroki instance to use in the Jekyll `_config.yml` file:
52
+ You can specify the following parameters in the Jekyll `_config.yml` file:
53
+
54
+ | Parameter | Default value | Description |
55
+ | --------- | ------------- | ----------- |
56
+ | `url` | `https://kroki.io` | The URL of the Kroki instance to use |
57
+ | `http_retries` | `3` | The number of HTTP retries |
58
+ | `http_timeout` | `15` | The HTTP timeout value in seconds |
59
+ | `max_concurrent_docs` | `8` | The maximum number of Jekyll documents to render concurrently |
60
+
61
+ For example:
53
62
 
54
63
  ```yaml
55
64
  kroki:
56
65
  url: "https://my-kroki.server"
66
+ http_retries: 3
67
+ http_timeout: 15
68
+ max_concurrent_docs: 8
57
69
  ```
58
70
 
59
- This is useful if you want to run a Kroki instance locally or your organisation maintains its own private Kroki server. The public Kroki instance https://kroki.io is used by default.
60
-
61
71
  ### Security
62
72
  Embedding diagrams as SVGs directly within HTML files can be dangerous. You should only use a Kroki instance that you trust (or run your own!). For additional security, you can configure a [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) using custom Webrick headers in the Jekyll `_config.yml` file:
63
73
 
data/jekyll-kroki.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  languages into images using Kroki"
13
13
  spec.homepage = "https://github.com/felixvanoost/jekyll-kroki"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class Kroki
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
data/lib/jekyll/kroki.rb CHANGED
@@ -15,27 +15,30 @@ require "zlib"
15
15
  module Jekyll
16
16
  # Converts diagram descriptions into images using Kroki.
17
17
  class Kroki
18
- KROKI_DEFAULT_URL = "https://kroki.io"
19
- SUPPORTED_LANGUAGES = %w[actdiag blockdiag bpmn bytefield c4plantuml d2 dbml diagramsnet ditaa erd excalidraw
20
- graphviz mermaid nomnoml nwdiag packetdiag pikchr plantuml rackdiag seqdiag structurizr
21
- svgbob symbolator tikz umlet vega vegalite wavedrom wireviz].freeze
18
+ DEFAULT_KROKI_URL = "https://kroki.io"
19
+ DEFAULT_HTTP_RETRIES = 3
20
+ DEFAULT_HTTP_TIMEOUT = 15
21
+ DEFAULT_MAX_CONCURRENT_DOCS = 8
22
22
  EXPECTED_HTML_TAGS = %w[code div].freeze
23
- HTTP_MAX_RETRIES = 3
24
23
  HTTP_RETRY_INTERVAL_BACKOFF_FACTOR = 2
25
24
  HTTP_RETRY_INTERVAL_RANDOMNESS = 0.5
26
- HTTP_RETRY_INTERVAL_SECONDS = 0.1
27
- HTTP_TIMEOUT_SECONDS = 15
28
- MAX_CONCURRENT_DOCS = 8
25
+ HTTP_RETRY_INTERVAL = 0.1
26
+ SUPPORTED_LANGUAGES = %w[actdiag blockdiag bpmn bytefield c4plantuml d2 dbml diagramsnet ditaa erd excalidraw
27
+ graphviz mermaid nomnoml nwdiag packetdiag pikchr plantuml rackdiag seqdiag structurizr
28
+ svgbob symbolator tikz umlet vega vegalite wavedrom wireviz].freeze
29
29
 
30
30
  class << self
31
31
  # Renders and embeds all diagram descriptions in the given Jekyll site using Kroki.
32
32
  #
33
33
  # @param [Jekyll::Site] The Jekyll site to embed diagrams in.
34
34
  def embed_site(site)
35
- kroki_url = kroki_url(site.config)
36
- connection = setup_connection(kroki_url)
35
+ kroki_url = get_kroki_url(site.config)
36
+ http_retries = get_http_retries(site.config)
37
+ http_timeout = get_http_timeout(site.config)
38
+ connection = setup_connection(kroki_url, http_retries, http_timeout)
37
39
 
38
- rendered_diag = embed_docs_in_site(site, connection)
40
+ max_concurrent_docs = get_max_concurrent_docs(site.config)
41
+ rendered_diag = embed_docs_in_site(site, connection, max_concurrent_docs)
39
42
  unless rendered_diag.zero?
40
43
  puts "[jekyll-kroki] Rendered #{rendered_diag} diagrams using Kroki instance at '#{kroki_url}'"
41
44
  end
@@ -44,21 +47,22 @@ module Jekyll
44
47
  end
45
48
 
46
49
  # Renders the diagram descriptions in all Jekyll pages and documents in the given Jekyll site. Pages / documents
47
- # are rendered concurrently up to the limit defined by MAX_CONCURRENT_DOCS.
50
+ # are rendered concurrently up to the limit defined by DEFAULT_MAX_CONCURRENT_DOCS.
48
51
  #
49
52
  # @param [Jekyll::Site] The Jekyll site to embed diagrams in.
50
53
  # @param [Faraday::Connection] The Faraday connection to use.
54
+ # @param [Integer] The maximum number of documents to render concurrently.
51
55
  # @return [Integer] The number of successfully rendered diagrams.
52
- def embed_docs_in_site(site, connection)
56
+ def embed_docs_in_site(site, connection, max_concurrent_docs)
53
57
  rendered_diag = 0
54
- semaphore = Async::Semaphore.new(MAX_CONCURRENT_DOCS)
58
+ semaphore = Async::Semaphore.new(max_concurrent_docs)
55
59
 
56
60
  Async do |task|
57
- tasks = (site.pages + site.documents).map do |doc|
61
+ tasks = (site.pages + site.documents).filter_map do |doc|
58
62
  next unless embeddable?(doc)
59
63
 
60
64
  async_embed_single_doc(task, semaphore, connection, doc)
61
- end.compact
65
+ end
62
66
 
63
67
  rendered_diag = tasks.sum(&:wait)
64
68
  end
@@ -154,14 +158,16 @@ module Jekyll
154
158
  # Sets up a new Faraday connection.
155
159
  #
156
160
  # @param [URI::HTTP] The URL of the Kroki instance.
161
+ # @param [Integer] The number of retries.
162
+ # @param [Integer] The timeout value in seconds.
157
163
  # @return [Faraday::Connection] The Faraday connection.
158
- def setup_connection(kroki_url)
159
- retry_options = { max: HTTP_MAX_RETRIES, interval: HTTP_RETRY_INTERVAL_SECONDS,
164
+ def setup_connection(kroki_url, retries, timeout)
165
+ retry_options = { max: retries, interval: HTTP_RETRY_INTERVAL,
160
166
  interval_randomness: HTTP_RETRY_INTERVAL_RANDOMNESS,
161
167
  backoff_factor: HTTP_RETRY_INTERVAL_BACKOFF_FACTOR,
162
168
  exceptions: [Faraday::RequestTimeoutError, Faraday::ServerError] }
163
169
 
164
- Faraday.new(url: kroki_url, request: { timeout: HTTP_TIMEOUT_SECONDS }) do |builder|
170
+ Faraday.new(url: kroki_url, request: { timeout: timeout }) do |builder|
165
171
  builder.adapter :httpx, persistent: true
166
172
  builder.request :retry, retry_options
167
173
  builder.response :json, content_type: /\bjson$/
@@ -173,17 +179,38 @@ module Jekyll
173
179
  #
174
180
  # @param The Jekyll site configuration.
175
181
  # @return [URI::HTTP] The URL of the Kroki instance.
176
- def kroki_url(config)
177
- if config.key?("kroki") && config["kroki"].key?("url")
178
- url = config["kroki"]["url"]
179
- raise TypeError, "'url' is not a valid HTTP URL" unless URI.parse(url).is_a?(URI::HTTP)
180
- else
181
- url = KROKI_DEFAULT_URL
182
- end
182
+ def get_kroki_url(config)
183
+ url = config.fetch("kroki", {}).fetch("url", DEFAULT_KROKI_URL)
184
+ raise TypeError, "'url' is not a valid HTTP URL" unless URI.parse(url).is_a?(URI::HTTP)
185
+
183
186
  URI(url)
184
187
  end
185
188
 
186
- # Determines whether a document may contain embeddable diagram descriptions - it is in HTML format and is either
189
+ # Gets the number of HTTP retries.
190
+ #
191
+ # @param The Jekyll site configuration.
192
+ # @return [Integer] The number of HTTP retries.
193
+ def get_http_retries(config)
194
+ config.fetch("kroki", {}).fetch("http_retries", DEFAULT_HTTP_RETRIES)
195
+ end
196
+
197
+ # Gets the HTTP timeout value.
198
+ #
199
+ # @param The Jekyll site configuration.
200
+ # @return [Integer] The HTTP timeout value in seconds.
201
+ def get_http_timeout(config)
202
+ config.fetch("kroki", {}).fetch("http_timeout", DEFAULT_HTTP_TIMEOUT)
203
+ end
204
+
205
+ # Gets the maximum number of documents to render concurrently.
206
+ #
207
+ # @param The Jekyll site configuration.
208
+ # @return [Integer] The maximum number of documents to render concurrently.
209
+ def get_max_concurrent_docs(config)
210
+ config.fetch("kroki", {}).fetch("max_concurrent_docs", DEFAULT_MAX_CONCURRENT_DOCS)
211
+ end
212
+
213
+ # Determines whether a document may contain embeddable diagram descriptions; it is in HTML format and is either
187
214
  # a Jekyll::Page or writeable Jekyll::Document.
188
215
  #
189
216
  # @param [Jekyll::Page or Jekyll::Document] The document to check for embeddability.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kroki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix van Oost
@@ -207,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="
209
209
  - !ruby/object:Gem::Version
210
- version: 2.6.0
210
+ version: 2.7.0
211
211
  required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - ">="