jekyll-bookshop 2.0.0.pre.alpha.50 → 2.0.0.pre.beta.1

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: 986c96d3e958c3967551379041a88a4e8934dbc0ad6025900436e042094ea602
4
- data.tar.gz: c9393a58731595e9cac2dbf86ec85c805347a320faf25d24a909059546a92b73
3
+ metadata.gz: 96067db3f835d4cd743b8b0df5a2c648f5446a77a4dcb2c5bb4a1ccf66fa6d23
4
+ data.tar.gz: 437806dbe7a8783efad931c47feca9b12768c1bc2d6674f8458325f76a584b85
5
5
  SHA512:
6
- metadata.gz: ce11ff41268cde9ac8e726770d6d6fa187d1333f0f71296cdf1a4bc44a42f7fb32147d3a60a93e46d0dbe6117b13e30f8887b04d7c9c96fed77675917b7840e9
7
- data.tar.gz: 5b5e99a60c73885749a90a108edb81eb6ca52b237cd67e6ab8cb3c1ce902db2b7db8213ba2daeff2751b66202f3b3d1ac38839f1125f465376c3e8f46c79f350
6
+ metadata.gz: 9e71ae55211c5db955b66f60cab1a25038b795189f6d6ca03db55c7bb6e806ddd0065f5336149fb93c88f09bd31eb260cabd2835ececdd19949120a8c0a6d56c
7
+ data.tar.gz: 93adca96a9fdad0cfcd67b4a0c14aabbb584c8eb0319378fede68af5636561ab82902b0a84d0e815c6e4af61b44c166e83c5f14900ad3d66ec9c9126f786324a
@@ -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/browser-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_browser", JekyllBookshop::BrowserTag)
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_browser_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_browser_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_browser_site_data = null!,
49
+ "bookshop_browser_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,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class BrowserTag < Liquid::Tag
5
+ def initialize(tag_name, markup, tokens)
6
+ super
7
+ @host = markup.strip
8
+ end
9
+
10
+ def render(context)
11
+ return unless @host
12
+ return if Jekyll.env == "production"
13
+
14
+ site = context.registers[:site]
15
+ page = context.registers[:page]
16
+
17
+ site.data["_bookshop_data_pages"] ||= []
18
+ unless site.data["_bookshop_data_pages"].include?(page["url"])
19
+ site.data["_bookshop_data_pages"].push(page["url"])
20
+ end
21
+
22
+ "<div data-bookshop-browser></div>
23
+ <script>window.bookshop_browser_site_data = null;</script>
24
+ <script src=\"//#{@host}\"></script>
25
+ <script>window.BookshopBrowser = new window.BookshopBrowserClass(); window.BookshopBrowser.render();</script>"
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllBookshop
4
- VERSION = "2.0.0.pre.alpha.50"
4
+ VERSION = "2.0.0.pre.beta.1"
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.50
4
+ version: 2.0.0.pre.beta.1
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-08-02 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/browser-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