bridgetown-core 0.21.5 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +2 -0
  3. data/bridgetown-core.gemspec +3 -0
  4. data/lib/bridgetown-core/cleaner.rb +0 -8
  5. data/lib/bridgetown-core/collection.rb +59 -81
  6. data/lib/bridgetown-core/commands/base.rb +60 -1
  7. data/lib/bridgetown-core/commands/build.rb +26 -6
  8. data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
  9. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
  10. data/lib/bridgetown-core/commands/doctor.rb +3 -3
  11. data/lib/bridgetown-core/commands/new.rb +9 -3
  12. data/lib/bridgetown-core/commands/plugins.rb +1 -2
  13. data/lib/bridgetown-core/commands/serve.rb +14 -12
  14. data/lib/bridgetown-core/commands/start.rb +106 -0
  15. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
  16. data/lib/bridgetown-core/concerns/site/configurable.rb +0 -12
  17. data/lib/bridgetown-core/concerns/site/content.rb +6 -117
  18. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  19. data/lib/bridgetown-core/concerns/site/processable.rb +8 -20
  20. data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
  21. data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
  22. data/lib/bridgetown-core/concerns/site/writable.rb +5 -8
  23. data/lib/bridgetown-core/configuration.rb +18 -47
  24. data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
  25. data/lib/bridgetown-core/configurations/turbo.rb +1 -1
  26. data/lib/bridgetown-core/converters/erb_templates.rb +2 -1
  27. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
  28. data/lib/bridgetown-core/current.rb +4 -0
  29. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  30. data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
  31. data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
  32. data/lib/bridgetown-core/drops/site_drop.rb +3 -47
  33. data/lib/bridgetown-core/filters/url_filters.rb +3 -1
  34. data/lib/bridgetown-core/frontmatter_defaults.rb +44 -80
  35. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -58
  36. data/lib/bridgetown-core/generators/prototype_generator.rb +10 -21
  37. data/lib/bridgetown-core/helpers.rb +7 -2
  38. data/lib/bridgetown-core/layout.rb +15 -4
  39. data/lib/bridgetown-core/log_writer.rb +6 -0
  40. data/lib/bridgetown-core/model/base.rb +10 -2
  41. data/lib/bridgetown-core/model/builder_origin.rb +22 -10
  42. data/lib/bridgetown-core/model/origin.rb +3 -0
  43. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  44. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  45. data/lib/bridgetown-core/plugin_manager.rb +0 -2
  46. data/lib/bridgetown-core/rack/boot.rb +47 -0
  47. data/lib/bridgetown-core/rack/logger.rb +22 -0
  48. data/lib/bridgetown-core/rack/roda.rb +66 -0
  49. data/lib/bridgetown-core/rack/routes.rb +92 -0
  50. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  51. data/lib/bridgetown-core/reader.rb +16 -48
  52. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  53. data/lib/bridgetown-core/renderer.rb +1 -11
  54. data/lib/bridgetown-core/resource/base.rb +33 -10
  55. data/lib/bridgetown-core/resource/permalink_processor.rb +20 -10
  56. data/lib/bridgetown-core/resource/relations.rb +2 -3
  57. data/lib/bridgetown-core/resource/transformer.rb +1 -1
  58. data/lib/bridgetown-core/ruby_template_view.rb +5 -5
  59. data/lib/bridgetown-core/site.rb +4 -8
  60. data/lib/bridgetown-core/static_file.rb +10 -15
  61. data/lib/bridgetown-core/tags/include.rb +0 -13
  62. data/lib/bridgetown-core/tags/link.rb +4 -0
  63. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  64. data/lib/bridgetown-core/tags/post_url.rb +4 -9
  65. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  66. data/lib/bridgetown-core/url.rb +2 -1
  67. data/lib/bridgetown-core/utils/aux.rb +57 -0
  68. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  69. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  70. data/lib/bridgetown-core/utils.rb +37 -2
  71. data/lib/bridgetown-core/version.rb +2 -2
  72. data/lib/bridgetown-core/watcher.rb +2 -4
  73. data/lib/bridgetown-core.rb +14 -22
  74. data/lib/site_template/Gemfile.erb +6 -2
  75. data/lib/site_template/README.md +6 -6
  76. data/lib/site_template/Rakefile +49 -0
  77. data/lib/site_template/bridgetown.config.yml +2 -3
  78. data/lib/site_template/config/puma.rb +27 -0
  79. data/lib/site_template/config.ru +7 -0
  80. data/lib/site_template/package.json.erb +1 -9
  81. data/lib/site_template/server/roda_app.rb +22 -0
  82. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  83. data/lib/site_template/src/_components/head.liquid +2 -1
  84. data/lib/site_template/src/about.md +0 -1
  85. data/lib/site_template/src/posts.md +2 -3
  86. metadata +62 -18
  87. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  88. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  89. data/lib/bridgetown-core/document.rb +0 -437
  90. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  91. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  92. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  93. data/lib/bridgetown-core/excerpt.rb +0 -200
  94. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  95. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  96. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  97. data/lib/bridgetown-core/regenerator.rb +0 -202
  98. data/lib/bridgetown-core/related_posts.rb +0 -55
  99. data/lib/site_template/config/.keep +0 -0
  100. data/lib/site_template/start.js +0 -17
  101. data/lib/site_template/sync.js +0 -35
@@ -12,36 +12,33 @@ module Bridgetown
12
12
  # Read Site data from disk and load it into internal data structures.
13
13
  #
14
14
  # Returns nothing.
15
- def read # rubocop:todo Metrics/AbcSize
15
+ def read
16
16
  site.defaults_reader.read
17
- site.layouts = LayoutReader.new(site).read
17
+ read_layouts
18
18
  read_directories
19
- read_included_excludes
19
+ read_includes
20
20
  sort_files!
21
- site.data = if site.uses_resource?
22
- site.collections.data.read
23
- site.collections.data.merge_data_resources
24
- else
25
- DataReader.new(site).read
26
- end
21
+ site.data = site.collections.data.read.merge_data_resources
27
22
  read_collections
28
- Bridgetown::PluginManager.source_manifests.map(&:content).compact.each do |plugin_content_dir|
29
- PluginContentReader.new(site, plugin_content_dir).read
23
+ Bridgetown::PluginManager.source_manifests.select(&:content).each do |manifest|
24
+ PluginContentReader.new(site, manifest).read
30
25
  end
31
26
  end
32
27
 
28
+ def read_layouts
29
+ site.layouts = LayoutReader.new(site).read
30
+ end
31
+
33
32
  def read_collections
34
33
  site.collections.each_value do |collection|
35
- next if site.uses_resource? && collection.data?
36
- next if !site.uses_resource? && collection.legacy_reader?
34
+ next if collection.data?
37
35
 
38
36
  collection.read
39
37
  end
40
38
  end
41
39
 
42
- # Sorts posts, pages, and static files.
40
+ # Sorts generated pages and static files.
43
41
  def sort_files!
44
- site.collections.posts.docs.sort! unless site.uses_resource?
45
42
  site.generated_pages.sort_by!(&:name)
46
43
  site.static_files.sort_by!(&:relative_path)
47
44
  end
@@ -74,24 +71,11 @@ module Bridgetown
74
71
  end
75
72
  end
76
73
 
77
- retrieve_posts(dir) unless site.uses_resource?
78
74
  retrieve_dirs(base, dir, dot_dirs)
79
75
  retrieve_pages(dir, dot_pages)
80
76
  retrieve_static_files(dir, dot_static_files)
81
77
  end
82
78
 
83
- # Retrieves all the posts(posts) from the given directory
84
- # and add them to the site and sort them.
85
- #
86
- # dir - The String representing the directory to retrieve the posts from.
87
- #
88
- # Returns nothing.
89
- def retrieve_posts(dir)
90
- return if outside_configured_directory?(dir)
91
-
92
- post_reader.read_posts(dir)
93
- end
94
-
95
79
  # Recursively traverse directories with the read_directories function.
96
80
  #
97
81
  # base - The String representing the site's base directory.
@@ -115,14 +99,9 @@ module Bridgetown
115
99
  #
116
100
  # Returns nothing.
117
101
  def retrieve_pages(dir, dot_pages)
118
- if site.uses_resource?
119
- dot_pages.each do |page_path|
120
- site.collections.pages.read_resource(site.in_source_dir(dir, page_path))
121
- end
122
- return
102
+ dot_pages.each do |page_path|
103
+ site.collections.pages.read_resource(site.in_source_dir(dir, page_path))
123
104
  end
124
-
125
- site.pages.concat(PageReader.new(site, dir).read(dot_pages))
126
105
  end
127
106
 
128
107
  # Retrieve all the static files from the current directory,
@@ -180,13 +159,7 @@ module Bridgetown
180
159
  !collections_dir.empty? && !dir.start_with?("/#{collections_dir}")
181
160
  end
182
161
 
183
- # Create a single PostReader instance to retrieve posts from all valid
184
- # directories in current site.
185
- def post_reader
186
- @post_reader ||= PostReader.new(site)
187
- end
188
-
189
- def read_included_excludes
162
+ def read_includes
190
163
  site.config.include.each do |entry|
191
164
  next if entry == ".htaccess"
192
165
 
@@ -200,12 +173,7 @@ module Bridgetown
200
173
  def read_included_file(entry_path)
201
174
  dir = File.dirname(entry_path).sub(site.source, "")
202
175
  file = Array(File.basename(entry_path))
203
- if Utils.has_yaml_header?(entry_path)
204
- # TODO: does this need to get incorporated into the resource engine?
205
- site.pages.concat(PageReader.new(site, dir).read(file))
206
- else
207
- retrieve_static_files(dir, file)
208
- end
176
+ retrieve_static_files(dir, file)
209
177
  end
210
178
  end
211
179
  end
@@ -2,11 +2,14 @@
2
2
 
3
3
  module Bridgetown
4
4
  class PluginContentReader
5
- attr_reader :site, :content_dir
5
+ attr_reader :site, :manifest, :content_dir
6
6
 
7
- def initialize(site, plugin_content_dir)
7
+ # @param site [Bridgetown::Site]
8
+ # @param manifest [Bridgetown::Plugin::SourceManifest]
9
+ def initialize(site, manifest)
8
10
  @site = site
9
- @content_dir = plugin_content_dir
11
+ @manifest = manifest
12
+ @content_dir = manifest.content
10
13
  @content_files = Set.new
11
14
  end
12
15
 
@@ -28,13 +31,11 @@ module Bridgetown
28
31
  dir = File.dirname(path.sub("#{content_dir}/", ""))
29
32
  name = File.basename(path)
30
33
 
31
- @content_files << if Utils.has_yaml_header?(path)
32
- Bridgetown::Page.new(site, content_dir, dir, name, from_plugin: true)
34
+ @content_files << if Utils.has_yaml_header?(path) || Utils.has_rbfm_header?(path)
35
+ site.collections.pages.read_resource(path, manifest: manifest)
33
36
  else
34
37
  Bridgetown::StaticFile.new(site, content_dir, "/#{dir}", name)
35
38
  end
36
-
37
- add_to(site.pages, Bridgetown::Page)
38
39
  add_to(site.static_files, Bridgetown::StaticFile)
39
40
  end
40
41
 
@@ -65,7 +65,7 @@ module Bridgetown
65
65
  def execute_inline_ruby!
66
66
  return unless site.config.should_execute_inline_ruby?
67
67
 
68
- Bridgetown::Utils::RubyExec.search_data_for_ruby_code(document, self)
68
+ Bridgetown::Utils::RubyExec.search_data_for_ruby_code(document)
69
69
  end
70
70
 
71
71
  # Convert the document using the converters which match this renderer's document.
@@ -98,7 +98,6 @@ module Bridgetown
98
98
 
99
99
  while layout
100
100
  output = render_layout(output, layout)
101
- add_regenerator_dependencies(layout)
102
101
 
103
102
  next unless (layout = site.layouts[layout.data["layout"]])
104
103
  break if used.include?(layout)
@@ -144,15 +143,6 @@ module Bridgetown
144
143
  end
145
144
  end
146
145
 
147
- def add_regenerator_dependencies(layout)
148
- return unless document.write?
149
-
150
- site.regenerator.add_dependency(
151
- site.in_source_dir(document.path),
152
- layout.path
153
- )
154
- end
155
-
156
146
  def permalink_ext
157
147
  document_permalink = document.permalink
158
148
  if document_permalink &&
@@ -116,6 +116,8 @@ module Bridgetown
116
116
 
117
117
  def transform!
118
118
  transformer.process! unless collection.data?
119
+
120
+ self
119
121
  end
120
122
 
121
123
  def trigger_hooks(hook_name, *args)
@@ -261,19 +263,18 @@ module Bridgetown
261
263
  "#<#{self.class} #{id}>"
262
264
  end
263
265
 
264
- # Compare this document against another document.
265
- # Comparison is a comparison between the 2 paths of the documents.
266
+ # Compare this resource against another resource.
267
+ # Comparison is a comparison between the 2 dates or paths of the resources.
266
268
  #
267
- # Returns -1, 0, +1 or nil depending on whether this doc's path is less than,
268
- # equal or greater than the other doc's path. See String#<=> for more details.
269
- def <=>(other) # rubocop:todo Metrics/AbcSize
269
+ # @return [Integer] -1, 0, or +1
270
+ def <=>(other) # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity
270
271
  return nil unless other.respond_to?(:data)
271
272
 
272
- if data.date.respond_to?(:to_datetime) && other.data.date.respond_to?(:to_datetime)
273
- return data.date.to_datetime <=> other.data.date.to_datetime
274
- end
273
+ cmp = if data.date.respond_to?(:to_datetime) && other.data.date.respond_to?(:to_datetime)
274
+ data.date.to_datetime <=> other.data.date.to_datetime
275
+ end
275
276
 
276
- cmp = data["date"] <=> other.data["date"]
277
+ cmp = data["date"] <=> other.data["date"] if cmp.nil?
277
278
  cmp = path <=> other.path if cmp.nil? || cmp.zero?
278
279
  cmp
279
280
  end
@@ -293,6 +294,8 @@ module Bridgetown
293
294
  private
294
295
 
295
296
  def ensure_default_data
297
+ determine_locale
298
+
296
299
  slug = if matches = relative_path.to_s.match(DATE_FILENAME_MATCHER) # rubocop:disable Lint/AssignmentInCondition
297
300
  set_date_from_string(matches[1]) unless data.date
298
301
  matches[2]
@@ -300,6 +303,8 @@ module Bridgetown
300
303
  basename_without_ext
301
304
  end
302
305
 
306
+ slug.chomp!(".#{data.locale}") if data.locale && slug.ends_with?(".#{data.locale}")
307
+
303
308
  data.slug ||= slug
304
309
  data.title ||= Bridgetown::Utils.titleize_slug(slug)
305
310
  end
@@ -309,7 +314,7 @@ module Bridgetown
309
314
 
310
315
  data.date = Bridgetown::Utils.parse_date(
311
316
  new_date,
312
- "Document '#{relative_path}' does not have a valid date in the #{model}."
317
+ "Resource '#{relative_path}' does not have a valid date."
313
318
  )
314
319
  end
315
320
 
@@ -332,6 +337,24 @@ module Bridgetown
332
337
  end
333
338
  end
334
339
 
340
+ def determine_locale
341
+ unless data.locale
342
+ data.locale = locale_from_alt_data_or_filename.presence || site.config.default_locale
343
+ end
344
+
345
+ if data.locale_overrides&.is_a?(Hash) && data.locale_overrides&.key?(data.locale)
346
+ data.merge!(data.locale_overrides[data.locale])
347
+ end
348
+ end
349
+
350
+ # Look for alternative front matter or look at the filename pattern: slug.locale.ext
351
+ def locale_from_alt_data_or_filename
352
+ found_locale = data.language || data.lang || basename_without_ext.split(".")[1..-1].last
353
+ return unless found_locale && site.config.available_locales.include?(found_locale.to_sym)
354
+
355
+ found_locale
356
+ end
357
+
335
358
  def format_url(url)
336
359
  url.to_s.sub(%r{index\.html?$}, "").sub(%r{\.html?$}, "")
337
360
  end
@@ -36,11 +36,10 @@ module Bridgetown
36
36
  new_url = url_segments.map do |segment|
37
37
  segment.starts_with?(":") ? process_segment(segment.sub(%r{^:}, "")) : segment
38
38
  end.select(&:present?).join("/")
39
-
40
39
  # No relative URLs should ever end in /index.html
41
40
  new_url.sub!(%r{/index$}, "") if final_ext == ".html"
42
41
 
43
- add_base_path finalize_permalink(new_url, permalink)
42
+ ensure_base_path finalize_permalink(new_url, permalink)
44
43
  end
45
44
 
46
45
  def process_segment(segment)
@@ -66,13 +65,13 @@ module Bridgetown
66
65
 
67
66
  case permalink_style.to_sym
68
67
  when :pretty
69
- "#{collection_prefix}/:categories/:year/:month/:day/:slug/"
68
+ "/:locale/#{collection_prefix}/:categories/:year/:month/:day/:slug/"
70
69
  when :pretty_ext, :date
71
- "#{collection_prefix}/:categories/:year/:month/:day/:slug.*"
70
+ "/:locale/#{collection_prefix}/:categories/:year/:month/:day/:slug.*"
72
71
  when :simple
73
- "#{collection_prefix}/:categories/:slug/"
72
+ "/:locale/#{collection_prefix}/:categories/:slug/"
74
73
  when :simple_ext
75
- "#{collection_prefix}/:categories/:slug.*"
74
+ "/:locale/#{collection_prefix}/:categories/:slug.*"
76
75
  else
77
76
  permalink_style.to_s
78
77
  end
@@ -96,7 +95,7 @@ module Bridgetown
96
95
  end
97
96
  end
98
97
 
99
- def add_base_path(permalink)
98
+ def ensure_base_path(permalink)
100
99
  if resource.site.base_path.present?
101
100
  return "#{resource.site.base_path(strip_slash_only: true)}#{permalink}"
102
101
  end
@@ -108,7 +107,16 @@ module Bridgetown
108
107
 
109
108
  # @param resource [Bridgetown::Resource::Base]
110
109
  register_placeholder :path, ->(resource) do
111
- { raw_value: resource.relative_path_basename_without_prefix }
110
+ {
111
+ raw_value: resource.relative_path_basename_without_prefix.tap do |path|
112
+ if resource.site.config["collections_dir"].present?
113
+ path.delete_prefix! "#{resource.site.config["collections_dir"]}/"
114
+ end
115
+ if resource.data.locale && path.ends_with?(".#{resource.data.locale}")
116
+ path.chomp!(".#{resource.data.locale}")
117
+ end
118
+ end,
119
+ }
112
120
  end
113
121
 
114
122
  # @param resource [Bridgetown::Resource::Base]
@@ -128,8 +136,10 @@ module Bridgetown
128
136
 
129
137
  # @param resource [Bridgetown::Resource::Base]
130
138
  register_placeholder :locale, ->(resource) do
131
- locale_data = resource.data.locale
132
- resource.site.config.available_locales.include?(locale_data) ? locale_data : nil
139
+ next nil if resource.data.locale&.to_sym == resource.site.config.default_locale
140
+
141
+ locale_data = resource.data.locale&.to_sym
142
+ resource.site.config.available_locales.include?(locale_data) ? locale_data.to_s : nil
133
143
  end
134
144
  register_placeholder :lang, placeholder_processors[:locale]
135
145
 
@@ -94,9 +94,8 @@ module Bridgetown
94
94
  # @return [Bridgetown::Resource::Base, Array<Bridgetown::Resource::Base>]
95
95
  def belongs_to_relation_for_type(type)
96
96
  if resource.data[type].is_a?(Array)
97
- other_collection_for_type(type).resources.select do |other_resource|
98
- other_resource.data.slug.in?(resource.data[type])
99
- end
97
+ other_slugs = other_collection_for_type(type).resources_by_slug
98
+ resource.data[type].map { |slug| other_slugs[slug] }.compact
100
99
  else
101
100
  other_collection_for_type(type).resources.find do |other_resource|
102
101
  other_resource.data.slug == resource.data[type]
@@ -41,7 +41,7 @@ module Bridgetown
41
41
  def execute_inline_ruby!
42
42
  return unless site.config.should_execute_inline_ruby?
43
43
 
44
- Bridgetown::Utils::RubyExec.search_data_for_ruby_code(resource, self)
44
+ Bridgetown::Utils::RubyExec.search_data_for_ruby_code(resource)
45
45
  end
46
46
 
47
47
  def inspect
@@ -62,16 +62,16 @@ module Bridgetown
62
62
  end
63
63
 
64
64
  # rubocop:disable Style/MissingRespondToMissing
65
- ruby2_keywords def method_missing(method, *args, &block)
66
- if helpers.respond_to?(method.to_sym)
67
- helpers.send method.to_sym, *args, &block
65
+ ruby2_keywords def method_missing(method_name, *args, &block)
66
+ if helpers.respond_to?(method_name.to_sym)
67
+ helpers.send method_name.to_sym, *args, &block
68
68
  else
69
69
  super
70
70
  end
71
71
  end
72
72
 
73
- def respond_to_missing?(method, include_private = false)
74
- helpers.respond_to?(method.to_sym, include_private) || super
73
+ def respond_to_missing?(method_name, include_private = false)
74
+ helpers.respond_to?(method_name.to_sym, include_private) || super
75
75
  end
76
76
  # rubocop:enable Style/MissingRespondToMissing
77
77
 
@@ -10,10 +10,11 @@ module Bridgetown
10
10
  include Localizable
11
11
  include Processable
12
12
  include Renderable
13
+ include SSR
13
14
  include Writable
14
15
 
15
16
  attr_reader :root_dir, :source, :dest, :cache_dir, :config,
16
- :regenerator, :liquid_renderer, :components_load_paths,
17
+ :liquid_renderer, :components_load_paths,
17
18
  :includes_load_paths
18
19
 
19
20
  # All files not pages/documents or structured data in the source folder
@@ -23,12 +24,8 @@ module Bridgetown
23
24
  # @return [Array<Layout>]
24
25
  attr_accessor :layouts
25
26
 
26
- # @return [Array<Page>]
27
- attr_accessor :pages
28
-
29
- # NOTE: Eventually pages will be deprecated once the Resource content engine
30
- # is default
31
- alias_method :generated_pages, :pages
27
+ # @return [Array<GeneratedPage>]
28
+ attr_accessor :generated_pages
32
29
 
33
30
  attr_accessor :permalink_style, :time, :data,
34
31
  :file_read_opts, :plugin_manager, :converters,
@@ -44,7 +41,6 @@ module Bridgetown
44
41
  @plugin_manager = PluginManager.new(self)
45
42
  @cleaner = Cleaner.new(self)
46
43
  @reader = Reader.new(self)
47
- @regenerator = Regenerator.new(self)
48
44
  @liquid_renderer = LiquidRenderer.new(self)
49
45
 
50
46
  ensure_not_in_dest
@@ -21,10 +21,11 @@ module Bridgetown
21
21
 
22
22
  # Initialize a new StaticFile.
23
23
  #
24
- # site - The Site.
25
- # base - The String path to the <source>.
26
- # dir - The String path between <source> and the file.
27
- # name - The String filename of the file.
24
+ # @param site [Bridgetown::Site]
25
+ # @param base [String] path to the <source>.
26
+ # @param dir [String] path between <source> and the file.
27
+ # @param name [String] filename of the file.
28
+ # @param collection [Bridgetown::Collection] optional collection the file is attached to
28
29
  def initialize(site, base, dir, name, collection = nil) # rubocop:disable Metrics/ParameterLists
29
30
  @site = site
30
31
  @base = base
@@ -34,13 +35,11 @@ module Bridgetown
34
35
  @relative_path = File.join(*[@dir, @name].compact)
35
36
  @extname = File.extname(@name)
36
37
  @data = @site.frontmatter_defaults.all(relative_path, type).with_dot_access
37
- if site.uses_resource? && !data.permalink
38
- data.permalink = if collection && !collection.builtin?
39
- "/:collection/:path.*"
38
+ data.permalink ||= if collection && !collection.builtin?
39
+ collection.default_permalink.chomp("/").chomp(".*") + ".*"
40
40
  else
41
41
  "/:path.*"
42
42
  end
43
- end
44
43
  end
45
44
 
46
45
  # Returns source file path.
@@ -58,7 +57,7 @@ module Bridgetown
58
57
  def destination(dest)
59
58
  dest = site.in_dest_dir(dest)
60
59
  dest_url = url
61
- if site.uses_resource? && site.base_path.present? && collection
60
+ if site.base_path.present? && collection
62
61
  dest_url = dest_url.delete_prefix site.base_path(strip_slash_only: true)
63
62
  end
64
63
  site.in_dest_dir(dest, Bridgetown::URL.unescape_path(dest_url))
@@ -112,6 +111,7 @@ module Bridgetown
112
111
 
113
112
  FileUtils.mkdir_p(File.dirname(dest_path))
114
113
  FileUtils.rm(dest_path) if File.exist?(dest_path)
114
+ Bridgetown.logger.debug "Saving file:", dest_path
115
115
  copy_file(dest_path)
116
116
 
117
117
  true
@@ -177,14 +177,9 @@ module Bridgetown
177
177
  site.config.content_engine != "resource"
178
178
  base = if @collection.nil? || special_posts_case
179
179
  cleaned_relative_path
180
- elsif site.uses_resource?
180
+ else
181
181
  newly_processed = true
182
182
  Bridgetown::Resource::PermalinkProcessor.new(self).transform
183
- else
184
- Bridgetown::URL.new(
185
- template: @collection.url_template,
186
- placeholders: placeholders
187
- )
188
183
  end.to_s.chomp("/")
189
184
  newly_processed ? base : "#{base}#{extname}"
190
185
  end
@@ -119,16 +119,12 @@ module Bridgetown
119
119
  end
120
120
 
121
121
  def render(context)
122
- site = context.registers[:site]
123
-
124
122
  file = render_variable(context) || @file
125
123
  validate_file_name(file)
126
124
 
127
125
  path = locate_include_file(context, file)
128
126
  return unless path
129
127
 
130
- add_include_to_dependency(site, path, context)
131
-
132
128
  partial = load_cached_partial(path, context)
133
129
 
134
130
  context.stack do
@@ -143,15 +139,6 @@ module Bridgetown
143
139
  end
144
140
  end
145
141
 
146
- def add_include_to_dependency(site, path, context)
147
- if context.registers[:page]&.key?("path")
148
- site.regenerator.add_dependency(
149
- site.in_source_dir(context.registers[:page]["path"]),
150
- path
151
- )
152
- end
153
- end
154
-
155
142
  def load_cached_partial(path, context)
156
143
  context.registers[:cached_partials] ||= {}
157
144
  cached_partial = context.registers[:cached_partials]
@@ -23,6 +23,10 @@ module Bridgetown
23
23
  relative_path = Liquid::Template.parse(@relative_path).render(context)
24
24
 
25
25
  site.each_site_file do |item|
26
+ # Resource engine:
27
+ if item.respond_to?(:relative_url) && item.relative_path.to_s == relative_path
28
+ return item.relative_url
29
+ end
26
30
  return relative_url(item) if item.relative_path == relative_path
27
31
  # This takes care of the case for static files that have a leading /
28
32
  return relative_url(item) if item.relative_path == "/#{relative_path}"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class LiveReloadJsTag < Liquid::Tag
6
+ def render(context)
7
+ Bridgetown::Utils.live_reload_js(context.registers[:site])
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ Liquid::Template.register_tag("live_reload_dev_js", Bridgetown::Tags::LiveReloadJsTag)
@@ -29,7 +29,7 @@ module Bridgetown
29
29
  end
30
30
 
31
31
  def ==(other)
32
- other.relative_path.match(@name_regex)
32
+ other.relative_path.to_s.match(@name_regex)
33
33
  end
34
34
 
35
35
  def deprecated_equality(other)
@@ -47,12 +47,7 @@ module Bridgetown
47
47
  #
48
48
  # Returns the post slug with the subdirectory (relative to _posts)
49
49
  def post_slug(other)
50
- path = other.basename.split("/")[0...-1].join("/")
51
- if path.nil? || path == ""
52
- other.data["slug"]
53
- else
54
- path + "/" + other.data["slug"]
55
- end
50
+ other.data.slug
56
51
  end
57
52
  end
58
53
 
@@ -77,14 +72,14 @@ module Bridgetown
77
72
  @context = context
78
73
  site = context.registers[:site]
79
74
 
80
- site.collections.posts.docs.each do |document|
75
+ site.collections.posts.resources.each do |document|
81
76
  return relative_url(document) if @post == document
82
77
  end
83
78
 
84
79
  # New matching method did not match, fall back to old method
85
80
  # with deprecation warning if this matches
86
81
 
87
- site.collections.posts.docs.each do |document|
82
+ site.collections.posts.resources.each do |document|
88
83
  next unless @post.deprecated_equality document
89
84
 
90
85
  Bridgetown::Deprecator.deprecation_message "A call to "\
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :frontend do
4
+ desc "Run frontend bundler independently"
5
+ task :watcher, :sidecar do |_task, args|
6
+ # sidecar is when the task is running alongside the start command
7
+ sidecar = args[:sidecar] == true
8
+ Bridgetown::Utils::Aux.group do
9
+ run_process "Frontend", :yellow, "bundle exec bridgetown frontend:dev"
10
+ end
11
+ if sidecar
12
+ sleep 4 # give Webpack time to boot before returning control to the start command
13
+ else
14
+ trap("INT") do
15
+ Bridgetown::Utils::Aux.kill_processes
16
+ sleep 0.5
17
+ exit(0)
18
+ end
19
+ loop { sleep 1000 }
20
+ end
21
+ end
22
+ end
23
+
24
+ desc "Prerequisite task which loads site and provides automation"
25
+ task :environment do
26
+ class HammerActions < Thor
27
+ include Thor::Actions
28
+ include Bridgetown::Commands::Actions
29
+
30
+ def self.source_root
31
+ Dir.pwd
32
+ end
33
+
34
+ def self.exit_on_failure?
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def site
41
+ @site ||= Bridgetown::Site.new(Bridgetown.configuration)
42
+ end
43
+ end
44
+
45
+ define_singleton_method :automation do |*args, &block|
46
+ @hammer ||= HammerActions.new
47
+ @hammer.instance_exec(*args, &block)
48
+ end
49
+
50
+ define_singleton_method :site do
51
+ @hammer ||= HammerActions.new
52
+ @hammer.send(:site)
53
+ end
54
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Public: Methods that generate a URL for a resource such as a Post or a Page.
3
+ # Public: Methods that generate a URL for GeneratedPage.
4
4
  #
5
5
  # Examples
6
6
  #
@@ -10,6 +10,7 @@
10
10
  # }).to_s
11
11
  #
12
12
  module Bridgetown
13
+ # TODO: remove this class in favor of the new Resource permalink processor
13
14
  class URL
14
15
  # options - One of :permalink or :template must be supplied.
15
16
  # :template - The String used as template for URL generation,