bridgetown-core 0.11.0 → 0.11.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: 86af5c191c5ec6097a971ccbb66489d6d71effb8a48ffe19736a7ee8319fa672
4
- data.tar.gz: 2d68656ef593e5d2ed3aa1e2a3b0f3de7e1e45e1ac29b439089e0d4419c61657
3
+ metadata.gz: a37c6106883a48eeb4acea0c1f06d96d55743b9a0c96da58a8ce1e8d11872f6e
4
+ data.tar.gz: 8b6b0fbf59db76bf0f650569fe7203548639cfb4b01d1a5dfcc60ab6d6e5f47b
5
5
  SHA512:
6
- metadata.gz: caf6380687cbab8f43986faf41b3c2ca42013e4d4157ffe714b6d89f4e81f8f1b51089636c6b6360b5033699a1f9f2cda5a46650f5686058d6c92efba81fff23
7
- data.tar.gz: a8d429d08d30a12efe6138e8444954a7243606c1b29fe39c44d5c3882c7fe3fddac29711b1e39b7ecededd30880ecff31b2f3d1d636d5c9ead3f4b41d3999229
6
+ metadata.gz: d062100e89863161cae248782db05f9b0519f56bb5965f117cf0bb5734653bd4de27bdb08a063ed996af798f3f34a5e035e59b08f39084351fce33ec80074865
7
+ data.tar.gz: 675f41b860201cb0d80f2598761d7f187f0d59271eaebeb99fc8cb7b25931d85947047122017037eb06c8b8e048e79c17ddddabe56c658a22fa7d805e6121a45
@@ -33,6 +33,8 @@ module Bridgetown
33
33
  "try again with `--force` to proceed and overwrite any files."
34
34
  end
35
35
 
36
+ Bridgetown.logger.info("Creating:".green, new_site_path)
37
+
36
38
  create_site new_site_path
37
39
 
38
40
  after_install(new_site_path, args.join(" "), options)
@@ -121,7 +123,9 @@ module Bridgetown
121
123
  end
122
124
  end
123
125
 
124
- Bridgetown.logger.info "Success! 🎉 Your new Bridgetown site was" \
126
+ git_init path
127
+
128
+ Bridgetown.logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
125
129
  " generated in #{cli_path.cyan}."
126
130
  Bridgetown.logger.info "Execute cd #{cli_path.cyan} to get started."
127
131
  Bridgetown.logger.info "You'll probably also want to #{"yarn install".cyan}" \
@@ -145,6 +149,16 @@ module Bridgetown
145
149
  raise SystemExit unless process.success?
146
150
  end
147
151
  end
152
+
153
+ def git_init(path)
154
+ Dir.chdir(path) do
155
+ _process, output = Bridgetown::Utils::Exec.run("git", "init")
156
+ output.to_s.each_line do |line|
157
+ Bridgetown.logger.info("Git:".green, line.strip) unless line.to_s.empty?
158
+ end
159
+ end
160
+ rescue SystemCallError
161
+ end
148
162
  end
149
163
  end
150
164
  end
@@ -1,15 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ Bridgetown::Hooks.register :pages, :post_init do |page|
4
+ if page.class != Bridgetown::PrototypePage && page.data["prototype"].is_a?(Hash)
5
+ Bridgetown::PrototypeGenerator.add_matching_template(page)
6
+ end
7
+ end
8
+
3
9
  module Bridgetown
4
10
  class PrototypeGenerator < Generator
5
11
  priority :low
6
12
 
13
+ @matching_templates = []
14
+
15
+ def self.add_matching_template(template)
16
+ @matching_templates << template
17
+ end
18
+
19
+ class << self
20
+ attr_reader :matching_templates
21
+ end
22
+
7
23
  def generate(site)
8
24
  @site = site
9
25
  @configured_collection = "posts"
10
26
 
11
- prototype_pages = site.pages.select do |page|
12
- page.data["prototype"].is_a?(Hash)
27
+ prototype_pages = self.class.matching_templates.select do |page|
28
+ site.pages.include? page
13
29
  end
14
30
 
15
31
  if prototype_pages.length.positive?
@@ -42,18 +58,7 @@ module Bridgetown
42
58
  end
43
59
 
44
60
  def generate_new_page_from_prototype(prototype_page, search_term, term)
45
- new_page = PrototypePage.new(prototype_page)
46
- # Use the original specified term so we get "tag" back, not "tags":
47
- new_page.data[prototype_page.data["prototype"]["term"]] = term
48
-
49
- process_title_data_placeholder(new_page, prototype_page, search_term, term)
50
- process_title_simple_placeholders(new_page, prototype_page, term)
51
-
52
- new_page.data["pagination"] = {} unless new_page.data["pagination"].is_a?(Hash)
53
- new_page.data["pagination"]["enabled"] = true
54
- new_page.data["pagination"]["collection"] = @configured_collection
55
- new_page.data["pagination"]["where_query"] = [search_term, term]
56
- new_page.slugify_term(term)
61
+ new_page = PrototypePage.new(prototype_page, @configured_collection, search_term, term)
57
62
  @site.pages << new_page
58
63
  new_page
59
64
  end
@@ -63,43 +68,14 @@ module Bridgetown
63
68
  document.respond_to?(:collection) && document.collection.label == @configured_collection
64
69
  end
65
70
 
66
- Bridgetown::Paginate::Generator::PaginationIndexer.index_documents_by(
71
+ Bridgetown::Paginate::PaginationIndexer.index_documents_by(
67
72
  selected_docs, search_term
68
73
  ).keys
69
74
  end
70
-
71
- def process_title_data_placeholder(new_page, prototype_page, search_term, term)
72
- if prototype_page["prototype"]["data"]
73
- if new_page.data["title"]&.include?(":prototype-data-label")
74
- related_data = @site.data[prototype_page["prototype"]["data"]].dig(term)
75
- if related_data
76
- new_page.data["#{search_term}_data"] = related_data
77
- data_label = related_data[prototype_page["prototype"]["data_label"]]
78
- new_page.data["title"] = new_page.data["title"].gsub(
79
- ":prototype-data-label", data_label
80
- )
81
- end
82
- end
83
- end
84
- end
85
-
86
- def process_title_simple_placeholders(new_page, _prototype_page, term)
87
- if new_page.data["title"]&.include?(":prototype-term-titleize")
88
- new_page.data["title"] = new_page.data["title"].gsub(
89
- ":prototype-term-titleize", Bridgetown::Utils.titleize_slug(term)
90
- )
91
- end
92
-
93
- if new_page.data["title"]&.include?(":prototype-term")
94
- new_page.data["title"] = new_page.data["title"].gsub(
95
- ":prototype-term", term
96
- )
97
- end
98
- end
99
75
  end
100
76
 
101
77
  class PrototypePage < Page
102
- def initialize(prototype_page)
78
+ def initialize(prototype_page, collection, search_term, term)
103
79
  @site = prototype_page.site
104
80
  @url = ""
105
81
  @name = "index.html"
@@ -116,11 +92,65 @@ module Bridgetown
116
92
 
117
93
  @dir = Pathname.new(prototype_page.relative_path).dirname.to_s
118
94
  @path = site.in_source_dir(@dir, @name)
95
+
96
+ process_prototype_page_data(prototype_page, collection, search_term, term)
97
+
98
+ Bridgetown::Hooks.trigger :pages, :post_init, self
99
+ end
100
+
101
+ def process_prototype_page_data(prototype_page, collection, search_term, term)
102
+ # Fill in pagination details to be handled later by Bridgetown::Paginate
103
+ data["pagination"] = Bridgetown::Utils.deep_merge_hashes(
104
+ prototype_page.data["pagination"].to_h, {
105
+ "enabled" => true,
106
+ "collection" => collection,
107
+ "where_query" => [search_term, term],
108
+ }
109
+ )
110
+ # Use the original prototype page term so we get "tag" back, not "tags":
111
+ data[prototype_page.data["prototype"]["term"]] = term
112
+ # Process title and slugs/URLs:
113
+ process_title_data_placeholder(prototype_page, search_term, term)
114
+ process_title_simple_placeholders(term)
115
+ slugify_term(term)
116
+ end
117
+
118
+ def process_title_data_placeholder(prototype_page, search_term, term)
119
+ if prototype_page["prototype"]["data"]
120
+ if data["title"]&.include?(":prototype-data-label")
121
+ related_data = @site.data[prototype_page["prototype"]["data"]].dig(term)
122
+ if related_data
123
+ data["#{search_term}_data"] = related_data
124
+ data_label = related_data[prototype_page["prototype"]["data_label"]]
125
+ data["title"] = data["title"].gsub(
126
+ ":prototype-data-label", data_label
127
+ )
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ def process_title_simple_placeholders(term)
134
+ if data["title"]&.include?(":prototype-term-titleize")
135
+ data["title"] = data["title"].gsub(
136
+ ":prototype-term-titleize", Bridgetown::Utils.titleize_slug(term)
137
+ )
138
+ end
139
+
140
+ if data["title"]&.include?(":prototype-term")
141
+ data["title"] = data["title"].gsub(
142
+ ":prototype-term", term
143
+ )
144
+ end
119
145
  end
120
146
 
121
147
  def slugify_term(term)
122
148
  term_slug = Bridgetown::Utils.slugify(term)
123
- @url = "/#{@dir}/#{term_slug}/"
149
+ @url = if permalink.is_a?(String)
150
+ data["permalink"] = data["permalink"].sub(":term", term_slug)
151
+ else
152
+ "/#{@dir}/#{term_slug}/"
153
+ end
124
154
  end
125
155
  end
126
156
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.11.0"
4
+ VERSION = "0.11.1"
5
5
  end
@@ -1,7 +1,35 @@
1
+ # Bridgetown
1
2
  output
2
- node_modules
3
- .sass-cache
4
3
  .bridgetown-cache
5
4
  .bridgetown-metadata
6
5
  .bridgetown-webpack
6
+
7
+ # Dependency folders
8
+ node_modules
9
+ bower_components
7
10
  vendor
11
+
12
+ # Caches
13
+ .sass-cache
14
+ .npm
15
+ .node_repl_history
16
+
17
+ # Ignore bundler config.
18
+ /.bundle
19
+
20
+ # Ignore Byebug command history file.
21
+ .byebug_history
22
+
23
+ # dotenv environment variables file
24
+ .env
25
+
26
+ # Mac files
27
+ .DS_Store
28
+
29
+ # Yarn
30
+ yarn-error.log
31
+ yarn-debug.log*
32
+ .pnp/
33
+ .pnp.js
34
+ # Yarn Integrity file
35
+ .yarn-integrity
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-21 00:00:00.000000000 Z
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable