bridgetown-core 0.20.0 → 0.21.0
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.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +0 -1
- data/lib/bridgetown-core.rb +11 -22
- data/lib/bridgetown-core/cleaner.rb +2 -2
- data/lib/bridgetown-core/collection.rb +14 -11
- 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 +4 -3
- 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} +25 -11
- data/lib/bridgetown-core/component.rb +183 -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 +3 -7
- data/lib/bridgetown-core/concerns/site/content.rb +2 -3
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
- data/lib/bridgetown-core/concerns/site/processable.rb +5 -4
- data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
- data/lib/bridgetown-core/concerns/validatable.rb +1 -5
- data/lib/bridgetown-core/configuration.rb +22 -14
- 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 +9 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
- data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
- data/lib/bridgetown-core/converters/markdown.rb +1 -1
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +2 -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/document.rb +3 -2
- data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -1
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +1 -0
- data/lib/bridgetown-core/entry_filter.rb +7 -5
- data/lib/bridgetown-core/filters.rb +1 -25
- 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 +25 -4
- data/lib/bridgetown-core/helpers.rb +48 -9
- data/lib/bridgetown-core/layout.rb +52 -20
- data/lib/bridgetown-core/model/origin.rb +1 -1
- data/lib/bridgetown-core/model/{file_origin.rb → repo_origin.rb} +33 -26
- data/lib/bridgetown-core/page.rb +2 -1
- data/lib/bridgetown-core/plugin_manager.rb +1 -1
- data/lib/bridgetown-core/publisher.rb +2 -2
- data/lib/bridgetown-core/reader.rb +13 -11
- data/lib/bridgetown-core/readers/data_reader.rb +2 -1
- 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 +1 -1
- data/lib/bridgetown-core/related_posts.rb +8 -5
- data/lib/bridgetown-core/renderer.rb +1 -1
- data/lib/bridgetown-core/resource/base.rb +80 -26
- data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
- data/lib/bridgetown-core/resource/relations.rb +132 -0
- data/lib/bridgetown-core/resource/taxonomy_term.rb +10 -1
- data/lib/bridgetown-core/resource/taxonomy_type.rb +9 -0
- data/lib/bridgetown-core/resource/transformer.rb +18 -14
- data/lib/bridgetown-core/ruby_template_view.rb +7 -11
- data/lib/bridgetown-core/site.rb +4 -5
- 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/utils.rb +9 -3
- 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 +21 -23
- data/lib/bridgetown-core/external.rb +0 -58
- data/lib/bridgetown-core/path_manager.rb +0 -31
- data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
- data/lib/bridgetown-core/utils/platforms.rb +0 -81
- data/lib/bridgetown-core/utils/thread_event.rb +0 -31
|
@@ -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
|
|
@@ -27,20 +27,34 @@ module Bridgetown
|
|
|
27
27
|
attr_accessor :data
|
|
28
28
|
|
|
29
29
|
# Gets/Sets the content of this layout.
|
|
30
|
+
# @return [String]
|
|
30
31
|
attr_accessor :content
|
|
31
32
|
|
|
33
|
+
# @return [Integer]
|
|
34
|
+
attr_accessor :front_matter_line_count
|
|
35
|
+
|
|
32
36
|
# Gets/Sets the current document (for layout-compatible converters)
|
|
33
37
|
attr_accessor :current_document
|
|
34
38
|
|
|
35
39
|
# Gets/Sets the document output (for layout-compatible converters)
|
|
36
40
|
attr_accessor :current_document_output
|
|
37
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
|
+
|
|
38
52
|
# Initialize a new Layout.
|
|
39
53
|
#
|
|
40
|
-
# site
|
|
41
|
-
# base
|
|
42
|
-
# name
|
|
43
|
-
# 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.
|
|
44
58
|
def initialize(site, base, name, from_plugin: false)
|
|
45
59
|
@site = site
|
|
46
60
|
@base = base
|
|
@@ -54,31 +68,49 @@ module Bridgetown
|
|
|
54
68
|
@path = site.in_source_dir(base, name)
|
|
55
69
|
end
|
|
56
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
|
|
82
|
+
|
|
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
|
|
@@ -2,29 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
4
|
module Model
|
|
5
|
-
class
|
|
5
|
+
class RepoOrigin < Origin
|
|
6
|
+
include Bridgetown::FrontMatterImporter
|
|
7
|
+
include Bridgetown::Utils::RubyFrontMatterDSL
|
|
8
|
+
|
|
6
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
|
|
7
19
|
|
|
8
20
|
class << self
|
|
9
21
|
def handle_scheme?(scheme)
|
|
10
|
-
scheme == "
|
|
22
|
+
scheme == "repo"
|
|
11
23
|
end
|
|
12
24
|
|
|
13
25
|
def data_file_extensions
|
|
14
|
-
%w(.yaml .yml .json .csv .tsv).freeze
|
|
26
|
+
%w(.yaml .yml .json .csv .tsv .rb).freeze
|
|
15
27
|
end
|
|
16
28
|
end
|
|
17
29
|
|
|
18
30
|
def read
|
|
19
|
-
|
|
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 ||= {}
|
|
20
41
|
@data[:_id_] = id
|
|
21
42
|
@data[:_origin_] = self
|
|
22
43
|
@data[:_collection_] = collection
|
|
23
|
-
@data[:_content_] =
|
|
44
|
+
@data[:_content_] = content if content
|
|
24
45
|
|
|
25
46
|
@data
|
|
26
|
-
rescue StandardError => e
|
|
27
|
-
handle_read_error(e)
|
|
28
47
|
end
|
|
29
48
|
|
|
30
49
|
def url
|
|
@@ -63,40 +82,28 @@ module Bridgetown
|
|
|
63
82
|
collection.data?
|
|
64
83
|
end
|
|
65
84
|
|
|
66
|
-
def read_file_data
|
|
85
|
+
def read_file_data # rubocop:todo Metrics/MethodLength
|
|
67
86
|
case original_path.extname.downcase
|
|
68
87
|
when ".csv"
|
|
69
88
|
{
|
|
70
|
-
|
|
89
|
+
rows:
|
|
71
90
|
CSV.read(original_path,
|
|
72
91
|
headers: true,
|
|
73
92
|
encoding: Bridgetown::Current.site.config["encoding"]).map(&:to_hash),
|
|
74
93
|
}
|
|
75
94
|
when ".tsv"
|
|
76
95
|
{
|
|
77
|
-
|
|
96
|
+
rows:
|
|
78
97
|
CSV.read(original_path,
|
|
79
98
|
col_sep: "\t",
|
|
80
99
|
headers: true,
|
|
81
100
|
encoding: Bridgetown::Current.site.config["encoding"]).map(&:to_hash),
|
|
82
101
|
}
|
|
102
|
+
when ".rb"
|
|
103
|
+
process_ruby_data(File.read(original_path), original_path, 1)
|
|
83
104
|
else
|
|
84
|
-
yaml_data =
|
|
85
|
-
yaml_data.is_a?(Array) ? {
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def read_frontmatter
|
|
90
|
-
@content = File.read(
|
|
91
|
-
original_path, **Bridgetown::Utils.merged_file_read_opts(Bridgetown::Current.site, {})
|
|
92
|
-
)
|
|
93
|
-
content_match = @content.match(YAML_FRONT_MATTER_REGEXP)
|
|
94
|
-
if content_match
|
|
95
|
-
@content = content_match.post_match
|
|
96
|
-
SafeYAML.load(content_match[1])
|
|
97
|
-
else
|
|
98
|
-
yaml_data = SafeYAML.load_file(original_path)
|
|
99
|
-
yaml_data.is_a?(Array) ? { array: yaml_data } : yaml_data
|
|
105
|
+
yaml_data = YAMLParser.load_file(original_path)
|
|
106
|
+
yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data
|
|
100
107
|
end
|
|
101
108
|
end
|
|
102
109
|
|
data/lib/bridgetown-core/page.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
|
4
5
|
class Page
|
|
5
6
|
include DataAccessible
|
|
6
7
|
include LayoutPlaceable
|
|
@@ -44,7 +45,7 @@ module Bridgetown
|
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
process(name)
|
|
47
|
-
read_yaml(
|
|
48
|
+
read_yaml(File.join(base, dir), name)
|
|
48
49
|
|
|
49
50
|
data.default_proc = proc do |_, key|
|
|
50
51
|
site.frontmatter_defaults.find(relative_path, type, key.to_s)
|
|
@@ -133,7 +133,7 @@ module Bridgetown
|
|
|
133
133
|
sorted_plugin_files.each do |plugin_file|
|
|
134
134
|
self.class.add_registered_plugin plugin_file
|
|
135
135
|
end
|
|
136
|
-
Bridgetown::
|
|
136
|
+
Bridgetown::Utils::RequireGems.require_with_graceful_fail(sorted_plugin_files)
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -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
|
|
@@ -63,7 +63,7 @@ module Bridgetown
|
|
|
63
63
|
file_path = @site.in_source_dir(base, entry)
|
|
64
64
|
if File.directory?(file_path)
|
|
65
65
|
dot_dirs << entry
|
|
66
|
-
elsif Utils.has_yaml_header?(file_path)
|
|
66
|
+
elsif Utils.has_yaml_header?(file_path) || Utils.has_rbfm_header?(file_path)
|
|
67
67
|
dot_pages << entry
|
|
68
68
|
else
|
|
69
69
|
dot_static_files << entry
|
|
@@ -98,7 +98,7 @@ module Bridgetown
|
|
|
98
98
|
def retrieve_dirs(_base, dir, dot_dirs)
|
|
99
99
|
dot_dirs.each do |file|
|
|
100
100
|
dir_path = site.in_source_dir(dir, file)
|
|
101
|
-
rel_path =
|
|
101
|
+
rel_path = File.join(dir, file)
|
|
102
102
|
@site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path
|
|
103
103
|
end
|
|
104
104
|
end
|
|
@@ -113,7 +113,7 @@ module Bridgetown
|
|
|
113
113
|
def retrieve_pages(dir, dot_pages)
|
|
114
114
|
if site.uses_resource?
|
|
115
115
|
dot_pages.each do |page_path|
|
|
116
|
-
site.collections.pages.
|
|
116
|
+
site.collections.pages.read_resource(site.in_source_dir(dir, page_path))
|
|
117
117
|
end
|
|
118
118
|
return
|
|
119
119
|
end
|
|
@@ -124,12 +124,14 @@ module Bridgetown
|
|
|
124
124
|
# Retrieve all the static files from the current directory,
|
|
125
125
|
# add them to the site and sort them.
|
|
126
126
|
#
|
|
127
|
-
# dir
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
# @param dir [String] The directory retrieve the static files from.
|
|
128
|
+
# @param files [Array<String>] The static files in the dir.
|
|
129
|
+
def retrieve_static_files(dir, files)
|
|
130
|
+
site.static_files.concat(
|
|
131
|
+
files.map do |file|
|
|
132
|
+
StaticFile.new(site, site.source, dir, file)
|
|
133
|
+
end
|
|
134
|
+
)
|
|
133
135
|
end
|
|
134
136
|
|
|
135
137
|
# Filter out any files/directories that are hidden or backup files (start
|
|
@@ -181,7 +183,7 @@ module Bridgetown
|
|
|
181
183
|
end
|
|
182
184
|
|
|
183
185
|
def read_included_excludes
|
|
184
|
-
site.include.each do |entry|
|
|
186
|
+
site.config.include.each do |entry|
|
|
185
187
|
next if entry == ".htaccess"
|
|
186
188
|
|
|
187
189
|
entry_path = site.in_source_dir(entry)
|
|
@@ -197,7 +199,7 @@ module Bridgetown
|
|
|
197
199
|
if Utils.has_yaml_header?(entry_path)
|
|
198
200
|
site.pages.concat(PageReader.new(site, dir).read(file))
|
|
199
201
|
else
|
|
200
|
-
|
|
202
|
+
retrieve_static_files(dir, file)
|
|
201
203
|
end
|
|
202
204
|
end
|
|
203
205
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
|
4
5
|
class DataReader
|
|
5
6
|
attr_reader :site, :content
|
|
6
7
|
|
|
@@ -67,7 +68,7 @@ module Bridgetown
|
|
|
67
68
|
headers: true,
|
|
68
69
|
encoding: site.config["encoding"]).map(&:to_hash)
|
|
69
70
|
else
|
|
70
|
-
|
|
71
|
+
YAMLParser.load_file(path)
|
|
71
72
|
end
|
|
72
73
|
end
|
|
73
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] =
|
|
21
|
+
@path_defaults[File.dirname(path) + File::SEPARATOR] = YAMLParser.load_file(path)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
@path_defaults
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
|
4
5
|
class PostReader
|
|
5
6
|
attr_reader :site, :unfiltered_content
|
|
6
7
|
|
|
@@ -47,7 +48,7 @@ module Bridgetown
|
|
|
47
48
|
# Process as Document
|
|
48
49
|
Document.new(path,
|
|
49
50
|
site: @site,
|
|
50
|
-
collection: @site.posts)
|
|
51
|
+
collection: @site.collections.posts)
|
|
51
52
|
else
|
|
52
53
|
# Process as Static File
|
|
53
54
|
read_static_file(
|
|
@@ -66,7 +67,7 @@ module Bridgetown
|
|
|
66
67
|
site.source,
|
|
67
68
|
relative_dir,
|
|
68
69
|
File.basename(full_path),
|
|
69
|
-
@site.posts
|
|
70
|
+
@site.collections.posts
|
|
70
71
|
)
|
|
71
72
|
end
|
|
72
73
|
|
|
@@ -96,9 +97,9 @@ module Bridgetown
|
|
|
96
97
|
return false unless processable?(item)
|
|
97
98
|
|
|
98
99
|
if item.is_a?(Document)
|
|
99
|
-
site.posts.docs << item
|
|
100
|
+
site.collections.posts.docs << item
|
|
100
101
|
elsif item.is_a?(StaticFile)
|
|
101
|
-
site.posts.static_files << item
|
|
102
|
+
site.collections.posts.static_files << item
|
|
102
103
|
site.static_files << item
|
|
103
104
|
end
|
|
104
105
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Bridgetown
|
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
|
4
5
|
class RelatedPosts
|
|
5
6
|
class << self
|
|
6
7
|
attr_accessor :lsi
|
|
@@ -11,13 +12,15 @@ module Bridgetown
|
|
|
11
12
|
def initialize(post)
|
|
12
13
|
@post = post
|
|
13
14
|
@site = post.site
|
|
14
|
-
|
|
15
|
+
if site.config.lsi
|
|
16
|
+
Bridgetown::Utils::RequireGems.require_with_graceful_fail("classifier-reborn")
|
|
17
|
+
end
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
def build
|
|
18
|
-
return [] unless site.posts.docs.size > 1
|
|
21
|
+
return [] unless site.collections.posts.docs.size > 1
|
|
19
22
|
|
|
20
|
-
if site.lsi
|
|
23
|
+
if site.config.lsi
|
|
21
24
|
build_index
|
|
22
25
|
lsi_related_posts
|
|
23
26
|
else
|
|
@@ -30,7 +33,7 @@ module Bridgetown
|
|
|
30
33
|
lsi = ClassifierReborn::LSI.new(auto_rebuild: false)
|
|
31
34
|
Bridgetown.logger.info("Populating LSI...")
|
|
32
35
|
|
|
33
|
-
site.posts.docs.each do |x|
|
|
36
|
+
site.collections.posts.docs.each do |x|
|
|
34
37
|
lsi.add_item(x)
|
|
35
38
|
end
|
|
36
39
|
|
|
@@ -46,7 +49,7 @@ module Bridgetown
|
|
|
46
49
|
end
|
|
47
50
|
|
|
48
51
|
def most_recent_posts
|
|
49
|
-
@most_recent_posts ||= (site.posts.docs.last(11).reverse - [post]).first(10)
|
|
52
|
+
@most_recent_posts ||= (site.collections.posts.docs.last(11).reverse - [post]).first(10)
|
|
50
53
|
end
|
|
51
54
|
end
|
|
52
55
|
end
|