jekyll-bookshop 2.0.0.pre.alpha.52 → 2.0.0.pre.alpha.53

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb67ec52b3dd76507610c427c5298cd1092e22b1e7a6c50b617a83615d8b29ad
4
- data.tar.gz: de4a0a29b607a7519669dda12142af9aaa5ecbf465ebce4b528b2f14318be288
3
+ metadata.gz: 5c587c6738b573c80e77d0176139bc538b05c6270bbdab066b71cfe01638959a
4
+ data.tar.gz: c74eeb46a2ee282246fb68ca732438b07c61b1b6a48d4f072cf865076afaec70
5
5
  SHA512:
6
- metadata.gz: 3d1a78126daf3f5c32ae7a2bccc9da5c1b8836e82a3f8ef1f242e93046a74a524b0988d3c333129153dec10fc515908a0b025fba09bb30afcde9525089e67c90
7
- data.tar.gz: 701d79a3ae271d7e76d7ff365d3d92a92002b8643f89ead2949ddf6ba0ff94e38ad0c9d2bd27130610e685553371604683147d898c083de7da3b29e1f38e9ca9
6
+ metadata.gz: ac0c4448f861a8bb26f98255b56563f6dc424da1f9e0e2e4ae474f2a2c8e97ac5a553e5a86bfce85899261e39a628394e490bb5b4da96e2de5bce8f5a9ea1577
7
+ data.tar.gz: cb144ced61fc5c3ff13a45497d6124d4ea4761a6228b14859852971d4f65ab6e0d35fbb7b98cd7f55e9f8a35ab669fc0d36028ea819315b7b08b5cf836d124f6
@@ -5,12 +5,14 @@ require "pathname"
5
5
  require "dry/inflector"
6
6
 
7
7
  require_relative "jekyll-bookshop/tags/bookshop-tag"
8
+ require_relative "jekyll-bookshop/tags/renderer-tag"
8
9
  require_relative "jekyll-bookshop/tags/style-tag"
9
10
  require_relative "jekyll-bookshop/init-styles"
10
11
  require_relative "jekyll-bookshop/site-data"
11
12
 
12
13
  Liquid::Template.register_tag("bookshop", JekyllBookshop::Tag)
13
14
  Liquid::Template.register_tag("bookshop_scss", JekyllBookshop::StyleTag)
15
+ Liquid::Template.register_tag("bookshop_renderer", JekyllBookshop::RendererTag)
14
16
 
15
17
  Jekyll::Hooks.register :site, :after_init do |site|
16
18
  JekyllBookshop::Styles.open_bookshop(site)
@@ -20,6 +20,9 @@ module JekyllBookshop
20
20
  end
21
21
 
22
22
  @site.data["_bookshop_site_data"] = { "site" => payload_collections }
23
+
24
+ update_renderer_pages
25
+
23
26
  Jekyll.logger.info "Bookshop:",
24
27
  "Bookshop site data generated"
25
28
  end
@@ -36,5 +39,17 @@ module JekyllBookshop
36
39
  "excerpt" => document.data["excerpt"].output,
37
40
  })
38
41
  end
42
+
43
+ def self.update_renderer_pages
44
+ @site.pages.each do |page|
45
+ next unless @site.data["_bookshop_data_pages"]&.include?(page.url)
46
+
47
+ page.output = page.output.gsub(
48
+ %r!bookshop_renderer_site_data = null!,
49
+ "bookshop_renderer_site_data = #{@site.data["_bookshop_site_data"].to_json}"
50
+ )
51
+ end
52
+ @site.data["_bookshop_data_pages"] = nil
53
+ end
39
54
  end
40
55
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class RendererTag < Liquid::Tag
5
+ def initialize(tag_name, markup, tokens)
6
+ super
7
+ # check if markup contains a number
8
+ if %r!\d+!.match?(markup)
9
+ @port = markup.gsub(%r![^\d]!, "").to_i
10
+ else
11
+ Jekyll.logger.warning "Bookshop:",
12
+ "bookshop_renderer tag malformed.
13
+ Use {% bookshop_renderer :6061 %}
14
+ with the port @bookshop/renderer is running on."
15
+ end
16
+ end
17
+
18
+ def render(context)
19
+ return unless @port
20
+ return if Jekyll.env == "production"
21
+
22
+ site = context.registers[:site]
23
+ page = context.registers[:page]
24
+
25
+ site.data["_bookshop_data_pages"] ||= []
26
+ unless site.data["_bookshop_data_pages"].include?(page["url"])
27
+ site.data["_bookshop_data_pages"].push(page["url"])
28
+ end
29
+
30
+ "<div data-bookshop-renderer></div>
31
+ <script>window.bookshop_renderer_site_data = null;</script>
32
+ <script src=\"http://localhost:#{@port}/bookshop.js\"></script>
33
+ <link href=\"http://localhost:#{@port}/renderer.css\" rel=\"stylesheet\">"
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllBookshop
4
- VERSION = "2.0.0.pre.alpha.52"
4
+ VERSION = "2.0.0.pre.alpha.53"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-bookshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.52
4
+ version: 2.0.0.pre.alpha.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-26 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -89,6 +89,7 @@ files:
89
89
  - lib/jekyll-bookshop/init-styles.rb
90
90
  - lib/jekyll-bookshop/site-data.rb
91
91
  - lib/jekyll-bookshop/tags/bookshop-tag.rb
92
+ - lib/jekyll-bookshop/tags/renderer-tag.rb
92
93
  - lib/jekyll-bookshop/tags/style-tag.rb
93
94
  - lib/jekyll-bookshop/version.rb
94
95
  homepage: https://github.com/cloudcannon/bookshop