bridgetown-core 0.21.0.beta2 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +0 -1
  3. data/lib/bridgetown-core.rb +16 -15
  4. data/lib/bridgetown-core/cleaner.rb +2 -2
  5. data/lib/bridgetown-core/collection.rb +13 -8
  6. data/lib/bridgetown-core/commands/concerns/build_options.rb +2 -2
  7. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  8. data/lib/bridgetown-core/commands/configure.rb +4 -3
  9. data/lib/bridgetown-core/commands/new.rb +6 -6
  10. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  11. data/lib/bridgetown-core/commands/serve.rb +1 -1
  12. data/lib/bridgetown-core/commands/webpack.rb +82 -0
  13. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
  14. data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
  15. data/lib/bridgetown-core/commands/webpack/update.rb +24 -0
  16. data/lib/bridgetown-core/commands/webpack/webpack.config.js +31 -0
  17. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +130 -0
  18. data/lib/bridgetown-core/component.rb +36 -31
  19. data/lib/bridgetown-core/concerns/front_matter_importer.rb +2 -2
  20. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  21. data/lib/bridgetown-core/concerns/site/configurable.rb +18 -7
  22. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  23. data/lib/bridgetown-core/concerns/site/processable.rb +5 -4
  24. data/lib/bridgetown-core/concerns/validatable.rb +1 -1
  25. data/lib/bridgetown-core/configuration.rb +12 -5
  26. data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
  27. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  28. data/lib/bridgetown-core/configurations/tailwindcss.rb +14 -9
  29. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +2 -2
  30. data/lib/bridgetown-core/converters/erb_templates.rb +1 -1
  31. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  32. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  33. data/lib/bridgetown-core/document.rb +2 -2
  34. data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
  35. data/lib/bridgetown-core/drops/site_drop.rb +2 -0
  36. data/lib/bridgetown-core/entry_filter.rb +5 -3
  37. data/lib/bridgetown-core/filters/url_filters.rb +4 -8
  38. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  39. data/lib/bridgetown-core/generators/prototype_generator.rb +25 -4
  40. data/lib/bridgetown-core/layout.rb +27 -10
  41. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  42. data/lib/bridgetown-core/publisher.rb +2 -2
  43. data/lib/bridgetown-core/reader.rb +1 -1
  44. data/lib/bridgetown-core/readers/data_reader.rb +1 -1
  45. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  46. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  47. data/lib/bridgetown-core/regenerator.rb +1 -1
  48. data/lib/bridgetown-core/related_posts.rb +5 -2
  49. data/lib/bridgetown-core/resource/base.rb +29 -7
  50. data/lib/bridgetown-core/resource/destination.rb +3 -1
  51. data/lib/bridgetown-core/resource/permalink_processor.rb +7 -3
  52. data/lib/bridgetown-core/resource/transformer.rb +4 -2
  53. data/lib/bridgetown-core/site.rb +4 -5
  54. data/lib/bridgetown-core/static_file.rb +3 -2
  55. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  56. data/lib/bridgetown-core/utils.rb +1 -1
  57. data/lib/bridgetown-core/version.rb +1 -1
  58. data/lib/bridgetown-core/watcher.rb +1 -0
  59. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  60. data/lib/site_template/bridgetown.config.yml +5 -1
  61. data/lib/site_template/config/.keep +0 -0
  62. data/lib/site_template/package.json.erb +8 -11
  63. data/lib/site_template/plugins/site_builder.rb +1 -1
  64. data/lib/site_template/src/_data/site_metadata.yml +1 -1
  65. metadata +12 -17
  66. data/lib/site_template/webpack.config.js.erb +0 -122
@@ -4,23 +4,23 @@
4
4
 
5
5
  TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
6
6
 
7
- begin
8
- find_in_source_paths("postcss.config.js")
9
- rescue Thor::Error
7
+ unless File.exist?("postcss.config.js")
10
8
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
9
 
12
10
  @logger.error "\nError:".red, "🚨 #{error_message}"
13
- @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
11
+ @logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
14
12
 
15
13
  return
16
14
  end
17
15
 
16
+ confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
17
+ return unless confirm.casecmp?("Y")
18
+
18
19
  plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
19
20
 
20
21
  say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
21
22
  run "yarn add -D #{plugins.join(' ')}"
22
23
 
23
- remove_file "postcss.config.js"
24
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
24
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
25
25
 
26
26
  # rubocop:enable all
@@ -4,3 +4,4 @@ TEMPLATE_PATH = File.expand_path("./netlify", __dir__)
4
4
 
5
5
  copy_file "#{TEMPLATE_PATH}/netlify.toml", "netlify.toml"
6
6
  copy_file "#{TEMPLATE_PATH}/netlify.sh", "bin/netlify.sh"
7
+ `chmod a+x ./bin/netlify.sh`
@@ -4,26 +4,31 @@
4
4
 
5
5
  TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
6
6
 
7
- begin
8
- find_in_source_paths("postcss.config.js")
9
- rescue Thor::Error
7
+ unless File.exist?("postcss.config.js")
10
8
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
9
 
12
10
  @logger.error "\nError:".red, "🚨 #{error_message}"
13
- @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
11
+ @logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
14
12
 
15
13
  return
16
14
  end
17
15
 
16
+ confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
17
+ return unless confirm.casecmp?("Y")
18
+
18
19
  run "yarn add -D tailwindcss"
19
20
  run "npx tailwindcss init"
20
21
 
21
- remove_file "postcss.config.js"
22
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
23
-
24
- prepend_to_file "frontend/styles/index.css",
25
- File.read("#{TEMPLATE_PATH}/css_imports.css")
22
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
26
23
 
27
24
  run "bundle exec bridgetown configure purgecss"
28
25
 
26
+ if File.exist?("frontend/styles/index.css")
27
+ prepend_to_file "frontend/styles/index.css",
28
+ File.read("#{TEMPLATE_PATH}/css_imports.css")
29
+ else
30
+ say "\nPlease add the following lines to your CSS index file:"
31
+ say File.read("#{TEMPLATE_PATH}/css_imports.css")
32
+ end
33
+
29
34
  # rubocop:enable all
@@ -6,7 +6,7 @@ module.exports = {
6
6
  autoprefixer: {
7
7
  flexbox: 'no-2009'
8
8
  },
9
- stage: 3
9
+ stage: 2
10
10
  }
11
11
  }
12
- }
12
+ }
@@ -104,7 +104,7 @@ module Bridgetown
104
104
  # Logic to do the ERB content conversion.
105
105
  #
106
106
  # @param content [String] Content of the file (without front matter).
107
- # @params convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
107
+ # @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
108
108
  # The instantiated object which is processing the file.
109
109
  #
110
110
  # @return [String] The converted content.
@@ -18,7 +18,7 @@ module Bridgetown
18
18
  # Logic to do the Liquid content conversion.
19
19
  #
20
20
  # @param content [String] Content of the file (without front matter).
21
- # @params convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
21
+ # @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
22
22
  # The instantiated object which is processing the file.
23
23
  #
24
24
  # @return [String] The converted content.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module CoreExt
5
+ module Psych
6
+ module SafeLoadFile
7
+ def safe_load_file(filename, **kwargs)
8
+ File.open(filename, "r:bom|utf-8") do |f|
9
+ if RUBY_VERSION.start_with?("2.5")
10
+ safe_load f, kwargs[:permitted_classes], [], false, filename
11
+ else
12
+ safe_load f, filename: filename, **kwargs
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -224,7 +224,7 @@ module Bridgetown
224
224
  Bridgetown.logger.debug "Reading:", relative_path
225
225
 
226
226
  if yaml_file?
227
- @data = SafeYAML.load_file(path)
227
+ @data = YAMLParser.load_file(path)
228
228
  else
229
229
  begin
230
230
  merge_defaults
@@ -358,7 +358,7 @@ module Bridgetown
358
358
  self.content = File.read(path, **Utils.merged_file_read_opts(site, opts))
359
359
  if content =~ YAML_FRONT_MATTER_REGEXP
360
360
  self.content = $POSTMATCH
361
- data_file = SafeYAML.load(Regexp.last_match(1))
361
+ data_file = YAMLParser.load(Regexp.last_match(1))
362
362
  merge_data!(data_file, source: "YAML front matter") if data_file
363
363
  end
364
364
  end
@@ -17,6 +17,7 @@ module Bridgetown
17
17
  :data,
18
18
  :output,
19
19
  :content,
20
+ :summary,
20
21
  :to_s,
21
22
  :absolute_url,
22
23
  :relative_path,
@@ -48,7 +49,7 @@ module Bridgetown
48
49
  end
49
50
 
50
51
  def next
51
- @next ||= @obj.previous_resource.to_liquid
52
+ @next ||= @obj.next_resource.to_liquid
52
53
  end
53
54
 
54
55
  # Generate a Hash for use in generating JSON.
@@ -8,6 +8,8 @@ module Bridgetown
8
8
  mutable false
9
9
 
10
10
  def_delegators :@obj,
11
+ :baseurl, # deprecated
12
+ :base_path,
11
13
  :data,
12
14
  :locale,
13
15
  :time,
@@ -43,8 +43,8 @@ module Bridgetown
43
43
  end
44
44
 
45
45
  def included?(entry)
46
- glob_include?(site.include, entry) ||
47
- glob_include?(site.include, File.basename(entry))
46
+ glob_include?(site.config.include, entry) ||
47
+ glob_include?(site.config.include, File.basename(entry))
48
48
  end
49
49
 
50
50
  def special?(entry)
@@ -62,7 +62,9 @@ module Bridgetown
62
62
  end
63
63
 
64
64
  def excluded?(entry)
65
- glob_include?(site.exclude - site.include, relative_to_source(entry)).tap do |excluded|
65
+ glob_include?(
66
+ site.config.exclude - site.config.include, relative_to_source(entry)
67
+ ).tap do |excluded|
66
68
  if excluded
67
69
  Bridgetown.logger.debug(
68
70
  "EntryFilter:",
@@ -5,7 +5,7 @@ module Bridgetown
5
5
  module URLFilters
6
6
  extend self
7
7
 
8
- # Produces an absolute URL based on site.url and site.baseurl.
8
+ # Produces an absolute URL based on site.url and site.base_path.
9
9
  #
10
10
  # input - the URL to make absolute.
11
11
  #
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  cache[input] ||= compute_absolute_url(input)
16
16
  end
17
17
 
18
- # Produces a URL relative to the domain root based on site.baseurl
18
+ # Produces a URL relative to the domain root based on site.base_path
19
19
  # unless it is already an absolute url with an authority (host).
20
20
  #
21
21
  # input - the URL to make relative to the domain root
@@ -70,17 +70,13 @@ module Bridgetown
70
70
  input = input.url if input.respond_to?(:url)
71
71
  return input if Addressable::URI.parse(input.to_s).absolute?
72
72
 
73
- parts = [sanitized_baseurl, input]
73
+ site = @context.registers[:site]
74
+ parts = [site.base_path.chomp("/"), input]
74
75
  Addressable::URI.parse(
75
76
  parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
76
77
  ).normalize.to_s
77
78
  end
78
79
 
79
- def sanitized_baseurl
80
- site = @context.registers[:site]
81
- site.config["baseurl"].to_s.chomp("/")
82
- end
83
-
84
80
  def ensure_leading_slash(input)
85
81
  return input if input.nil? || input.empty? || input.start_with?("/")
86
82
 
@@ -13,7 +13,7 @@ module Bridgetown
13
13
  end
14
14
 
15
15
  def reset
16
- @glob_cache = {} if @glob_cache
16
+ @glob_cache = {}
17
17
  end
18
18
 
19
19
  def update_deprecated_types(set)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Handles Legacy Pages
3
+ # Handles Generated Pages
4
4
  Bridgetown::Hooks.register :pages, :post_init, reloadable: false do |page|
5
5
  if page.class != Bridgetown::PrototypePage && page.data["prototype"].is_a?(Hash)
6
6
  Bridgetown::PrototypeGenerator.add_matching_template(page)
@@ -14,6 +14,11 @@ Bridgetown::Hooks.register :resources, :post_read, reloadable: false do |resourc
14
14
  end
15
15
  end
16
16
 
17
+ # Ensure sites clear out templates before rebuild
18
+ Bridgetown::Hooks.register :site, :after_reset, reloadable: false do |_site|
19
+ Bridgetown::PrototypeGenerator.matching_templates.clear
20
+ end
21
+
17
22
  module Bridgetown
18
23
  class PrototypeGenerator < Generator
19
24
  priority :low
@@ -21,9 +26,9 @@ module Bridgetown
21
26
  # @return [Bridgetown::Site]
22
27
  attr_reader :site
23
28
 
24
- # @return [Array<Bridgetown::Page, Bridgetown::Resource::Base>]
29
+ # @return [Set<Bridgetown::Page, Bridgetown::Resource::Base>]
25
30
  def self.matching_templates
26
- @matching_templates ||= []
31
+ @matching_templates ||= Set.new
27
32
  end
28
33
 
29
34
  def self.add_matching_template(template)
@@ -41,6 +46,8 @@ module Bridgetown
41
46
  end
42
47
 
43
48
  if prototype_pages.length.positive?
49
+ ensure_pagination_enabled
50
+
44
51
  page_list.reject! do |page|
45
52
  prototype_pages.include? page
46
53
  end
@@ -56,6 +63,15 @@ module Bridgetown
56
63
  end
57
64
  end
58
65
 
66
+ def ensure_pagination_enabled
67
+ unless @site.config.dig(:pagination, :enabled)
68
+ Bridgetown.logger.warn(
69
+ "Pagination:",
70
+ "Must be enabled for prototype pages to contain matches"
71
+ )
72
+ end
73
+ end
74
+
59
75
  # Check incoming prototype configuration and normalize options.
60
76
  #
61
77
  # @param prototype_page [Bridgetown::Page, Bridgetown::Resource::Base]
@@ -70,7 +86,12 @@ module Bridgetown
70
86
  @configured_collection = prototype_page.data["prototype"]["collection"]
71
87
  end
72
88
 
73
- return nil unless site.collections[@configured_collection]
89
+ unless site.collections[@configured_collection]
90
+ Bridgetown.logger.warn(
91
+ "No collection specified for prototype page #{prototype_page.relative_path}"
92
+ )
93
+ return nil
94
+ end
74
95
 
75
96
  # Categories and Tags are unique in that singular and plural front matter
76
97
  # can be present for each
@@ -39,12 +39,22 @@ module Bridgetown
39
39
  # Gets/Sets the document output (for layout-compatible converters)
40
40
  attr_accessor :current_document_output
41
41
 
42
+ # Determines the label a layout should use based on its filename
43
+ #
44
+ # @param file [String]
45
+ # @return [String]
46
+ def self.label_for_file(file)
47
+ # TODO: refactor this so multi-extension layout filenames don't leak
48
+ # middle extensions into layout label
49
+ file.split(".")[0..-2].join(".")
50
+ end
51
+
42
52
  # Initialize a new Layout.
43
53
  #
44
- # site - The Site.
45
- # base - The String path to the source.
46
- # name - The String filename of the layout file.
47
- # from_plugin - true if the layout comes from a Gem-based plugin folder.
54
+ # @param site [Bridgetown::Site]
55
+ # @param base [String] The path to the source.
56
+ # @param name [String] The filename of the layout file.
57
+ # @param from_plugin [Boolean] if the layout comes from a Gem-based plugin folder.
48
58
  def initialize(site, base, name, from_plugin: false)
49
59
  @site = site
50
60
  @base = base
@@ -83,17 +93,24 @@ module Bridgetown
83
93
  end
84
94
  end
85
95
 
86
- # The inspect string for this document.
87
- # Includes the relative path and the collection label.
96
+ # The label of the layout (should match what would used in front matter
97
+ # references).
88
98
  #
89
- # Returns the inspect string for this document.
99
+ # @return [String]
100
+ def label
101
+ @label ||= self.class.label_for_file(name)
102
+ end
103
+
104
+ # The inspect string for this layout. Includes the relative path.
105
+ #
106
+ # @return [String]
90
107
  def inspect
91
- "#<#{self.class} #{@path}>"
108
+ "#<#{self.class} #{relative_path}>"
92
109
  end
93
110
 
94
- # Provide this Layout's data to a Hash suitable for use by Liquid.
111
+ # Provide this Layout's data for use by Liquid.
95
112
  #
96
- # Returns the Hash representation of this Layout.
113
+ # @return [HashWithDotAccess::Hash]
97
114
  def to_liquid
98
115
  data
99
116
  end
@@ -102,7 +102,7 @@ module Bridgetown
102
102
  when ".rb"
103
103
  process_ruby_data(File.read(original_path), original_path, 1)
104
104
  else
105
- yaml_data = SafeYAML.load_file(original_path)
105
+ yaml_data = YAMLParser.load_file(original_path)
106
106
  yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data
107
107
  end
108
108
  end
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  return false unless thing.respond_to?(:date)
16
16
 
17
17
  future_allowed =
18
- thing.respond_to?(:collection) && thing.collection.metadata.future || @site.future
18
+ thing.respond_to?(:collection) && thing.collection.metadata.future || @site.config.future
19
19
  thing_time = thing.date.is_a?(Date) ? thing.date.to_time.to_i : thing.date.to_i
20
20
  !future_allowed && thing_time > @site.time.to_i
21
21
  end
@@ -23,7 +23,7 @@ module Bridgetown
23
23
  private
24
24
 
25
25
  def can_be_published?(thing)
26
- thing.data.fetch("published", true) || @site.unpublished
26
+ thing.data.fetch("published", true) || @site.config.unpublished
27
27
  end
28
28
  end
29
29
  end
@@ -183,7 +183,7 @@ module Bridgetown
183
183
  end
184
184
 
185
185
  def read_included_excludes
186
- site.include.each do |entry|
186
+ site.config.include.each do |entry|
187
187
  next if entry == ".htaccess"
188
188
 
189
189
  entry_path = site.in_source_dir(entry)
@@ -68,7 +68,7 @@ module Bridgetown
68
68
  headers: true,
69
69
  encoding: site.config["encoding"]).map(&:to_hash)
70
70
  else
71
- SafeYAML.load_file(path)
71
+ YAMLParser.load_file(path)
72
72
  end
73
73
  end
74
74
 
@@ -18,7 +18,7 @@ module Bridgetown
18
18
 
19
19
  entries.each do |entry|
20
20
  path = @site.in_source_dir(entry)
21
- @path_defaults[File.dirname(path) + File::SEPARATOR] = SafeYAML.load_file(path)
21
+ @path_defaults[File.dirname(path) + File::SEPARATOR] = YAMLParser.load_file(path)
22
22
  end
23
23
 
24
24
  @path_defaults
@@ -44,7 +44,7 @@ module Bridgetown
44
44
  end
45
45
 
46
46
  def layout_name(file)
47
- file.split(".")[0..-2].join(".")
47
+ Layout.label_for_file(file)
48
48
  end
49
49
 
50
50
  def within(directory)
@@ -154,7 +154,7 @@ module Bridgetown
154
154
  begin
155
155
  Marshal.load(content)
156
156
  rescue TypeError
157
- SafeYAML.load(content)
157
+ YAMLParser.load(content)
158
158
  rescue ArgumentError => e
159
159
  Bridgetown.logger.warn("Failed to load #{metadata_file}: #{e}")
160
160
  {}