jekyll-dice-tray 0.3.0 → 0.3.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: d3d407c51d39049511c08f665a5b70a71d0eff1a0ec1522472948ce6350fd670
4
- data.tar.gz: d2ae3f53ca8018c55bfff796cba3781684076bdeb8ba5bfdc9307c5f3e30c127
3
+ metadata.gz: 3f1058c6701f813bd5bef233707af9e65bc2b1876de92db04675158a71a0adab
4
+ data.tar.gz: 6550e68c8ef38aaefebffb822c85c4090402fbfda41585f3ece54f36a1bddf7b
5
5
  SHA512:
6
- metadata.gz: e30263b41fc804cb82a2f6ba76a0697bd31e0e6d5ace3550a94fb6d41d20a25eec1c2db6e65048ea94b549b3137de4a079dc57c7c9f6209b6b841d5b20723ac4
7
- data.tar.gz: 843991fe95b1a12b60550fc6bc462ea547b46e23b740eda47fe3a454dda4d0e34c4757d7ba8f2f3ae68989814c551b3011fbb571b7f022ab1dd404a4f28942fe
6
+ metadata.gz: 9b5f1d58cfcced42951de3dc03660c4c1d683a7a8523af220d1817c0cf610935383a48f4e20b58409920cce03b2654040ce8a6e7ae753eb2971f5972576ad2fe
7
+ data.tar.gz: ecf24959ae7c875c23923be6b231ea494fc4d7fa9d0837f8567a1b161e9120f9a48de4fb76e58522a3751697213469a6bf92f6abdaf25491792ebdd99a7b4627
data/README.md CHANGED
@@ -31,7 +31,7 @@ Optional `_config.yml` settings:
31
31
  ```yml
32
32
  dice_tray:
33
33
  enabled: true
34
- assets_path: /assets/jekyll-dice-tray
34
+ assets_path: /assets/jekyll-dice-tray # prefixed with site baseurl automatically
35
35
  inject_tray: true
36
36
  link_dice_in_markdown: true
37
37
  ```
@@ -0,0 +1,26 @@
1
+ module Jekyll
2
+ module DiceTray
3
+ module Config
4
+ DEFAULT_ASSETS_PATH = "/assets/jekyll-dice-tray"
5
+
6
+ # Site-relative directory for writing static assets (no baseurl).
7
+ def self.assets_dir(site)
8
+ path = configured_path(site)
9
+ path.sub(%r{\A/}, "")
10
+ end
11
+
12
+ # URL path for linking assets in HTML (includes baseurl).
13
+ def self.assets_url(site)
14
+ baseurl = site.config["baseurl"].to_s.chomp("/")
15
+ "#{baseurl}#{configured_path(site)}"
16
+ end
17
+
18
+ def self.configured_path(site)
19
+ cfg = site.config["dice_tray"] || {}
20
+ path = (cfg["assets_path"] || DEFAULT_ASSETS_PATH).to_s
21
+ path.start_with?("/") ? path : "/#{path}"
22
+ end
23
+ private_class_method :configured_path
24
+ end
25
+ end
26
+ end
@@ -8,10 +8,8 @@ module Jekyll
8
8
  cfg = (site.config["dice_tray"] || {})
9
9
  return if cfg["enabled"] == false
10
10
 
11
- assets_path = cfg["assets_path"] || "/assets/jekyll-dice-tray"
12
- assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
13
-
14
11
  asset_dir = File.expand_path("../../../assets/jekyll-dice-tray", __dir__)
12
+ dest_dir = Config.assets_dir(site)
15
13
 
16
14
  files = {
17
15
  "dice_tray.js" => File.join(asset_dir, "dice_tray.js"),
@@ -23,7 +21,7 @@ module Jekyll
23
21
  site.static_files << AssetFile.new(
24
22
  site,
25
23
  site.source,
26
- assets_path.sub(%r{\A/}, ""),
24
+ dest_dir,
27
25
  name,
28
26
  source_path: source_path
29
27
  )
@@ -8,13 +8,10 @@ module Jekyll
8
8
  next if cfg["enabled"] == false
9
9
  next unless doc.respond_to?(:output_ext) && doc.output_ext == ".html"
10
10
 
11
- assets_path = cfg["assets_path"] || "/assets/jekyll-dice-tray"
12
- assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
13
-
14
11
  begin
15
12
  out = doc.output.to_s
16
13
  out = HtmlRewriter.rewrite(out) if cfg.fetch("link_dice_in_markdown", true)
17
- out = HtmlRewriter.inject_tray(out, assets_path: assets_path) if cfg.fetch("inject_tray", true)
14
+ out = HtmlRewriter.inject_tray(out, assets_path: Config.assets_url(site)) if cfg.fetch("inject_tray", true)
18
15
  doc.output = out
19
16
  rescue StandardError => e
20
17
  Jekyll.logger.warn("jekyll-dice-tray:", "Failed to process #{doc.relative_path}: #{e.class}: #{e.message}")
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module DiceTray
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
6
6
 
@@ -2,6 +2,7 @@ require "jekyll"
2
2
  require "nokogiri"
3
3
 
4
4
  require_relative "jekyll/dice_tray/version"
5
+ require_relative "jekyll/dice_tray/config"
5
6
  require_relative "jekyll/dice_tray/asset_file"
6
7
  require_relative "jekyll/dice_tray/generator"
7
8
  require_relative "jekyll/dice_tray/html_rewriter"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-dice-tray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun
@@ -54,6 +54,7 @@ files:
54
54
  - assets/jekyll-dice-tray/dice_tray.js
55
55
  - lib/jekyll-dice-tray.rb
56
56
  - lib/jekyll/dice_tray/asset_file.rb
57
+ - lib/jekyll/dice_tray/config.rb
57
58
  - lib/jekyll/dice_tray/generator.rb
58
59
  - lib/jekyll/dice_tray/hooks.rb
59
60
  - lib/jekyll/dice_tray/html_rewriter.rb