bridgetown-core 0.21.3 → 1.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/Rakefile +5 -5
  4. data/bin/bridgetown +2 -0
  5. data/bridgetown-core.gemspec +3 -0
  6. data/lib/bridgetown-core/cache.rb +3 -5
  7. data/lib/bridgetown-core/cleaner.rb +2 -10
  8. data/lib/bridgetown-core/collection.rb +62 -86
  9. data/lib/bridgetown-core/commands/base.rb +62 -2
  10. data/lib/bridgetown-core/commands/build.rb +33 -12
  11. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
  14. data/lib/bridgetown-core/commands/console.rb +3 -3
  15. data/lib/bridgetown-core/commands/doctor.rb +13 -11
  16. data/lib/bridgetown-core/commands/new.rb +14 -6
  17. data/lib/bridgetown-core/commands/plugins.rb +8 -11
  18. data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
  19. data/lib/bridgetown-core/commands/serve.rb +37 -37
  20. data/lib/bridgetown-core/commands/start.rb +106 -0
  21. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
  22. data/lib/bridgetown-core/commands/webpack.rb +1 -1
  23. data/lib/bridgetown-core/component.rb +2 -6
  24. data/lib/bridgetown-core/concerns/liquid_renderable.rb +2 -2
  25. data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
  26. data/lib/bridgetown-core/concerns/site/content.rb +17 -118
  27. data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
  28. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  29. data/lib/bridgetown-core/concerns/site/processable.rb +9 -20
  30. data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
  31. data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
  32. data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
  33. data/lib/bridgetown-core/configuration.rb +19 -48
  34. data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
  35. data/lib/bridgetown-core/configurations/turbo.rb +1 -1
  36. data/lib/bridgetown-core/converter.rb +1 -0
  37. data/lib/bridgetown-core/converters/erb_templates.rb +8 -5
  38. data/lib/bridgetown-core/converters/liquid_templates.rb +5 -2
  39. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  40. data/lib/bridgetown-core/converters/smartypants.rb +1 -0
  41. data/lib/bridgetown-core/current.rb +4 -0
  42. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  43. data/lib/bridgetown-core/drops/drop.rb +4 -4
  44. data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
  45. data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
  46. data/lib/bridgetown-core/drops/site_drop.rb +3 -47
  47. data/lib/bridgetown-core/entry_filter.rb +1 -0
  48. data/lib/bridgetown-core/errors.rb +0 -2
  49. data/lib/bridgetown-core/filters/url_filters.rb +2 -0
  50. data/lib/bridgetown-core/filters.rb +11 -12
  51. data/lib/bridgetown-core/frontmatter_defaults.rb +44 -82
  52. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
  53. data/lib/bridgetown-core/generators/prototype_generator.rb +49 -61
  54. data/lib/bridgetown-core/helpers.rb +8 -3
  55. data/lib/bridgetown-core/hooks.rb +2 -2
  56. data/lib/bridgetown-core/layout.rb +15 -4
  57. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  58. data/lib/bridgetown-core/log_adapter.rb +1 -1
  59. data/lib/bridgetown-core/log_writer.rb +7 -1
  60. data/lib/bridgetown-core/model/base.rb +12 -4
  61. data/lib/bridgetown-core/model/builder_origin.rb +23 -11
  62. data/lib/bridgetown-core/model/origin.rb +3 -0
  63. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  64. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  65. data/lib/bridgetown-core/plugin_manager.rb +10 -10
  66. data/lib/bridgetown-core/publisher.rb +1 -1
  67. data/lib/bridgetown-core/rack/boot.rb +47 -0
  68. data/lib/bridgetown-core/rack/logger.rb +22 -0
  69. data/lib/bridgetown-core/rack/roda.rb +66 -0
  70. data/lib/bridgetown-core/rack/routes.rb +88 -0
  71. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  72. data/lib/bridgetown-core/reader.rb +20 -47
  73. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  74. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  75. data/lib/bridgetown-core/renderer.rb +2 -12
  76. data/lib/bridgetown-core/resource/base.rb +34 -11
  77. data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
  78. data/lib/bridgetown-core/resource/relations.rb +2 -3
  79. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  80. data/lib/bridgetown-core/resource/transformer.rb +8 -6
  81. data/lib/bridgetown-core/ruby_template_view.rb +6 -8
  82. data/lib/bridgetown-core/site.rb +4 -8
  83. data/lib/bridgetown-core/static_file.rb +14 -21
  84. data/lib/bridgetown-core/tags/find.rb +6 -6
  85. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  86. data/lib/bridgetown-core/tags/include.rb +22 -32
  87. data/lib/bridgetown-core/tags/link.rb +4 -0
  88. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  89. data/lib/bridgetown-core/tags/post_url.rb +9 -14
  90. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  91. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  92. data/lib/bridgetown-core/url.rb +5 -4
  93. data/lib/bridgetown-core/utils/aux.rb +57 -0
  94. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  95. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  96. data/lib/bridgetown-core/utils.rb +60 -33
  97. data/lib/bridgetown-core/version.rb +2 -2
  98. data/lib/bridgetown-core/watcher.rb +4 -6
  99. data/lib/bridgetown-core.rb +16 -23
  100. data/lib/site_template/Gemfile.erb +6 -2
  101. data/lib/site_template/README.md +6 -6
  102. data/lib/site_template/Rakefile +49 -0
  103. data/lib/site_template/bridgetown.config.yml +2 -3
  104. data/lib/site_template/config/puma.rb +27 -0
  105. data/lib/site_template/config.ru +7 -0
  106. data/lib/site_template/frontend/javascript/index.js.erb +3 -3
  107. data/lib/site_template/package.json.erb +7 -12
  108. data/lib/site_template/server/roda_app.rb +22 -0
  109. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  110. data/lib/site_template/src/_components/head.liquid +2 -1
  111. data/lib/site_template/src/about.md +0 -1
  112. data/lib/site_template/src/posts.md +2 -3
  113. metadata +63 -18
  114. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  115. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  116. data/lib/bridgetown-core/document.rb +0 -437
  117. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  118. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  119. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  120. data/lib/bridgetown-core/excerpt.rb +0 -200
  121. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  122. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  123. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  124. data/lib/bridgetown-core/regenerator.rb +0 -202
  125. data/lib/bridgetown-core/related_posts.rb +0 -55
  126. data/lib/site_template/config/.keep +0 -0
  127. data/lib/site_template/start.js +0 -17
  128. data/lib/site_template/sync.js +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93f29ed24b8de3b277f80f77581605e3e0ed4aa8a40f87bb5b3e3cbc68fa8dfa
4
- data.tar.gz: 9da3d6b3c608d7b067fdd9a65f6c05f1f40479c752d5c4fc5c523bcb9074e41b
3
+ metadata.gz: 2c5f6a5f0fc27c9e3f7d45161e91317fd42e7dbeb789d8c38a103a610efb9d46
4
+ data.tar.gz: 68431d8ead8cdb11107db03aa57ae3d4607d0809e60f3fd30d7045d58e1c67f0
5
5
  SHA512:
6
- metadata.gz: 63578f5534657f1ce647edd2f8d63ab7603d95d2ab3e2090a67baee046aa851f25eebca7d140525e39d5291f7101a286e0667eddedfe3dbbfe25a9f5a965f6ec
7
- data.tar.gz: a0d39c95cd660de86debb328c6aecd8e884ef2154caedd5e8d61b5de7c9268e3df4feb4c7f2ebc0706ec5d7eef40ce40b46be38190ce68a7679d42abd4dffd68
6
+ metadata.gz: 57daec3a249941fc6303a22e470cd8fc8e1641be8527a6533c7c73527a93fc04321b774407865a07fb99df95566902d035cfdf84fd68f8aa6e440fac6860d266
7
+ data.tar.gz: f42ce24666c948ad8616ef25cb36a766392279e216716a397d27308ae5b06acb58305887264f04c83faedf3ed6a68fcdbbf716e648935bb92de8c019997c1c03
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ inherit_from: ../.rubocop.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - "*.gemspec"
7
+ - bin/**/*
8
+ - exe/**/*
9
+ - benchmark/**/*
10
+ - script/**/*
11
+ - vendor/**/*
12
+ - tmp/**/*
13
+ - test/source/**/*
14
+ - lib/site_template/Rakefile
15
+ - lib/site_template/config.ru
16
+ - lib/site_template/config/**/*
17
+ - lib/site_template/plugins/site_builder.rb
18
+
19
+ Lint/ConstantDefinitionInBlock:
20
+ Exclude:
21
+ - test/test_filters.rb
22
+ - test/test_liquid_extensions.rb
23
+ - test/test_site.rb
24
+
25
+ Lint/MissingSuper:
26
+ Exclude:
27
+ - test/test_liquid_extensions.rb
28
+
29
+ Performance/CollectionLiteralInLoop:
30
+ Exclude:
31
+ - test/test_filters.rb
32
+
33
+ Style/StringConcatenation:
34
+ Exclude:
35
+ - test/test_apply_command.rb
data/Rakefile CHANGED
@@ -13,16 +13,16 @@ Rake::TestTask.new(:test) do |test|
13
13
  test.verbose = true
14
14
  end
15
15
 
16
- require 'yard'
16
+ require "yard"
17
17
  YARD::Rake::YardocTask.new(:yard) do |t|
18
- t.files = ['lib/**/*.rb']
19
- t.options = ['--no-output']
20
- t.stats_options = ['--list-undoc']
18
+ t.files = ["lib/**/*.rb"]
19
+ t.options = ["--no-output"]
20
+ t.stats_options = ["--list-undoc"]
21
21
  end
22
22
 
23
23
  namespace :yard do
24
24
  task :serve do
25
- port = ENV['YARD_PORT'] || "8808"
25
+ port = ENV["YARD_PORT"] || "8808"
26
26
  sh("yard server --reload -p #{port}")
27
27
  end
28
28
  end
data/bin/bridgetown CHANGED
@@ -24,5 +24,7 @@ output_version = if ARGV[0] == "-v"
24
24
  true
25
25
  end
26
26
 
27
+ ENV["RACK_ENV"] = ENV["BRIDGETOWN_ENV"]
28
+
27
29
  require "bridgetown-core/commands/base"
28
30
  Bridgetown::Commands::Base.start unless output_version
@@ -46,6 +46,9 @@ Gem::Specification.new do |s|
46
46
  s.add_runtime_dependency("liquid", "~> 5.0")
47
47
  s.add_runtime_dependency("liquid-component", ">= 0.1")
48
48
  s.add_runtime_dependency("listen", "~> 3.0")
49
+ s.add_runtime_dependency("rack-indifferent", ">= 1.2.0")
50
+ s.add_runtime_dependency("rake", ">= 13.0")
51
+ s.add_runtime_dependency("roda", "~> 3.46")
49
52
  s.add_runtime_dependency("rouge", "~> 3.0")
50
53
  s.add_runtime_dependency("terminal-table", "~> 1.8")
51
54
  s.add_runtime_dependency("thor", "~> 1.1")
@@ -82,11 +82,9 @@ module Bridgetown
82
82
  return @cache[key] if @cache.key?(key)
83
83
 
84
84
  path = path_to(hash(key))
85
- if disk_cache_enabled? && File.file?(path) && File.readable?(path)
86
- @cache[key] = load(path)
87
- else
88
- raise
89
- end
85
+ raise unless disk_cache_enabled? && File.file?(path) && File.readable?(path)
86
+
87
+ @cache[key] = load(path)
90
88
  end
91
89
 
92
90
  # Add an item to cache
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  # Handles the cleanup of a site's destination before it is built.
5
5
  class Cleaner
6
- HIDDEN_FILE_REGEX = %r!\/\.{1,2}$!.freeze
6
+ HIDDEN_FILE_REGEX = %r!/\.{1,2}$!.freeze
7
7
  attr_reader :site
8
8
 
9
9
  def initialize(site)
@@ -13,7 +13,6 @@ module Bridgetown
13
13
  # Cleans up the site's destination directory
14
14
  def cleanup!
15
15
  FileUtils.rm_rf(obsolete_files)
16
- FileUtils.rm_rf(metadata_file) unless @site.incremental?
17
16
  end
18
17
 
19
18
  private
@@ -28,13 +27,6 @@ module Bridgetown
28
27
  out
29
28
  end
30
29
 
31
- # Private: The metadata file storing dependency tree and build history
32
- #
33
- # Returns an Array with the metdata file as the only item
34
- def metadata_file
35
- [site.regenerator.metadata_file]
36
- end
37
-
38
30
  # Private: The list of existing files, apart from those included in
39
31
  # keep_files and hidden files.
40
32
  #
@@ -112,7 +104,7 @@ module Bridgetown
112
104
  #
113
105
  # Returns the regular expression
114
106
  def keep_file_regex
115
- %r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.config.keep_files).source})!
107
+ %r!\A#{Regexp.quote(site.dest)}/(#{Regexp.union(site.config.keep_files).source})!
116
108
  end
117
109
  end
118
110
  end
@@ -6,7 +6,6 @@ module Bridgetown
6
6
  attr_reader :site
7
7
 
8
8
  attr_reader :label, :metadata
9
- attr_writer :docs
10
9
 
11
10
  attr_writer :resources
12
11
 
@@ -24,22 +23,10 @@ module Bridgetown
24
23
  label.in? %w(posts pages data).freeze
25
24
  end
26
25
 
27
- def legacy_reader?
28
- label.in? %w(posts data).freeze
29
- end
30
-
31
26
  def data?
32
27
  label == "data"
33
28
  end
34
29
 
35
- # Fetch the Documents in this collection.
36
- # Defaults to an empty array if no documents have been read in.
37
- #
38
- # @return [Array<Bridgetown::Document>]
39
- def docs
40
- @docs ||= []
41
- end
42
-
43
30
  # Fetch the Resources in this collection.
44
31
  # Defaults to an empty array if no resources have been read in.
45
32
  #
@@ -48,10 +35,23 @@ module Bridgetown
48
35
  @resources ||= []
49
36
  end
50
37
 
51
- # Iterate over either Resources or Documents depending on how the site is
52
- # configured
38
+ # Fetch the collection resources and arrange them by slug in a hash.
39
+ #
40
+ # @return [Hash<String, Bridgetown::Resource::Base>]
41
+ def resources_by_slug
42
+ resources.group_by { |item| item.data.slug }.transform_values(&:first)
43
+ end
44
+
45
+ # Fetch the collection resources and arrange them by relative URL in a hash.
46
+ #
47
+ # @return [Hash<String, Bridgetown::Resource::Base>]
48
+ def resources_by_relative_url
49
+ resources.group_by(&:relative_url).transform_values(&:first)
50
+ end
51
+
52
+ # Iterate over Resources
53
53
  def each(&block)
54
- site.uses_resource? ? resources.each(&block) : docs.each(&block)
54
+ resources.each(&block)
55
55
  end
56
56
 
57
57
  # Fetch the static files in this collection.
@@ -67,38 +67,32 @@ module Bridgetown
67
67
  static_files
68
68
  end
69
69
 
70
- # Read the allowed documents into the collection's array of docs.
70
+ # Read the allowed resources into the collection's array of resources.
71
71
  #
72
72
  # @return [Bridgetown::Collection] self
73
- def read # rubocop:todo Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
73
+ def read
74
74
  filtered_entries.each do |file_path|
75
75
  full_path = collection_dir(file_path)
76
76
  next if File.directory?(full_path)
77
77
 
78
- if site.uses_resource?
79
- next if File.basename(file_path).starts_with?("_")
78
+ next if File.basename(file_path).starts_with?("_")
80
79
 
81
- if label == "data" || Utils.has_yaml_header?(full_path) ||
82
- Utils.has_rbfm_header?(full_path)
83
- read_resource(full_path)
84
- else
85
- read_static_file(file_path, full_path)
86
- end
87
- elsif Utils.has_yaml_header? full_path
88
- read_document(full_path)
80
+ if label == "data" || Utils.has_yaml_header?(full_path) ||
81
+ Utils.has_rbfm_header?(full_path)
82
+ read_resource(full_path)
89
83
  else
90
84
  read_static_file(file_path, full_path)
91
85
  end
92
86
  end
93
87
  site.static_files.concat(static_files)
94
- sort_docs!
88
+ sort_resources!
95
89
 
96
90
  self
97
91
  end
98
92
 
99
93
  # All the entries in this collection.
100
94
  #
101
- # @return [Array<String>] file paths to the documents in this collection
95
+ # @return [Array<String>] file paths to the resources in this collection
102
96
  # relative to the collection's folder
103
97
  def entries
104
98
  return [] unless exists?
@@ -178,7 +172,7 @@ module Bridgetown
178
172
  @entry_filter ||= Bridgetown::EntryFilter.new(
179
173
  site,
180
174
  base_directory: folder_name,
181
- include_underscores: site.uses_resource?
175
+ include_underscores: true
182
176
  )
183
177
  end
184
178
 
@@ -186,7 +180,7 @@ module Bridgetown
186
180
  #
187
181
  # @return [String]
188
182
  def inspect
189
- "#<#{self.class} @label=#{label} docs=#{docs} resources=#{resources}>"
183
+ "#<#{self.class} @label=#{label} resources=#{resources}>"
190
184
  end
191
185
 
192
186
  # Produce a sanitized label name
@@ -196,13 +190,13 @@ module Bridgetown
196
190
  # @param label [String] the possibly-unsafe label
197
191
  # @return [String] sanitized version of the label.
198
192
  def sanitize_label(label)
199
- label.gsub(%r![^a-z0-9_\-\.]!i, "")
193
+ label.gsub(%r![^a-z0-9_\-.]!i, "")
200
194
  end
201
195
 
202
196
  # Produce a representation of this Collection for use in Liquid.
203
197
  # Exposes two attributes:
204
198
  # - label
205
- # - docs
199
+ # - resources
206
200
  #
207
201
  # @return [Bridgetown::Drops::CollectionDrop] representation of this
208
202
  # collection for use in Liquid
@@ -210,7 +204,7 @@ module Bridgetown
210
204
  Drops::CollectionDrop.new self
211
205
  end
212
206
 
213
- # Whether the collection's documents ought to be written as individual
207
+ # Whether the collection's resources ought to be written as individual
214
208
  # files in the output.
215
209
  #
216
210
  # @return [Boolean] true if the 'write' metadata is true, false otherwise.
@@ -221,18 +215,7 @@ module Bridgetown
221
215
  # Used by Resource's permalink processor
222
216
  # @return [String]
223
217
  def default_permalink
224
- metadata.fetch("permalink") do
225
- "/:collection/:path/"
226
- end
227
- end
228
-
229
- # LEGACY: The URL template to render collection's documents at.
230
- #
231
- # @return [String]
232
- def url_template
233
- @url_template ||= metadata.fetch("permalink") do
234
- Utils.add_permalink_suffix("/:collection/:path", site.permalink_style)
235
- end
218
+ metadata.fetch("permalink", "/:collection/:path/")
236
219
  end
237
220
 
238
221
  # Extract options for this collection from the site configuration.
@@ -242,7 +225,7 @@ module Bridgetown
242
225
  site.config.collections[label] || HashWithDotAccess::Hash.new
243
226
  end
244
227
 
245
- def merge_data_resources # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
228
+ def merge_data_resources # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
246
229
  data_contents = {}
247
230
 
248
231
  sanitize_filename = ->(name) do
@@ -287,11 +270,30 @@ module Bridgetown
287
270
 
288
271
  # Read in resource from repo path
289
272
  # @param full_path [String]
290
- def read_resource(full_path)
291
- id = "repo://#{label}.collection/" + Addressable::URI.escape(
292
- Pathname(full_path).relative_path_from(Pathname(site.source)).to_s
293
- )
294
- resource = Bridgetown::Model::Base.find(id).to_resource.read!
273
+ def read_resource(full_path, manifest: nil) # rubocop:todo Metrics/AbcSize
274
+ scheme = manifest ? "plugin" : "repo"
275
+ id = +"#{scheme}://#{label}.collection/"
276
+ id += "#{manifest.origin}/" if manifest
277
+ id += Addressable::URI.escape(
278
+ Pathname(full_path).relative_path_from(
279
+ manifest ? Pathname(manifest.content) : Pathname(site.source)
280
+ ).to_s
281
+ ).gsub("#", "%23")
282
+ model = Bridgetown::Model::Base.find(id)
283
+
284
+ if model.attributes.key?(:locale) && model.locale.to_sym == :multi
285
+ site.config.available_locales.each do |locale|
286
+ model.locale = locale
287
+ add_model_resource model
288
+ end
289
+ return
290
+ end
291
+
292
+ add_model_resource model
293
+ end
294
+
295
+ def add_model_resource(model)
296
+ resource = model.to_resource.read!
295
297
  resources << resource if site.config.unpublished || resource.published?
296
298
  end
297
299
 
@@ -301,50 +303,24 @@ module Bridgetown
301
303
  @container ||= site.config["collections_dir"]
302
304
  end
303
305
 
304
- def read_document(full_path)
305
- doc = Document.new(full_path, site: site, collection: self).tap(&:read)
306
- docs << doc if site.config.unpublished || doc.published?
307
- end
308
-
309
- def sort_docs!
306
+ def sort_resources!
310
307
  if metadata["sort_by"].is_a?(String)
311
- sort_docs_by_key!
312
308
  sort_resources_by_key!
313
309
  else
314
- docs.sort!
315
310
  resources.sort!
316
311
  end
317
- docs.reverse! if metadata.sort_direction == "descending"
318
312
  resources.reverse! if metadata.sort_direction == "descending"
319
313
  end
320
314
 
321
315
  # A custom sort function based on Schwartzian transform
322
316
  # Refer https://byparker.com/blog/2017/schwartzian-transform-faster-sorting/ for details
323
- def sort_docs_by_key!
324
- meta_key = metadata["sort_by"]
325
- # Modify `docs` array to cache document's property along with the Document instance
326
- docs.map! { |doc| [doc.data[meta_key], doc] }.sort! do |apples, olives|
327
- order = determine_sort_order(meta_key, apples, olives)
328
-
329
- # Fall back to `Document#<=>` if the properties were equal or were non-sortable
330
- # Otherwise continue with current sort-order
331
- if order.nil? || order.zero?
332
- apples[-1] <=> olives[-1]
333
- else
334
- order
335
- end
336
-
337
- # Finally restore the `docs` array with just the Document objects themselves
338
- end.map!(&:last)
339
- end
340
-
341
317
  def sort_resources_by_key!
342
318
  meta_key = metadata["sort_by"]
343
- # Modify `docs` array to cache document's property along with the Document instance
344
- resources.map! { |doc| [doc.data[meta_key], doc] }.sort! do |apples, olives|
319
+ # Modify array to cache property along with the Resource instance
320
+ resources.map! { |r| [r.data[meta_key], r] }.sort! do |apples, olives|
345
321
  order = determine_sort_order(meta_key, apples, olives)
346
322
 
347
- # Fall back to `Document#<=>` if the properties were equal or were non-sortable
323
+ # Fall back to `Resource::Base#<=>` if the properties were equal or were non-sortable
348
324
  # Otherwise continue with current sort-order
349
325
  if order.nil? || order.zero?
350
326
  apples[-1] <=> olives[-1]
@@ -352,7 +328,7 @@ module Bridgetown
352
328
  order
353
329
  end
354
330
 
355
- # Finally restore the `docs` array with just the Document objects themselves
331
+ # Finally restore the `resources` array with just the objects themselves
356
332
  end.map!(&:last)
357
333
  end
358
334
 
@@ -369,9 +345,9 @@ module Bridgetown
369
345
  end
370
346
  end
371
347
 
372
- def order_with_warning(sort_key, document, order)
348
+ def order_with_warning(sort_key, resource, order)
373
349
  Bridgetown.logger.warn "Sort warning:", "'#{sort_key}' not defined in" \
374
- " #{document.relative_path}"
350
+ " #{resource.relative_path}"
375
351
  order
376
352
  end
377
353
 
@@ -17,13 +17,58 @@ module Bridgetown
17
17
  class << self
18
18
  # Override single character commands if necessary
19
19
  def find_command_possibilities(subcommand)
20
- if subcommand == "c"
20
+ case subcommand
21
+ when "c"
21
22
  ["console"]
23
+ when "s"
24
+ ["start"]
22
25
  else
23
26
  super
24
27
  end
25
28
  end
29
+
30
+ def display_rake_tasks(rake)
31
+ rake.options.show_all_tasks = true
32
+ rake.options.show_task_pattern = Regexp.new("")
33
+ rake.options.show_tasks = :tasks
34
+ rake.display_tasks_and_comments
35
+ end
36
+
37
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/GlobalVars
38
+ def handle_no_command_error(cmd, _has_namespace = $thor_runner)
39
+ require "rake"
40
+ Rake::TaskManager.record_task_metadata = true
41
+
42
+ Rake.with_application do |rake|
43
+ rake.instance_variable_set(:@name, "bridgetown")
44
+ rake.standard_exception_handling do
45
+ rakefile, _location = rake.find_rakefile_location
46
+ unless rakefile
47
+ puts "No Rakefile found (searching: #{rake.class::DEFAULT_RAKEFILES.join(", ")})\n"
48
+ new.invoke("help")
49
+ return # rubocop:disable Lint/NonLocalExitFromIterator
50
+ end
51
+ rake.load_rakefile
52
+ rake.top_level
53
+ end
54
+ cmd = cmd.split("[")
55
+ args = []
56
+ if cmd[1]
57
+ args = cmd[1].gsub("\\,", "__COMMA__").delete_suffix!("]").split(",").map do |item|
58
+ item.gsub("__COMMA__", ",")
59
+ end
60
+ end
61
+
62
+ if Rake::Task.task_defined?(cmd[0])
63
+ Rake::Task[cmd[0]].invoke(*args)
64
+ else
65
+ puts "Unknown task: #{cmd[0]}\n\nHere's a list of tasks you can run:"
66
+ display_rake_tasks(rake)
67
+ end
68
+ end
69
+ end
26
70
  end
71
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/GlobalVars
27
72
 
28
73
  desc "dream", "There's a place where that idea still exists as a reality"
29
74
  def dream
@@ -35,7 +80,7 @@ module Bridgetown
35
80
  end
36
81
 
37
82
  desc "help <command>", "Show detailed command usage information and exit"
38
- def help(subcommand = nil)
83
+ def help(subcommand = nil) # rubocop:disable Metrics/MethodLength
39
84
  if subcommand && respond_to?(subcommand)
40
85
  klass = Kernel.const_get("Bridgetown::Commands::#{subcommand.capitalize}")
41
86
  klass.start(["-h"])
@@ -47,6 +92,21 @@ module Bridgetown
47
92
  puts " bridgetown <command> [options]"
48
93
  puts ""
49
94
  super
95
+
96
+ require "rake"
97
+ Rake::TaskManager.record_task_metadata = true
98
+ Rake.with_application do |rake|
99
+ rake.instance_variable_set(:@name, " bridgetown")
100
+ rake.standard_exception_handling do
101
+ rakefile, _location = rake.find_rakefile_location
102
+ return unless rakefile # rubocop:disable Lint/NonLocalExitFromIterator
103
+
104
+ rake.load_rakefile
105
+ rake.top_level
106
+ puts "Available Rake Tasks:"
107
+ self.class.display_rake_tasks(rake)
108
+ end
109
+ end
50
110
  end
51
111
  end
52
112
  end
@@ -21,21 +21,32 @@ module Bridgetown
21
21
  aliases: "-w",
22
22
  desc: "Watch for changes and rebuild"
23
23
 
24
+ def self.print_startup_message
25
+ Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
26
+ " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
27
+ end
28
+
24
29
  # Build your bridgetown site
25
30
  # Continuously watch if `watch` is set to true in the config.
26
31
  def build
27
32
  Bridgetown.logger.adjust_verbosity(options)
28
33
 
29
- Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
30
- " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
34
+ unless caller_locations.find do |loc|
35
+ loc.to_s.include?("bridgetown-core/commands/start.rb")
36
+ end
37
+ self.class.print_startup_message
38
+ end
39
+
40
+ config_options = (
41
+ Bridgetown::Current.preloaded_configuration || configuration_with_overrides(options)
42
+ ).merge(options)
31
43
 
32
- config_options = Serve.loaded_config || configuration_with_overrides(options)
33
44
  config_options["serving"] = false unless config_options["serving"]
34
45
  @site = Bridgetown::Site.new(config_options)
35
46
 
36
47
  if config_options.fetch("skip_initial_build", false)
37
48
  Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
38
- " This may result in an out-of-date site."
49
+ " This may result in an out-of-date site."
39
50
  else
40
51
  build_site(config_options)
41
52
  end
@@ -64,13 +75,23 @@ module Bridgetown
64
75
  Bridgetown.logger.info "Unpublished mode:",
65
76
  "enabled. Processing documents marked unpublished"
66
77
  end
67
- incremental = config_options["incremental"]
68
- Bridgetown.logger.info "Incremental build:",
69
- (incremental ? "enabled" : "disabled. Enable with --incremental")
70
78
  Bridgetown.logger.info "Generating…"
71
79
  @site.process
72
80
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
73
- " #{(Time.now - t).ceil(2)} seconds."
81
+ " #{(Time.now - t).ceil(2)} seconds."
82
+
83
+ return unless config_options[:using_puma]
84
+
85
+ require "socket"
86
+ external_ip = Socket.ip_address_list.find do |ai|
87
+ ai.ipv4? && !ai.ipv4_loopback?
88
+ end&.ip_address
89
+ scheme = config_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
90
+ port = config_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
91
+ Bridgetown.logger.info ""
92
+ Bridgetown.logger.info "Now serving at:", "#{scheme}://localhost:#{port}".magenta
93
+ Bridgetown.logger.info "", "#{scheme}://#{external_ip}:#{port}".magenta if external_ip
94
+ Bridgetown.logger.info ""
74
95
  end
75
96
 
76
97
  # Watch for file changes and rebuild the site.
@@ -94,10 +115,10 @@ module Bridgetown
94
115
  Bridgetown.logger.info "Source:", source
95
116
  Bridgetown.logger.info "Destination:", destination
96
117
  # TODO: work with arrays
97
- if config_options["plugins_dir"].is_a?(String)
98
- plugins_dir = File.expand_path(config_options["plugins_dir"])
99
- Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
100
- end
118
+ return unless config_options["plugins_dir"].is_a?(String)
119
+
120
+ plugins_dir = File.expand_path(config_options["plugins_dir"])
121
+ Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
101
122
  end
102
123
  end
103
124
  end
@@ -25,7 +25,7 @@ module Bridgetown
25
25
  create_file("plugins/builders/#{filename}", data, verbose: false)
26
26
  end
27
27
 
28
- def javascript_import(data = nil, filename: "index.js")
28
+ def javascript_import(data = nil, filename: "index.js") # rubocop:todo Metrics/PerceivedComplexity
29
29
  data ||= yield if block_given?
30
30
  data += "\n" unless data.chars.last == "\n"
31
31
 
@@ -97,7 +97,7 @@ module Bridgetown
97
97
  github_match = GITHUB_REGEX.match(arg)
98
98
 
99
99
  arg = if arg.start_with?("https://gist.github.com")
100
- arg.sub(
100
+ arg.sub( # rubocop:disable Style/StringConcatenation
101
101
  "https://gist.github.com", "https://gist.githubusercontent.com"
102
102
  ) + "/raw"
103
103
  elsif github_match
@@ -33,18 +33,15 @@ module Bridgetown
33
33
  klass.class_option :future,
34
34
  type: :boolean,
35
35
  desc: "Publishes posts with a future date"
36
- klass.class_option :limit_posts,
37
- type: :numeric,
38
- desc: "Limits the number of posts to parse and publish"
36
+ klass.class_option :url,
37
+ aliases: "-u",
38
+ desc: "Override the configured url for the website"
39
39
  klass.class_option :base_path,
40
40
  aliases: "-b",
41
41
  desc: "Serve the website from the given base path"
42
42
  klass.class_option :force_polling,
43
43
  type: :boolean,
44
44
  desc: "Force watch to use polling"
45
- klass.class_option :lsi,
46
- type: :boolean,
47
- desc: "Use LSI for improved related posts"
48
45
  klass.class_option :unpublished,
49
46
  type: :boolean,
50
47
  aliases: "-U",
@@ -63,10 +60,6 @@ module Bridgetown
63
60
  aliases: "-V",
64
61
  type: :boolean,
65
62
  desc: "Print verbose output."
66
- klass.class_option :incremental,
67
- aliases: "-I",
68
- type: :boolean,
69
- desc: "Enable incremental rebuild."
70
63
  klass.class_option :strict_front_matter,
71
64
  type: :boolean,
72
65
  desc: "Fail if errors are present in front matter"
@@ -11,7 +11,9 @@ module Bridgetown
11
11
  def configuration_with_overrides(options)
12
12
  return options if options.is_a?(Bridgetown::Configuration)
13
13
 
14
- Bridgetown.configuration(options)
14
+ Bridgetown.configuration(options).tap do |new_config|
15
+ Bridgetown::Current.preloaded_configuration = new_config
16
+ end
15
17
  end
16
18
  end
17
19
  end