bridgetown-core 0.19.3 → 0.21.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +1 -2
- data/lib/bridgetown-core.rb +37 -29
- data/lib/bridgetown-core/cleaner.rb +9 -3
- data/lib/bridgetown-core/collection.rb +177 -78
- data/lib/bridgetown-core/commands/base.rb +9 -0
- data/lib/bridgetown-core/commands/build.rb +0 -11
- data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
- data/lib/bridgetown-core/commands/configure.rb +8 -3
- data/lib/bridgetown-core/commands/console.rb +4 -0
- data/lib/bridgetown-core/commands/doctor.rb +1 -19
- data/lib/bridgetown-core/commands/new.rb +6 -6
- data/lib/bridgetown-core/commands/plugins.rb +14 -13
- data/lib/bridgetown-core/commands/serve.rb +0 -14
- data/lib/bridgetown-core/commands/webpack.rb +75 -0
- data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
- data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
- data/lib/bridgetown-core/commands/webpack/update.rb +3 -0
- data/lib/bridgetown-core/commands/webpack/webpack.config.js +18 -0
- data/lib/{site_template/webpack.config.js.erb → bridgetown-core/commands/webpack/webpack.defaults.js.erb} +32 -16
- data/lib/bridgetown-core/component.rb +183 -0
- data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +10 -10
- data/lib/bridgetown-core/concerns/site/content.rb +56 -15
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
- data/lib/bridgetown-core/concerns/site/processable.rb +6 -4
- data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
- data/lib/bridgetown-core/concerns/validatable.rb +2 -5
- data/lib/bridgetown-core/configuration.rb +61 -33
- data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
- data/lib/bridgetown-core/configurations/netlify.rb +1 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +6 -6
- data/lib/bridgetown-core/converter.rb +23 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
- data/lib/bridgetown-core/converters/identity.rb +0 -9
- data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
- data/lib/bridgetown-core/converters/markdown.rb +14 -4
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +5 -38
- data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
- data/lib/bridgetown-core/converters/smartypants.rb +3 -1
- data/lib/bridgetown-core/core_ext/psych.rb +19 -0
- data/lib/bridgetown-core/current.rb +10 -0
- data/lib/bridgetown-core/document.rb +9 -16
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/page_drop.rb +4 -0
- data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
- data/lib/bridgetown-core/drops/site_drop.rb +33 -8
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
- data/lib/bridgetown-core/entry_filter.rb +17 -28
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters.rb +3 -26
- data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
- data/lib/bridgetown-core/filters/url_filters.rb +12 -0
- data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +59 -20
- data/lib/bridgetown-core/helpers.rb +48 -9
- data/lib/bridgetown-core/layout.rb +53 -21
- data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
- data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
- data/lib/bridgetown-core/model/base.rb +138 -0
- data/lib/bridgetown-core/model/builder_origin.rb +40 -0
- data/lib/bridgetown-core/model/origin.rb +38 -0
- data/lib/bridgetown-core/model/repo_origin.rb +126 -0
- data/lib/bridgetown-core/page.rb +11 -2
- data/lib/bridgetown-core/plugin_manager.rb +1 -3
- data/lib/bridgetown-core/publisher.rb +8 -2
- data/lib/bridgetown-core/reader.rb +37 -22
- data/lib/bridgetown-core/readers/data_reader.rb +5 -5
- data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
- data/lib/bridgetown-core/readers/page_reader.rb +1 -0
- data/lib/bridgetown-core/readers/post_reader.rb +5 -4
- data/lib/bridgetown-core/regenerator.rb +9 -2
- data/lib/bridgetown-core/related_posts.rb +9 -6
- data/lib/bridgetown-core/renderer.rb +6 -13
- data/lib/bridgetown-core/resource/base.rb +329 -0
- data/lib/bridgetown-core/resource/destination.rb +49 -0
- data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
- data/lib/bridgetown-core/resource/relations.rb +132 -0
- data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
- data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
- data/lib/bridgetown-core/resource/transformer.rb +177 -0
- data/lib/bridgetown-core/ruby_template_view.rb +11 -11
- data/lib/bridgetown-core/site.rb +13 -6
- data/lib/bridgetown-core/static_file.rb +33 -10
- data/lib/bridgetown-core/tags/highlight.rb +2 -15
- data/lib/bridgetown-core/tags/include.rb +1 -1
- data/lib/bridgetown-core/tags/post_url.rb +2 -2
- data/lib/bridgetown-core/url.rb +1 -0
- data/lib/bridgetown-core/utils.rb +49 -43
- data/lib/bridgetown-core/utils/require_gems.rb +60 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +2 -1
- data/lib/bridgetown-core/yaml_parser.rb +22 -0
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/package.json.erb +4 -4
- data/lib/site_template/plugins/site_builder.rb +1 -1
- data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
- metadata +46 -41
- data/lib/bridgetown-core/external.rb +0 -58
- data/lib/bridgetown-core/page_without_a_file.rb +0 -17
- data/lib/bridgetown-core/path_manager.rb +0 -31
- data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
- data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
- data/lib/bridgetown-core/utils/exec.rb +0 -26
- data/lib/bridgetown-core/utils/internet.rb +0 -37
- data/lib/bridgetown-core/utils/platforms.rb +0 -80
- data/lib/bridgetown-core/utils/thread_event.rb +0 -31
- data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -3,8 +3,8 @@
|
|
3
3
|
module Bridgetown
|
4
4
|
class Layout
|
5
5
|
include DataAccessible
|
6
|
+
include FrontMatterImporter
|
6
7
|
include LiquidRenderable
|
7
|
-
include Validatable
|
8
8
|
|
9
9
|
# Gets the Site object.
|
10
10
|
attr_reader :site
|
@@ -21,24 +21,40 @@ module Bridgetown
|
|
21
21
|
# Gets/Sets the extension of this layout.
|
22
22
|
attr_accessor :ext
|
23
23
|
|
24
|
+
alias_method :extname, :ext
|
25
|
+
|
24
26
|
# Gets/Sets the Hash that holds the metadata for this layout.
|
25
27
|
attr_accessor :data
|
26
28
|
|
27
29
|
# Gets/Sets the content of this layout.
|
30
|
+
# @return [String]
|
28
31
|
attr_accessor :content
|
29
32
|
|
33
|
+
# @return [Integer]
|
34
|
+
attr_accessor :front_matter_line_count
|
35
|
+
|
30
36
|
# Gets/Sets the current document (for layout-compatible converters)
|
31
37
|
attr_accessor :current_document
|
32
38
|
|
33
39
|
# Gets/Sets the document output (for layout-compatible converters)
|
34
40
|
attr_accessor :current_document_output
|
35
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
|
+
|
36
52
|
# Initialize a new Layout.
|
37
53
|
#
|
38
|
-
# site
|
39
|
-
# base
|
40
|
-
# name
|
41
|
-
# from_plugin
|
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.
|
42
58
|
def initialize(site, base, name, from_plugin: false)
|
43
59
|
@site = site
|
44
60
|
@base = base
|
@@ -52,33 +68,49 @@ module Bridgetown
|
|
52
68
|
@path = site.in_source_dir(base, name)
|
53
69
|
end
|
54
70
|
@relative_path = @path.sub(@base_dir, "")
|
71
|
+
@ext = File.extname(name)
|
72
|
+
|
73
|
+
@data = read_front_matter(@path)&.with_dot_access
|
74
|
+
rescue SyntaxError => e
|
75
|
+
Bridgetown.logger.error "Error:",
|
76
|
+
"Ruby Exception in #{e.message}"
|
77
|
+
rescue StandardError => e
|
78
|
+
handle_read_error(e)
|
79
|
+
ensure
|
80
|
+
@data ||= HashWithDotAccess::Hash.new
|
81
|
+
end
|
55
82
|
|
56
|
-
|
83
|
+
def handle_read_error(error)
|
84
|
+
if error.is_a? Psych::SyntaxError
|
85
|
+
Bridgetown.logger.warn "YAML Exception reading #{@path}: #{error.message}"
|
86
|
+
else
|
87
|
+
Bridgetown.logger.warn "Error reading file #{@path}: #{error.message}"
|
88
|
+
end
|
57
89
|
|
58
|
-
|
59
|
-
|
90
|
+
if site.config["strict_front_matter"] ||
|
91
|
+
error.is_a?(Bridgetown::Errors::FatalException)
|
92
|
+
raise error
|
93
|
+
end
|
60
94
|
end
|
61
95
|
|
62
|
-
# The
|
63
|
-
#
|
96
|
+
# The label of the layout (should match what would used in front matter
|
97
|
+
# references).
|
64
98
|
#
|
65
|
-
#
|
66
|
-
def
|
67
|
-
|
99
|
+
# @return [String]
|
100
|
+
def label
|
101
|
+
@label ||= self.class.label_for_file(name)
|
68
102
|
end
|
69
103
|
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# name - The String filename of the layout file.
|
104
|
+
# The inspect string for this layout. Includes the relative path.
|
73
105
|
#
|
74
|
-
#
|
75
|
-
def
|
76
|
-
self.
|
106
|
+
# @return [String]
|
107
|
+
def inspect
|
108
|
+
"#<#{self.class} #{relative_path}>"
|
77
109
|
end
|
78
110
|
|
79
|
-
# Provide this Layout's data
|
111
|
+
# Provide this Layout's data for use by Liquid.
|
80
112
|
#
|
81
|
-
#
|
113
|
+
# @return [HashWithDotAccess::Hash]
|
82
114
|
def to_liquid
|
83
115
|
data
|
84
116
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
|
5
|
+
module Bridgetown
|
6
|
+
module Model
|
7
|
+
class Base
|
8
|
+
include ActiveModel::Model
|
9
|
+
extend ActiveModel::Callbacks # also extends with DescendantsTracker
|
10
|
+
define_model_callbacks :load, :save, :destroy
|
11
|
+
|
12
|
+
def self.loads_id?(id)
|
13
|
+
name == ActiveSupport::Inflector.classify(
|
14
|
+
URI.parse(id).host.chomp(".collection")
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(id)
|
19
|
+
unless Bridgetown::Current.site
|
20
|
+
raise "A Bridgetown site must be initialized and added to Current"
|
21
|
+
end
|
22
|
+
|
23
|
+
model_klass = klass_for_id(id)
|
24
|
+
model_klass.new(read_data_for_id(id))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.klass_for_id(id)
|
28
|
+
descendants.find do |klass|
|
29
|
+
klass.loads_id?(id)
|
30
|
+
end || self
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.read_data_for_id(id)
|
34
|
+
origin_for_id(id).read
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.origin_for_id(id)
|
38
|
+
scheme = URI.parse(id).scheme
|
39
|
+
origin_klass = Origin.descendants.find do |klass|
|
40
|
+
klass.handle_scheme?(scheme)
|
41
|
+
end
|
42
|
+
|
43
|
+
raise "No origin could be found for #{id}" unless origin_klass
|
44
|
+
|
45
|
+
origin_klass.new(id)
|
46
|
+
end
|
47
|
+
|
48
|
+
class << self
|
49
|
+
def build(collection_name, path, data)
|
50
|
+
data = Bridgetown::Model::BuilderOrigin.new("builder://#{path}").read do
|
51
|
+
data[:_collection_] = Bridgetown::Current.site.collections[collection_name]
|
52
|
+
data
|
53
|
+
end
|
54
|
+
new(data)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize(attributes = {})
|
59
|
+
run_callbacks :load do
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def id
|
65
|
+
attributes[:id] || attributes[:_id_]
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [Bridgetown::Model::Origin]
|
69
|
+
def origin
|
70
|
+
attributes[:_origin_]
|
71
|
+
end
|
72
|
+
|
73
|
+
def persisted?
|
74
|
+
id && origin.exists?
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Bridgetown::Resource::Base]
|
78
|
+
def to_resource
|
79
|
+
Bridgetown::Resource::Base.new(model: self)
|
80
|
+
end
|
81
|
+
|
82
|
+
def as_resource_in_collection
|
83
|
+
collection.resources << to_resource.read!
|
84
|
+
collection.resources.last
|
85
|
+
end
|
86
|
+
|
87
|
+
# override if need be
|
88
|
+
# @return [Bridgetown::Site]
|
89
|
+
def site
|
90
|
+
Bridgetown::Current.site
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [Bridgetown::Collection]
|
94
|
+
def collection
|
95
|
+
attributes[:_collection_]
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [String]
|
99
|
+
def content
|
100
|
+
attributes[:_content_]
|
101
|
+
end
|
102
|
+
|
103
|
+
def attributes
|
104
|
+
@attributes ||= HashWithDotAccess::Hash.new
|
105
|
+
end
|
106
|
+
|
107
|
+
# Strip out keys like _origin_, _collection_, etc.
|
108
|
+
# @return [HashWithDotAccess::Hash]
|
109
|
+
def data_attributes
|
110
|
+
attributes.reject { |k| k.starts_with?("_") && k.ends_with?("_") }
|
111
|
+
end
|
112
|
+
|
113
|
+
def respond_to_missing?(method_name, include_private = false)
|
114
|
+
attributes.key?(method_name) || method_name.to_s.end_with?("=") || super
|
115
|
+
end
|
116
|
+
|
117
|
+
def method_missing(method_name, *args) # rubocop:disable Style/MethodMissingSuper
|
118
|
+
return attributes[method_name] if attributes.key?(method_name)
|
119
|
+
|
120
|
+
key = method_name.to_s
|
121
|
+
if key.end_with?("=")
|
122
|
+
key.chop!
|
123
|
+
# attribute_will_change!(key)
|
124
|
+
attributes[key] = args.first
|
125
|
+
return attributes[key]
|
126
|
+
end
|
127
|
+
|
128
|
+
Bridgetown.logger.warn "key `#{method_name}' not found in attributes for" \
|
129
|
+
" #{attributes[:id].presence || ("new " + self.class.to_s)}"
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def inspect
|
134
|
+
"#<#{self.class} #{data_attributes.inspect.delete_prefix("{").delete_suffix("}")}>"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -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 = YAMLParser.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
|