bridgetown-core 0.19.0 → 0.21.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +6 -0
  3. data/bridgetown-core.gemspec +3 -4
  4. data/lib/bridgetown-core.rb +34 -12
  5. data/lib/bridgetown-core/cleaner.rb +7 -1
  6. data/lib/bridgetown-core/collection.rb +176 -77
  7. data/lib/bridgetown-core/commands/apply.rb +4 -3
  8. data/lib/bridgetown-core/commands/base.rb +9 -0
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
  10. data/lib/bridgetown-core/commands/configure.rb +66 -0
  11. data/lib/bridgetown-core/commands/console.rb +4 -0
  12. data/lib/bridgetown-core/commands/new.rb +8 -0
  13. data/lib/bridgetown-core/commands/plugins.rb +1 -0
  14. data/lib/bridgetown-core/component.rb +178 -0
  15. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  16. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  17. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
  18. data/lib/bridgetown-core/concerns/site/content.rb +56 -15
  19. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  20. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  21. data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
  22. data/lib/bridgetown-core/concerns/validatable.rb +1 -4
  23. data/lib/bridgetown-core/configuration.rb +49 -28
  24. data/lib/bridgetown-core/configurations/.keep +0 -0
  25. data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
  26. data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
  27. data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
  28. data/lib/bridgetown-core/configurations/netlify.rb +6 -0
  29. data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
  30. data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
  31. data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
  32. data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
  33. data/lib/bridgetown-core/configurations/swup.rb +37 -0
  34. data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
  35. data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
  36. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
  37. data/lib/bridgetown-core/configurations/turbo.rb +16 -0
  38. data/lib/bridgetown-core/converter.rb +23 -0
  39. data/lib/bridgetown-core/converters/erb_templates.rb +50 -41
  40. data/lib/bridgetown-core/converters/identity.rb +0 -9
  41. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  42. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +3 -0
  43. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  44. data/lib/bridgetown-core/current.rb +10 -0
  45. data/lib/bridgetown-core/document.rb +6 -14
  46. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  47. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  48. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  49. data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
  50. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  51. data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
  52. data/lib/bridgetown-core/entry_filter.rb +10 -23
  53. data/lib/bridgetown-core/errors.rb +0 -2
  54. data/lib/bridgetown-core/filters.rb +3 -2
  55. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  56. data/lib/bridgetown-core/generator.rb +2 -1
  57. data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
  58. data/lib/bridgetown-core/helpers.rb +48 -9
  59. data/lib/bridgetown-core/layout.rb +28 -13
  60. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  61. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  62. data/lib/bridgetown-core/model/base.rb +138 -0
  63. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  64. data/lib/bridgetown-core/model/origin.rb +38 -0
  65. data/lib/bridgetown-core/model/repo_origin.rb +126 -0
  66. data/lib/bridgetown-core/page.rb +9 -1
  67. data/lib/bridgetown-core/plugin.rb +2 -26
  68. data/lib/bridgetown-core/plugin_manager.rb +0 -2
  69. data/lib/bridgetown-core/publisher.rb +7 -1
  70. data/lib/bridgetown-core/reader.rb +26 -13
  71. data/lib/bridgetown-core/readers/data_reader.rb +3 -4
  72. data/lib/bridgetown-core/readers/post_reader.rb +1 -1
  73. data/lib/bridgetown-core/regenerator.rb +8 -1
  74. data/lib/bridgetown-core/related_posts.rb +1 -1
  75. data/lib/bridgetown-core/renderer.rb +6 -13
  76. data/lib/bridgetown-core/resource/base.rb +317 -0
  77. data/lib/bridgetown-core/resource/destination.rb +49 -0
  78. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  79. data/lib/bridgetown-core/resource/relations.rb +132 -0
  80. data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
  81. data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
  82. data/lib/bridgetown-core/resource/transformer.rb +175 -0
  83. data/lib/bridgetown-core/ruby_template_view.rb +12 -4
  84. data/lib/bridgetown-core/site.rb +9 -1
  85. data/lib/bridgetown-core/static_file.rb +33 -10
  86. data/lib/bridgetown-core/url.rb +1 -0
  87. data/lib/bridgetown-core/utils.rb +48 -41
  88. data/lib/bridgetown-core/utils/platforms.rb +1 -0
  89. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  90. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  91. data/lib/bridgetown-core/version.rb +2 -2
  92. data/lib/bridgetown-core/watcher.rb +1 -1
  93. data/lib/site_template/README.md +70 -0
  94. data/lib/site_template/package.json.erb +2 -2
  95. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  96. data/lib/site_template/webpack.config.js.erb +26 -6
  97. metadata +55 -39
  98. data/lib/bridgetown-core/page_without_a_file.rb +0 -17
  99. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  100. data/lib/bridgetown-core/utils/exec.rb +0 -26
  101. data/lib/bridgetown-core/utils/internet.rb +0 -37
  102. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Model
5
+ # Abstract Superclass
6
+ class BuilderOrigin < Origin
7
+ # @return [Pathname]
8
+ attr_reader :relative_path
9
+
10
+ # Override in subclass
11
+ def self.handle_scheme?(scheme)
12
+ scheme == "builder"
13
+ end
14
+
15
+ def initialize(id)
16
+ self.id = id
17
+ @relative_path = Pathname.new(id.delete_prefix("builder://"))
18
+ end
19
+
20
+ def read
21
+ @data = if block_given?
22
+ yield
23
+ elsif defined?(SiteBuilder) && SiteBuilder.respond_to?(:data_for_id)
24
+ SiteBuilder.data_for_id(id)
25
+ else
26
+ raise "No builder exists which can read #{id}"
27
+ end
28
+ @data[:_id_] = id
29
+ @data[:_origin_] = self
30
+ @relative_path = Pathname.new(@data[:_relative_path_]) if @data[:_relative_path_]
31
+
32
+ @data
33
+ end
34
+
35
+ def exists?
36
+ false
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Model
5
+ # Abstract Superclass
6
+ class Origin
7
+ extend ActiveSupport::DescendantsTracker
8
+
9
+ # @return [String]
10
+ attr_accessor :id
11
+
12
+ # Override in subclass
13
+ def self.handle_scheme?(_scheme)
14
+ false
15
+ end
16
+
17
+ def initialize(id)
18
+ self.id = id
19
+ end
20
+
21
+ def read
22
+ raise "Implement #read in a subclass of Bridgetown::Model::Origin"
23
+ end
24
+
25
+ # @return [Pathname]
26
+ def relative_path
27
+ raise "Implement #relative_path in a subclass of Bridgetown::Model::Origin"
28
+ end
29
+
30
+ def exists?
31
+ raise "Implement #exists? in a subclass of Bridgetown::Model::Origin"
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ require "bridgetown-core/model/builder_origin"
38
+ require "bridgetown-core/model/repo_origin"
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Model
5
+ class RepoOrigin < Origin
6
+ include Bridgetown::FrontMatterImporter
7
+ include Bridgetown::Utils::RubyFrontMatterDSL
8
+
9
+ YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
10
+ RUBY_FRONT_MATTER_HEADER = %r!\A[~`#\-]{3,}(?:ruby|<%|{%)\s*\n!.freeze
11
+ RUBY_FRONT_MATTER_REGEXP =
12
+ %r!#{RUBY_FRONT_MATTER_HEADER.source}(.*?\n?)^((?:%>|%})?[~`#\-]{3,}\s*$\n?)!m.freeze
13
+
14
+ # @return [String]
15
+ attr_accessor :content
16
+
17
+ # @return [Integer]
18
+ attr_accessor :front_matter_line_count
19
+
20
+ class << self
21
+ def handle_scheme?(scheme)
22
+ scheme == "repo"
23
+ end
24
+
25
+ def data_file_extensions
26
+ %w(.yaml .yml .json .csv .tsv .rb).freeze
27
+ end
28
+ end
29
+
30
+ def read
31
+ begin
32
+ @data = (in_data_collection? ? read_file_data : read_front_matter(original_path)) || {}
33
+ rescue SyntaxError => e
34
+ Bridgetown.logger.error "Error:",
35
+ "Ruby Exception in #{e.message}"
36
+ rescue StandardError => e
37
+ handle_read_error(e)
38
+ end
39
+
40
+ @data ||= {}
41
+ @data[:_id_] = id
42
+ @data[:_origin_] = self
43
+ @data[:_collection_] = collection
44
+ @data[:_content_] = content if content
45
+
46
+ @data
47
+ end
48
+
49
+ def url
50
+ @url = URI.parse(id)
51
+ end
52
+
53
+ def relative_path
54
+ @relative_path ||= Pathname.new(
55
+ Addressable::URI.unescape(url.path.delete_prefix("/"))
56
+ )
57
+ end
58
+
59
+ def collection
60
+ return @collection if @collection
61
+
62
+ collection_name = if url.host.ends_with?(".collection")
63
+ url.host.chomp(".collection")
64
+ else
65
+ "pages"
66
+ end
67
+ @collection = Bridgetown::Current.site.collections[collection_name]
68
+ end
69
+
70
+ def original_path
71
+ @original_path ||= relative_path.expand_path(Bridgetown::Current.site.source)
72
+ end
73
+
74
+ def exists?
75
+ File.exist?(original_path)
76
+ end
77
+
78
+ private
79
+
80
+ def in_data_collection?
81
+ original_path.extname.downcase.in?(self.class.data_file_extensions) &&
82
+ collection.data?
83
+ end
84
+
85
+ def read_file_data # rubocop:todo Metrics/MethodLength
86
+ case original_path.extname.downcase
87
+ when ".csv"
88
+ {
89
+ rows:
90
+ CSV.read(original_path,
91
+ headers: true,
92
+ encoding: Bridgetown::Current.site.config["encoding"]).map(&:to_hash),
93
+ }
94
+ when ".tsv"
95
+ {
96
+ rows:
97
+ CSV.read(original_path,
98
+ col_sep: "\t",
99
+ headers: true,
100
+ encoding: Bridgetown::Current.site.config["encoding"]).map(&:to_hash),
101
+ }
102
+ when ".rb"
103
+ process_ruby_data(File.read(original_path), original_path, 1)
104
+ else
105
+ yaml_data = SafeYAML.load_file(original_path)
106
+ yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data
107
+ end
108
+ end
109
+
110
+ def handle_read_error(error)
111
+ if error.is_a? Psych::SyntaxError
112
+ Bridgetown.logger.error "Error:",
113
+ "YAML Exception reading #{original_path}: #{error.message}"
114
+ else
115
+ Bridgetown.logger.error "Error:",
116
+ "could not read file #{original_path}: #{error.message}"
117
+ end
118
+
119
+ if Bridgetown::Current.site.config["strict_front_matter"] ||
120
+ error.is_a?(Bridgetown::Errors::FatalException)
121
+ raise error
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -47,7 +47,7 @@ module Bridgetown
47
47
  read_yaml(PathManager.join(base, dir), name)
48
48
 
49
49
  data.default_proc = proc do |_, key|
50
- site.frontmatter_defaults.find(relative_path, type, key)
50
+ site.frontmatter_defaults.find(relative_path, type, key.to_s)
51
51
  end
52
52
 
53
53
  Bridgetown::Hooks.trigger :pages, :post_init, self
@@ -116,6 +116,7 @@ module Bridgetown
116
116
  permalink: permalink
117
117
  ).to_s
118
118
  end
119
+ alias_method :relative_url, :url
119
120
 
120
121
  # Returns a hash of URL placeholder names (as symbols) mapping to the
121
122
  # desired placeholder replacements. For details see "url.rb"
@@ -218,4 +219,11 @@ module Bridgetown
218
219
  true
219
220
  end
220
221
  end
222
+
223
+ # set up virtual page class for future compatibility
224
+ class GeneratedPage < Page
225
+ def read_yaml(_base, _name, _opts = {})
226
+ self.data ||= HashWithDotAccess::Hash.new
227
+ end
228
+ end
221
229
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Plugin
5
+ extend ActiveSupport::DescendantsTracker
6
+
5
7
  PRIORITIES = {
6
8
  low: -10,
7
9
  highest: 100,
@@ -12,32 +14,6 @@ module Bridgetown
12
14
 
13
15
  SourceManifest = Struct.new(:origin, :components, :content, :layouts, keyword_init: true)
14
16
 
15
- #
16
-
17
- def self.inherited(const)
18
- catch_inheritance(const) do |const_|
19
- catch_inheritance(const_)
20
- end
21
- end
22
-
23
- #
24
-
25
- def self.catch_inheritance(const)
26
- const.define_singleton_method :inherited do |const_|
27
- (@children ||= Set.new).add const_
28
- yield const_ if block_given?
29
- end
30
- end
31
-
32
- #
33
-
34
- def self.descendants
35
- @children ||= Set.new
36
- out = @children.map(&:descendants)
37
- out << self unless superclass == Plugin
38
- Set.new(out).flatten
39
- end
40
-
41
17
  # Get or set the priority of this plugin. When called without an
42
18
  # argument it returns the priority. When an argument is given, it will
43
19
  # set the priority.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "zeitwerk"
4
-
5
3
  module Bridgetown
6
4
  class PluginManager
7
5
  PLUGINS_GROUP = :bridgetown_plugins
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Publisher
5
+ # @param site [Bridgetown::Site]
5
6
  def initialize(site)
6
7
  @site = site
7
8
  end
@@ -11,7 +12,12 @@ module Bridgetown
11
12
  end
12
13
 
13
14
  def hidden_in_the_future?(thing)
14
- thing.respond_to?(:date) && !@site.future && thing.date.to_i > @site.time.to_i
15
+ return false unless thing.respond_to?(:date)
16
+
17
+ future_allowed =
18
+ thing.respond_to?(:collection) && thing.collection.metadata.future || @site.future
19
+ thing_time = thing.date.is_a?(Date) ? thing.date.to_time.to_i : thing.date.to_i
20
+ !future_allowed && thing_time > @site.time.to_i
15
21
  end
16
22
 
17
23
  private
@@ -11,20 +11,29 @@ module Bridgetown
11
11
  # Read Site data from disk and load it into internal data structures.
12
12
  #
13
13
  # Returns nothing.
14
- # rubocop:disable Metrics/AbcSize
15
- def read
16
- @site.defaults_reader.read
17
- @site.layouts = LayoutReader.new(site).read
14
+ def read # rubocop:todo Metrics/AbcSize
15
+ site.defaults_reader.read
16
+ site.layouts = LayoutReader.new(site).read
18
17
  read_directories
19
18
  read_included_excludes
20
19
  sort_files!
21
- @site.data = DataReader.new(site).read(site.config["data_dir"])
22
- CollectionReader.new(site).read
20
+ read_collections
21
+ site.data = if site.uses_resource?
22
+ site.collections.data.merge_data_resources
23
+ else
24
+ DataReader.new(site).read
25
+ end
23
26
  Bridgetown::PluginManager.source_manifests.map(&:content).compact.each do |plugin_content_dir|
24
27
  PluginContentReader.new(site, plugin_content_dir).read
25
28
  end
26
29
  end
27
- # rubocop:enable Metrics/AbcSize
30
+
31
+ def read_collections
32
+ site.collections.each_value do |collection|
33
+ collection.read unless !site.uses_resource? &&
34
+ collection.legacy_reader?
35
+ end
36
+ end
28
37
 
29
38
  # Sorts posts, pages, and static files.
30
39
  def sort_files!
@@ -54,14 +63,14 @@ module Bridgetown
54
63
  file_path = @site.in_source_dir(base, entry)
55
64
  if File.directory?(file_path)
56
65
  dot_dirs << entry
57
- elsif Utils.has_yaml_header?(file_path)
66
+ elsif Utils.has_yaml_header?(file_path) || Utils.has_rbfm_header?(file_path)
58
67
  dot_pages << entry
59
68
  else
60
69
  dot_static_files << entry
61
70
  end
62
71
  end
63
72
 
64
- retrieve_posts(dir)
73
+ retrieve_posts(dir) unless site.uses_resource?
65
74
  retrieve_dirs(base, dir, dot_dirs)
66
75
  retrieve_pages(dir, dot_pages)
67
76
  retrieve_static_files(dir, dot_static_files)
@@ -102,6 +111,13 @@ module Bridgetown
102
111
  #
103
112
  # Returns nothing.
104
113
  def retrieve_pages(dir, dot_pages)
114
+ if site.uses_resource?
115
+ dot_pages.each do |page_path|
116
+ site.collections.pages.read_resource(site.in_source_dir(dir, page_path))
117
+ end
118
+ return
119
+ end
120
+
105
121
  site.pages.concat(PageReader.new(site, dir).read(dot_pages))
106
122
  end
107
123
 
@@ -126,7 +142,7 @@ module Bridgetown
126
142
  #
127
143
  # Returns the Array of filtered entries.
128
144
  def filter_entries(entries, base_directory = nil)
129
- EntryFilter.new(site, base_directory).filter(entries)
145
+ EntryFilter.new(site, base_directory: base_directory).filter(entries)
130
146
  end
131
147
 
132
148
  # Read the entries from a particular directory for processing
@@ -165,14 +181,11 @@ module Bridgetown
165
181
  end
166
182
 
167
183
  def read_included_excludes
168
- entry_filter = EntryFilter.new(site)
169
-
170
184
  site.include.each do |entry|
171
185
  next if entry == ".htaccess"
172
186
 
173
187
  entry_path = site.in_source_dir(entry)
174
188
  next if File.directory?(entry_path)
175
- next if entry_filter.symlink?(entry_path)
176
189
 
177
190
  read_included_file(entry_path) if File.file?(entry_path)
178
191
  end
@@ -16,8 +16,8 @@ module Bridgetown
16
16
  #
17
17
  # Returns @content, a Hash of the .yaml, .yml,
18
18
  # .json, and .csv files in the base directory
19
- def read(dir)
20
- base = site.in_source_dir(dir)
19
+ def read
20
+ base = site.in_source_dir(site.config.data_dir)
21
21
  read_data_to(base, @content)
22
22
  merge_environment_specific_metadata!
23
23
  @content = @content.with_dot_access
@@ -31,7 +31,7 @@ module Bridgetown
31
31
  #
32
32
  # Returns nothing
33
33
  def read_data_to(dir, data)
34
- return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
34
+ return unless File.directory?(dir)
35
35
 
36
36
  entries = Dir.chdir(dir) do
37
37
  Dir["*.{yaml,yml,json,csv,tsv}"] + Dir["*"].select { |fn| File.directory?(fn) }
@@ -39,7 +39,6 @@ module Bridgetown
39
39
 
40
40
  entries.each do |entry|
41
41
  path = @site.in_source_dir(dir, entry)
42
- next if @entry_filter.symlink?(path)
43
42
 
44
43
  if File.directory?(path)
45
44
  read_data_to(
@@ -98,7 +98,7 @@ module Bridgetown
98
98
  if item.is_a?(Document)
99
99
  site.posts.docs << item
100
100
  elsif item.is_a?(StaticFile)
101
- site.posts.files << item
101
+ site.posts.static_files << item
102
102
  site.static_files << item
103
103
  end
104
104
 
@@ -19,7 +19,7 @@ module Bridgetown
19
19
  # Checks if a renderable object needs to be regenerated
20
20
  #
21
21
  # Returns a boolean.
22
- def regenerate?(document)
22
+ def regenerate?(document) # rubocop:todo Metrics/CyclomaticComplexity
23
23
  return true if disabled
24
24
 
25
25
  case document
@@ -27,6 +27,8 @@ module Bridgetown
27
27
  regenerate_page?(document)
28
28
  when Document
29
29
  regenerate_document?(document)
30
+ when Bridgetown::Resource::Base
31
+ regenerate_resource?(document)
30
32
  else
31
33
  source_path = document.respond_to?(:path) ? document.path : nil
32
34
  dest_path = document.destination(@site.dest) if document.respond_to?(:destination)
@@ -176,6 +178,11 @@ module Bridgetown
176
178
  )
177
179
  end
178
180
 
181
+ # TODO: need to manage dependencies, but for now always regenerate
182
+ def regenerate_resource?(_resource)
183
+ true
184
+ end
185
+
179
186
  def existing_file_modified?(path)
180
187
  # If one of this file dependencies have been modified,
181
188
  # set the regeneration bit for both the dependency and the file to true