bridgetown-core 0.21.2 → 1.0.0.alpha2
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/.rubocop.yml +35 -0
- data/Rakefile +5 -5
- data/bin/bridgetown +2 -0
- data/bridgetown-core.gemspec +3 -0
- data/lib/bridgetown-core/cache.rb +3 -5
- data/lib/bridgetown-core/cleaner.rb +2 -10
- data/lib/bridgetown-core/collection.rb +62 -86
- data/lib/bridgetown-core/commands/base.rb +62 -2
- data/lib/bridgetown-core/commands/build.rb +33 -12
- data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
- data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
- data/lib/bridgetown-core/commands/console.rb +3 -3
- data/lib/bridgetown-core/commands/doctor.rb +13 -11
- data/lib/bridgetown-core/commands/new.rb +14 -6
- data/lib/bridgetown-core/commands/plugins.rb +8 -11
- data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
- data/lib/bridgetown-core/commands/serve.rb +37 -37
- data/lib/bridgetown-core/commands/start.rb +106 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
- data/lib/bridgetown-core/commands/webpack.rb +1 -1
- data/lib/bridgetown-core/component.rb +1 -5
- data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
- data/lib/bridgetown-core/concerns/site/content.rb +17 -118
- data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
- data/lib/bridgetown-core/concerns/site/processable.rb +9 -20
- data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
- data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
- data/lib/bridgetown-core/configuration.rb +19 -48
- data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
- data/lib/bridgetown-core/configurations/turbo.rb +1 -1
- data/lib/bridgetown-core/converter.rb +1 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +3 -2
- data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/smartypants.rb +1 -0
- data/lib/bridgetown-core/current.rb +4 -0
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/drop.rb +4 -4
- data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
- data/lib/bridgetown-core/drops/site_drop.rb +3 -47
- data/lib/bridgetown-core/entry_filter.rb +1 -0
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters/url_filters.rb +2 -0
- data/lib/bridgetown-core/filters.rb +11 -12
- data/lib/bridgetown-core/frontmatter_defaults.rb +52 -90
- data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
- data/lib/bridgetown-core/generators/prototype_generator.rb +49 -61
- data/lib/bridgetown-core/helpers.rb +8 -3
- data/lib/bridgetown-core/hooks.rb +2 -2
- data/lib/bridgetown-core/layout.rb +15 -4
- data/lib/bridgetown-core/liquid_renderer.rb +1 -3
- data/lib/bridgetown-core/log_adapter.rb +1 -1
- data/lib/bridgetown-core/log_writer.rb +7 -1
- data/lib/bridgetown-core/model/base.rb +12 -4
- data/lib/bridgetown-core/model/builder_origin.rb +23 -11
- data/lib/bridgetown-core/model/origin.rb +3 -0
- data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +10 -10
- data/lib/bridgetown-core/publisher.rb +1 -1
- data/lib/bridgetown-core/rack/boot.rb +47 -0
- data/lib/bridgetown-core/rack/logger.rb +22 -0
- data/lib/bridgetown-core/rack/roda.rb +66 -0
- data/lib/bridgetown-core/rack/routes.rb +88 -0
- data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
- data/lib/bridgetown-core/reader.rb +20 -47
- data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
- data/lib/bridgetown-core/renderer.rb +2 -12
- data/lib/bridgetown-core/resource/base.rb +51 -27
- data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
- data/lib/bridgetown-core/resource/relations.rb +2 -3
- data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
- data/lib/bridgetown-core/resource/transformer.rb +8 -6
- data/lib/bridgetown-core/ruby_template_view.rb +6 -8
- data/lib/bridgetown-core/site.rb +4 -8
- data/lib/bridgetown-core/static_file.rb +14 -21
- data/lib/bridgetown-core/tags/find.rb +6 -6
- data/lib/bridgetown-core/tags/highlight.rb +5 -5
- data/lib/bridgetown-core/tags/include.rb +22 -32
- data/lib/bridgetown-core/tags/link.rb +4 -0
- data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
- data/lib/bridgetown-core/tags/post_url.rb +9 -14
- data/lib/bridgetown-core/tags/render_content.rb +2 -2
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
- data/lib/bridgetown-core/url.rb +5 -4
- data/lib/bridgetown-core/utils/aux.rb +57 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
- data/lib/bridgetown-core/utils.rb +60 -33
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +4 -6
- data/lib/bridgetown-core.rb +16 -23
- data/lib/site_template/Gemfile.erb +6 -2
- data/lib/site_template/README.md +6 -6
- data/lib/site_template/Rakefile +49 -0
- data/lib/site_template/bridgetown.config.yml +2 -3
- data/lib/site_template/config/puma.rb +27 -0
- data/lib/site_template/config.ru +7 -0
- data/lib/site_template/frontend/javascript/index.js.erb +3 -3
- data/lib/site_template/package.json.erb +7 -12
- data/lib/site_template/server/roda_app.rb +22 -0
- data/lib/site_template/server/routes/hello.rb.sample +10 -0
- data/lib/site_template/src/_components/head.liquid +2 -1
- data/lib/site_template/src/about.md +0 -1
- data/lib/site_template/src/posts.md +2 -3
- metadata +63 -18
- data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
- data/lib/bridgetown-core/concerns/validatable.rb +0 -56
- data/lib/bridgetown-core/document.rb +0 -437
- data/lib/bridgetown-core/drops/document_drop.rb +0 -80
- data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
- data/lib/bridgetown-core/drops/page_drop.rb +0 -18
- data/lib/bridgetown-core/excerpt.rb +0 -200
- data/lib/bridgetown-core/readers/data_reader.rb +0 -89
- data/lib/bridgetown-core/readers/page_reader.rb +0 -26
- data/lib/bridgetown-core/readers/post_reader.rb +0 -109
- data/lib/bridgetown-core/regenerator.rb +0 -202
- data/lib/bridgetown-core/related_posts.rb +0 -55
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/start.js +0 -17
- data/lib/site_template/sync.js +0 -35
|
@@ -3,38 +3,10 @@
|
|
|
3
3
|
class Bridgetown::Site
|
|
4
4
|
# Content is king!
|
|
5
5
|
module Content
|
|
6
|
-
# Construct a Hash of Posts indexed by the specified Post attribute.
|
|
7
|
-
#
|
|
8
|
-
# Returns a hash like so: `{ attr => posts }` where:
|
|
9
|
-
#
|
|
10
|
-
# * `attr` - One of the values for the requested attribute.
|
|
11
|
-
# * `posts` - The array of Posts with the given attr value.
|
|
12
|
-
#
|
|
13
|
-
# @param post_attr [String] The String name of the Post attribute.
|
|
14
|
-
#
|
|
15
|
-
# @example
|
|
16
|
-
# post_attr_hash('categories')
|
|
17
|
-
# # => { 'tech' => [<Post A>, <Post B>],
|
|
18
|
-
# # 'ruby' => [<Post B>] }
|
|
19
|
-
#
|
|
20
|
-
# @return [Hash{String, Symbol => Array<Post>}]
|
|
21
|
-
# Returns a hash of !{attr => posts}
|
|
22
|
-
def post_attr_hash(post_attr)
|
|
23
|
-
# Build a hash map based on the specified post attribute ( post attr =>
|
|
24
|
-
# array of posts ) then sort each array in reverse order.
|
|
25
|
-
@post_attr_hash[post_attr] ||= begin
|
|
26
|
-
hash = Hash.new { |h, key| h[key] = [] }
|
|
27
|
-
posts.docs.each do |p|
|
|
28
|
-
p.data[post_attr]&.each { |t| hash[t] << p }
|
|
29
|
-
end
|
|
30
|
-
hash.each_value { |posts| posts.sort!.reverse! }
|
|
31
|
-
hash
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
6
|
def resources_grouped_by_taxonomy(taxonomy)
|
|
36
|
-
|
|
37
|
-
|
|
7
|
+
data.site_taxonomies_hash ||= {}
|
|
8
|
+
data.site_taxonomies_hash[taxonomy.label] ||= taxonomy.terms.transform_values do |terms|
|
|
9
|
+
terms.map(&:resource).sort.reverse
|
|
38
10
|
end
|
|
39
11
|
end
|
|
40
12
|
|
|
@@ -44,29 +16,12 @@ class Bridgetown::Site
|
|
|
44
16
|
end
|
|
45
17
|
end
|
|
46
18
|
|
|
47
|
-
# Returns a hash of "tags" using {#post_attr_hash} where each tag is a key
|
|
48
|
-
# and each value is a post which contains the key.
|
|
49
|
-
# @example
|
|
50
|
-
# tags
|
|
51
|
-
# # => { 'tech': [<Post A>, <Post B>],
|
|
52
|
-
# # 'ruby': [<Post C> }
|
|
53
|
-
# @return [Hash{String, Array<Post>}] Returns a hash of all tags and their corresponding posts
|
|
54
|
-
# @see post_attr_hash
|
|
55
19
|
def tags
|
|
56
|
-
|
|
20
|
+
taxonomies.tag
|
|
57
21
|
end
|
|
58
22
|
|
|
59
|
-
# Returns a hash of "categories" using {#post_attr_hash} where each tag is
|
|
60
|
-
# a key and each value is a post which contains the key.
|
|
61
|
-
# @example
|
|
62
|
-
# categories
|
|
63
|
-
# # => { 'tech': [<Post A>, <Post B>],
|
|
64
|
-
# # 'ruby': [<Post C> }
|
|
65
|
-
# @return [Hash{String, Array<Post>}] Returns a hash of all categories and
|
|
66
|
-
# their corresponding posts
|
|
67
|
-
# @see post_attr_hash
|
|
68
23
|
def categories
|
|
69
|
-
|
|
24
|
+
taxonomies.category
|
|
70
25
|
end
|
|
71
26
|
|
|
72
27
|
# Returns the value of `data["site_metadata"]` or creates a new instance of
|
|
@@ -78,34 +33,7 @@ class Bridgetown::Site
|
|
|
78
33
|
|
|
79
34
|
# The Hash payload containing site-wide data.
|
|
80
35
|
#
|
|
81
|
-
# @example
|
|
82
|
-
# site_payload
|
|
83
|
-
# # => { "site" => data } Where data is a Hash. See example below
|
|
84
|
-
#
|
|
85
|
-
# site = site_payload["site"]
|
|
86
|
-
# # => Returns a Hash with the following keys:
|
|
87
|
-
# #
|
|
88
|
-
# # site["time"] - The Time as specified in the configuration or the
|
|
89
|
-
# # current time if none was specified.
|
|
90
|
-
# #
|
|
91
|
-
# # site["posts"] - The Array of Posts, sorted chronologically by post date
|
|
92
|
-
# # and then title.
|
|
93
|
-
# #
|
|
94
|
-
# # site["pages"] - The Array of all Pages.
|
|
95
|
-
# #
|
|
96
|
-
# # site["html_pages"] - The Array of HTML Pages.
|
|
97
|
-
# #
|
|
98
|
-
# # site["categories"] - The Hash of category values and Posts.
|
|
99
|
-
# # See Site#post_attr_hash for type info.
|
|
100
|
-
# #
|
|
101
|
-
# # site["tags"] - The Hash of tag values and Posts.
|
|
102
|
-
# # See Site#post_attr_hash for type info.
|
|
103
|
-
#
|
|
104
36
|
# @return [Hash] Returns a hash in the structure of { "site" => data }
|
|
105
|
-
#
|
|
106
|
-
# See above example for usage.
|
|
107
|
-
#
|
|
108
|
-
# @see #post_attr_hash
|
|
109
37
|
def site_payload
|
|
110
38
|
Bridgetown::Drops::UnifiedPayloadDrop.new self
|
|
111
39
|
end
|
|
@@ -154,25 +82,6 @@ class Bridgetown::Site
|
|
|
154
82
|
end.to_h.with_dot_access
|
|
155
83
|
end
|
|
156
84
|
|
|
157
|
-
# Get all documents.
|
|
158
|
-
# @return [Array<Document>] an array of documents from the
|
|
159
|
-
# configuration
|
|
160
|
-
def documents
|
|
161
|
-
collections.each_with_object(Set.new) do |(_, collection), set|
|
|
162
|
-
set.merge(collection.docs)
|
|
163
|
-
end.to_a
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
# Get the documents to be written
|
|
167
|
-
#
|
|
168
|
-
# @return [Array<Document>] an array of documents which should be
|
|
169
|
-
# written and that `respond_to :write?`
|
|
170
|
-
# @see #documents
|
|
171
|
-
# @see Collection
|
|
172
|
-
def docs_to_write
|
|
173
|
-
documents.select(&:write?)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
85
|
# Get all loaded resources.
|
|
177
86
|
# @return [Array<Bridgetown::Resource::Base>] an array of resources
|
|
178
87
|
def resources
|
|
@@ -181,23 +90,12 @@ class Bridgetown::Site
|
|
|
181
90
|
end.to_a
|
|
182
91
|
end
|
|
183
92
|
|
|
93
|
+
alias_method :contents, :resources
|
|
94
|
+
|
|
184
95
|
def resources_to_write
|
|
185
96
|
resources.select(&:write?)
|
|
186
97
|
end
|
|
187
98
|
|
|
188
|
-
# Get all posts. Deprecated, to be removed in v1.0.
|
|
189
|
-
#
|
|
190
|
-
# @return [Collection] Returns {#collections}`["posts"]`, creating it if need be
|
|
191
|
-
# @see Collection
|
|
192
|
-
def posts
|
|
193
|
-
unless @wrote_deprecation_msg
|
|
194
|
-
Bridgetown::Deprecator.deprecation_message "Call site.collections.posts " \
|
|
195
|
-
"instead of site.posts (Ruby code)"
|
|
196
|
-
end
|
|
197
|
-
@wrote_deprecation_msg ||= true
|
|
198
|
-
collections["posts"] ||= Bridgetown::Collection.new(self, "posts")
|
|
199
|
-
end
|
|
200
|
-
|
|
201
99
|
# Get the static files to be written
|
|
202
100
|
#
|
|
203
101
|
# @return [Array<StaticFile>] an array of files which should be
|
|
@@ -208,17 +106,18 @@ class Bridgetown::Site
|
|
|
208
106
|
static_files.select(&:write?)
|
|
209
107
|
end
|
|
210
108
|
|
|
211
|
-
# Get all pages and documents (posts and collection items) in a single array.
|
|
212
|
-
#
|
|
213
|
-
# @return [Array]
|
|
214
|
-
def contents
|
|
215
|
-
return resources if uses_resource?
|
|
216
|
-
|
|
217
|
-
pages + documents
|
|
218
|
-
end
|
|
219
|
-
|
|
220
109
|
def add_generated_page(generated_page)
|
|
221
110
|
generated_pages << generated_page
|
|
222
111
|
end
|
|
112
|
+
|
|
113
|
+
# Loads and memoizes the parsed Webpack manifest file (if available)
|
|
114
|
+
# @return [Hash]
|
|
115
|
+
def frontend_manifest
|
|
116
|
+
@frontend_manifest ||= begin
|
|
117
|
+
manifest_file = in_root_dir(".bridgetown-webpack", "manifest.json")
|
|
118
|
+
|
|
119
|
+
JSON.parse(File.read(manifest_file)) if File.exist?(manifest_file)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
223
122
|
end
|
|
224
123
|
end
|
|
@@ -40,10 +40,9 @@ class Bridgetown::Site
|
|
|
40
40
|
# instance implementing the given `Converter` class.
|
|
41
41
|
def find_converter_instance(klass)
|
|
42
42
|
@find_converter_instance ||= {}
|
|
43
|
-
@find_converter_instance[klass] ||=
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
end
|
|
43
|
+
@find_converter_instance[klass] ||= converters.find do |converter|
|
|
44
|
+
converter.instance_of?(klass)
|
|
45
|
+
end || raise("No Converters found for #{klass}")
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
# Create an array of instances of the subclasses of the class
|
|
@@ -7,7 +7,9 @@ class Bridgetown::Site
|
|
|
7
7
|
def locale
|
|
8
8
|
@locale ||= begin
|
|
9
9
|
locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
|
|
10
|
-
|
|
10
|
+
Dir["#{in_source_dir("_locales")}/*.yml"].each do |locale_path|
|
|
11
|
+
I18n.load_path << locale_path
|
|
12
|
+
end
|
|
11
13
|
I18n.available_locales = config[:available_locales]
|
|
12
14
|
I18n.default_locale = locale
|
|
13
15
|
end
|
|
@@ -22,8 +22,10 @@ class Bridgetown::Site
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# Reset all in-memory data and content.
|
|
25
|
+
#
|
|
26
|
+
|
|
25
27
|
# @return [void]
|
|
26
|
-
def reset
|
|
28
|
+
def reset(soft: false)
|
|
27
29
|
self.time = Time.now
|
|
28
30
|
if config["time"]
|
|
29
31
|
self.time = Bridgetown::Utils.parse_date(
|
|
@@ -31,19 +33,18 @@ class Bridgetown::Site
|
|
|
31
33
|
)
|
|
32
34
|
end
|
|
33
35
|
self.layouts = HashWithDotAccess::Hash.new
|
|
34
|
-
self.
|
|
36
|
+
self.generated_pages = []
|
|
35
37
|
self.static_files = []
|
|
36
|
-
self.data = HashWithDotAccess::Hash.new
|
|
37
|
-
@
|
|
38
|
+
self.data = HashWithDotAccess::Hash.new unless soft
|
|
39
|
+
@frontend_manifest = nil
|
|
38
40
|
@collections = nil
|
|
39
41
|
@documents = nil
|
|
40
42
|
@docs_to_write = nil
|
|
41
|
-
@regenerator.clear_cache
|
|
42
43
|
@liquid_renderer.reset
|
|
43
|
-
frontmatter_defaults.reset
|
|
44
|
+
frontmatter_defaults.reset unless soft
|
|
44
45
|
|
|
45
|
-
Bridgetown::Cache.clear_if_config_changed config
|
|
46
|
-
Bridgetown::Hooks.trigger :site, :after_reset, self
|
|
46
|
+
Bridgetown::Cache.clear_if_config_changed config unless soft
|
|
47
|
+
Bridgetown::Hooks.trigger :site, (soft ? :after_soft_reset : :after_reset), self
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
# Read data from disk and load it into internal memory.
|
|
@@ -51,23 +52,11 @@ class Bridgetown::Site
|
|
|
51
52
|
def read
|
|
52
53
|
Bridgetown::Hooks.trigger :site, :pre_read, self
|
|
53
54
|
reader.read
|
|
54
|
-
limit_posts!
|
|
55
55
|
Bridgetown::Hooks.trigger :site, :post_read, self
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
private
|
|
59
59
|
|
|
60
|
-
# Limits the current posts; removes the posts which exceed the limit_posts
|
|
61
|
-
def limit_posts!
|
|
62
|
-
if config.limit_posts.positive?
|
|
63
|
-
Bridgetown::Deprecator.deprecation_message(
|
|
64
|
-
"The limit_posts config option will be removed prior to Bridgetown 1.0"
|
|
65
|
-
)
|
|
66
|
-
limit = posts.docs.length < config.limit_posts ? posts.docs.length : config.limit_posts
|
|
67
|
-
posts.docs = posts.docs[-limit, limit]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
60
|
def print_stats
|
|
72
61
|
Bridgetown.logger.info @liquid_renderer.stats_table
|
|
73
62
|
end
|
|
@@ -9,23 +9,20 @@ class Bridgetown::Site
|
|
|
9
9
|
def render
|
|
10
10
|
Bridgetown::Hooks.trigger :site, :pre_render, self
|
|
11
11
|
execute_inline_ruby_for_layouts!
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
render_resources
|
|
13
|
+
render_generated_pages
|
|
14
14
|
Bridgetown::Hooks.trigger :site, :post_render, self
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# Executes
|
|
17
|
+
# Executes procs in Ruby frontmatter
|
|
18
18
|
#
|
|
19
|
-
# @example
|
|
20
|
-
# calculation: !ruby/string:Rb |
|
|
21
|
-
# [2 * 4, 5 + 2].min
|
|
22
19
|
# @return [void]
|
|
23
20
|
# @see https://www.bridgetownrb.com/docs/front-matter#ruby-front-matter
|
|
24
21
|
def execute_inline_ruby_for_layouts!
|
|
25
22
|
return unless config.should_execute_inline_ruby?
|
|
26
23
|
|
|
27
24
|
layouts.each_value do |layout|
|
|
28
|
-
Bridgetown::Utils::RubyExec.search_data_for_ruby_code(layout
|
|
25
|
+
Bridgetown::Utils::RubyExec.search_data_for_ruby_code(layout)
|
|
29
26
|
end
|
|
30
27
|
end
|
|
31
28
|
|
|
@@ -49,16 +46,10 @@ class Bridgetown::Site
|
|
|
49
46
|
matches
|
|
50
47
|
end
|
|
51
48
|
|
|
52
|
-
# Renders all
|
|
49
|
+
# Renders all resources
|
|
53
50
|
# @return [void]
|
|
54
|
-
def
|
|
51
|
+
def render_resources
|
|
55
52
|
collections.each_value do |collection|
|
|
56
|
-
collection.docs.each do |document|
|
|
57
|
-
render_with_locale(document) do
|
|
58
|
-
render_regenerated document
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
53
|
collection.resources.each do |resource|
|
|
63
54
|
render_with_locale(resource) do
|
|
64
55
|
resource.transform!
|
|
@@ -67,22 +58,22 @@ class Bridgetown::Site
|
|
|
67
58
|
end
|
|
68
59
|
end
|
|
69
60
|
|
|
70
|
-
# Renders all pages
|
|
61
|
+
# Renders all generated pages
|
|
71
62
|
# @return [void]
|
|
72
|
-
def
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
def render_generated_pages
|
|
64
|
+
generated_pages.each do |page|
|
|
65
|
+
render_page page
|
|
75
66
|
end
|
|
76
67
|
end
|
|
77
68
|
|
|
78
|
-
# Renders a
|
|
79
|
-
# @param
|
|
69
|
+
# Renders a content item while ensuring site locale is set if the data is available.
|
|
70
|
+
# @param item [Document, Page, Bridgetown::Resource::Base] The item to render
|
|
80
71
|
# @yield Runs the block in between locale setting and resetting
|
|
81
72
|
# @return [void]
|
|
82
|
-
def render_with_locale(
|
|
83
|
-
if
|
|
73
|
+
def render_with_locale(item)
|
|
74
|
+
if item.data["locale"]
|
|
84
75
|
previous_locale = locale
|
|
85
|
-
self.locale =
|
|
76
|
+
self.locale = item.data["locale"]
|
|
86
77
|
yield
|
|
87
78
|
self.locale = previous_locale
|
|
88
79
|
else
|
|
@@ -90,13 +81,11 @@ class Bridgetown::Site
|
|
|
90
81
|
end
|
|
91
82
|
end
|
|
92
83
|
|
|
93
|
-
# Regenerates a
|
|
94
|
-
# @param
|
|
84
|
+
# Regenerates a content item using {Renderer}
|
|
85
|
+
# @param item [Page] The page to render
|
|
95
86
|
# @return [void]
|
|
96
|
-
def
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Bridgetown::Renderer.new(self, document).run
|
|
87
|
+
def render_page(page)
|
|
88
|
+
Bridgetown::Renderer.new(self, page).run
|
|
100
89
|
end
|
|
101
90
|
end
|
|
102
91
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Bridgetown::Site
|
|
4
|
+
module SSR
|
|
5
|
+
def self.included(base)
|
|
6
|
+
base.extend ClassMethods
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module ClassMethods
|
|
10
|
+
# Establish an SSR pipeline for a persistent backend process
|
|
11
|
+
def start_ssr! # rubocop:todo Metrics/AbcSize
|
|
12
|
+
if Bridgetown::Current.site
|
|
13
|
+
raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
|
|
14
|
+
"Check your Rack app for threading issues"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Bridgetown::PluginManager.require_from_bundler
|
|
18
|
+
site = new(Bridgetown::Current.preloaded_configuration)
|
|
19
|
+
site.enable_ssr
|
|
20
|
+
|
|
21
|
+
Bridgetown::Hooks.trigger :site, :pre_read, site
|
|
22
|
+
site.defaults_reader.tap do |d|
|
|
23
|
+
d.path_defaults.clear
|
|
24
|
+
d.read
|
|
25
|
+
end
|
|
26
|
+
site.layouts = Bridgetown::LayoutReader.new(site).read
|
|
27
|
+
site.collections.data.tap do |coll|
|
|
28
|
+
coll.read
|
|
29
|
+
site.data = coll.merge_data_resources
|
|
30
|
+
end
|
|
31
|
+
Bridgetown::Hooks.trigger :site, :post_read, site
|
|
32
|
+
|
|
33
|
+
yield(site) if block_given? # provide additional setup hook
|
|
34
|
+
|
|
35
|
+
site
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def ssr?
|
|
40
|
+
@ssr_enabled == true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def enable_ssr
|
|
44
|
+
Bridgetown.logger.info "SSR:", "enabled."
|
|
45
|
+
@ssr_enabled = true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def disable_ssr
|
|
49
|
+
Bridgetown.logger.info "SSR:", "now disabled."
|
|
50
|
+
@ssr_enabled = false
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -13,22 +13,19 @@ class Bridgetown::Site
|
|
|
13
13
|
#
|
|
14
14
|
# @return [void]
|
|
15
15
|
def write
|
|
16
|
-
each_site_file
|
|
17
|
-
item.write(dest) if regenerator.regenerate?(item)
|
|
18
|
-
end
|
|
19
|
-
regenerator.write_metadata
|
|
16
|
+
each_site_file { |item| item.write(dest) }
|
|
20
17
|
Bridgetown::Hooks.trigger :site, :post_write, self
|
|
21
18
|
end
|
|
22
19
|
|
|
23
|
-
# Yields all content objects while looping through {#
|
|
24
|
-
# {#static_files_to_write}, {#
|
|
20
|
+
# Yields all content objects while looping through {#generated_pages},
|
|
21
|
+
# {#static_files_to_write}, {#resources_to_write}.
|
|
25
22
|
#
|
|
26
|
-
# @yieldparam item [
|
|
23
|
+
# @yieldparam item [Bridgetown::Resource::Base, GeneratedPage, StaticFile]
|
|
27
24
|
#
|
|
28
25
|
# @return [void]
|
|
29
26
|
def each_site_file
|
|
30
|
-
%w(
|
|
31
|
-
send(type).each do |item|
|
|
27
|
+
%w(generated_pages static_files_to_write resources_to_write).each do |type|
|
|
28
|
+
send(type).each do |item| # rubocop:disable Style/ExplicitBlockArgument
|
|
32
29
|
yield item
|
|
33
30
|
end
|
|
34
31
|
end
|
|
@@ -34,32 +34,28 @@ module Bridgetown
|
|
|
34
34
|
"encoding" => "utf-8",
|
|
35
35
|
"markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
|
|
36
36
|
"strict_front_matter" => false,
|
|
37
|
-
"slugify_categories" => true,
|
|
38
37
|
"slugify_mode" => "pretty",
|
|
39
38
|
|
|
40
39
|
# Filtering Content
|
|
41
|
-
"limit_posts" => 0,
|
|
42
40
|
"future" => false,
|
|
43
41
|
"unpublished" => false,
|
|
44
42
|
"ruby_in_front_matter" => true,
|
|
45
43
|
|
|
46
44
|
# Conversion
|
|
45
|
+
"content_engine" => "resource",
|
|
47
46
|
"markdown" => "kramdown",
|
|
48
47
|
"highlighter" => "rouge",
|
|
49
|
-
"lsi" => false,
|
|
50
48
|
"excerpt_separator" => "\n\n",
|
|
51
|
-
"incremental" => false,
|
|
52
49
|
|
|
53
50
|
# Serving
|
|
54
|
-
"detach" => false, # default to not detaching the server
|
|
55
51
|
"port" => "4000",
|
|
56
52
|
"host" => "127.0.0.1",
|
|
57
53
|
"base_path" => "/",
|
|
58
54
|
"show_dir_listing" => false,
|
|
59
55
|
|
|
60
56
|
# Output Configuration
|
|
61
|
-
"available_locales" => [
|
|
62
|
-
"default_locale" =>
|
|
57
|
+
"available_locales" => [:en],
|
|
58
|
+
"default_locale" => :en,
|
|
63
59
|
"permalink" => nil, # default is set according to content engine
|
|
64
60
|
"timezone" => nil, # use the local timezone
|
|
65
61
|
|
|
@@ -103,6 +99,7 @@ module Bridgetown
|
|
|
103
99
|
def from(user_config, starting_defaults = DEFAULTS)
|
|
104
100
|
Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
|
|
105
101
|
.merge_environment_specific_options!
|
|
102
|
+
.setup_locales
|
|
106
103
|
.add_default_collections
|
|
107
104
|
.add_default_excludes
|
|
108
105
|
.check_include_exclude
|
|
@@ -206,7 +203,7 @@ module Bridgetown
|
|
|
206
203
|
end
|
|
207
204
|
rescue ArgumentError => e
|
|
208
205
|
Bridgetown.logger.warn "WARNING:", "Error reading configuration. Using defaults" \
|
|
209
|
-
|
|
206
|
+
" (and options)."
|
|
210
207
|
warn e
|
|
211
208
|
end
|
|
212
209
|
|
|
@@ -247,6 +244,12 @@ module Bridgetown
|
|
|
247
244
|
self
|
|
248
245
|
end
|
|
249
246
|
|
|
247
|
+
def setup_locales
|
|
248
|
+
self.default_locale = default_locale.to_sym
|
|
249
|
+
available_locales.map!(&:to_sym)
|
|
250
|
+
self
|
|
251
|
+
end
|
|
252
|
+
|
|
250
253
|
def add_default_collections # rubocop:todo all
|
|
251
254
|
# It defaults to `{}`, so this is only if someone sets it to null manually.
|
|
252
255
|
return self if self[:collections].nil?
|
|
@@ -263,23 +266,16 @@ module Bridgetown
|
|
|
263
266
|
self[:collections][:posts][:output] = true
|
|
264
267
|
self[:collections][:posts][:sort_direction] ||= "descending"
|
|
265
268
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
self[:collections][:pages][:permalink] ||= "/:path/"
|
|
269
|
+
self[:permalink] = "pretty" if self[:permalink].blank?
|
|
270
|
+
self[:collections][:pages] = {} unless self[:collections][:pages]
|
|
271
|
+
self[:collections][:pages][:output] = true
|
|
272
|
+
self[:collections][:pages][:permalink] ||= "/:locale/:path/"
|
|
271
273
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
+
self[:collections][:data] = {} unless self[:collections][:data]
|
|
275
|
+
self[:collections][:data][:output] = false
|
|
274
276
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
end
|
|
278
|
-
else
|
|
279
|
-
self[:permalink] = "date" if self[:permalink].blank?
|
|
280
|
-
unless self[:collections][:posts][:permalink]
|
|
281
|
-
self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
|
|
282
|
-
end
|
|
277
|
+
unless self[:collections][:posts][:permalink]
|
|
278
|
+
self[:collections][:posts][:permalink] = self[:permalink]
|
|
283
279
|
end
|
|
284
280
|
|
|
285
281
|
self
|
|
@@ -304,26 +300,6 @@ module Bridgetown
|
|
|
304
300
|
self["ruby_in_front_matter"]
|
|
305
301
|
end
|
|
306
302
|
|
|
307
|
-
# Deprecated, to be removed when Bridgetown goes Resource-only
|
|
308
|
-
def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
|
|
309
|
-
case permalink_style.to_s.to_sym
|
|
310
|
-
when :pretty
|
|
311
|
-
"/:categories/:year/:month/:day/:title/"
|
|
312
|
-
when :simple
|
|
313
|
-
"/:categories/:title/"
|
|
314
|
-
when :none
|
|
315
|
-
"/:categories/:title:output_ext"
|
|
316
|
-
when :date
|
|
317
|
-
"/:categories/:year/:month/:day/:title:output_ext"
|
|
318
|
-
when :ordinal
|
|
319
|
-
"/:categories/:year/:y_day/:title:output_ext"
|
|
320
|
-
when :weekdate
|
|
321
|
-
"/:categories/:year/W:week/:short_day/:title:output_ext"
|
|
322
|
-
else
|
|
323
|
-
permalink_style.to_s
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
|
|
327
303
|
def check_include_exclude
|
|
328
304
|
%w(include exclude).each do |option|
|
|
329
305
|
next unless key?(option)
|
|
@@ -333,11 +309,6 @@ module Bridgetown
|
|
|
333
309
|
"'#{option}' should be set as an array, but was: #{self[option].inspect}."
|
|
334
310
|
end
|
|
335
311
|
|
|
336
|
-
unless self[:include].include?("_pages") || self[:content_engine] == "resource"
|
|
337
|
-
# add _pages to includes set
|
|
338
|
-
self[:include] << "_pages"
|
|
339
|
-
end
|
|
340
|
-
|
|
341
312
|
self
|
|
342
313
|
end
|
|
343
314
|
|
|
@@ -65,7 +65,7 @@ create_file "test/test_homepage.rb" do
|
|
|
65
65
|
class TestHomepage < Minitest::Test
|
|
66
66
|
context "homepage" do
|
|
67
67
|
setup do
|
|
68
|
-
page = site.pages.find { |doc| doc.
|
|
68
|
+
page = site.collections.pages.resources.find { |doc| doc.relative_url == "/" }
|
|
69
69
|
document_root page
|
|
70
70
|
end
|
|
71
71
|
should "exist" do
|
|
@@ -38,7 +38,7 @@ module Bridgetown
|
|
|
38
38
|
return if text.empty?
|
|
39
39
|
|
|
40
40
|
src << bufvar << ".safe_append='"
|
|
41
|
-
src << text.gsub(%r{['\\]}, '\\\\\&')
|
|
41
|
+
src << text.gsub(%r{['\\]}, '\\\\\&') # rubocop:disable Style/StringLiterals
|
|
42
42
|
src << "'.freeze;"
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -104,7 +104,8 @@ 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
|
-
# @param convertible [
|
|
107
|
+
# @param convertible [
|
|
108
|
+
# Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
|
|
108
109
|
# The instantiated object which is processing the file.
|
|
109
110
|
#
|
|
110
111
|
# @return [String] The converted content.
|
|
@@ -18,7 +18,8 @@ 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
|
-
# @param convertible [
|
|
21
|
+
# @param convertible [
|
|
22
|
+
# Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
|
|
22
23
|
# The instantiated object which is processing the file.
|
|
23
24
|
#
|
|
24
25
|
# @return [String] The converted content.
|
|
@@ -84,7 +85,7 @@ module Bridgetown
|
|
|
84
85
|
def configure_payload(content = nil)
|
|
85
86
|
payload["page"] = document.to_liquid
|
|
86
87
|
payload["paginator"] = document.respond_to?(:paginator) ? document.paginator.to_liquid : nil
|
|
87
|
-
payload["layout"] = @layout ? @layout.data : {}
|
|
88
|
+
payload["layout"] = @layout ? @layout.to_liquid.merge({ data: @layout.data }) : {}
|
|
88
89
|
payload["content"] = content
|
|
89
90
|
end
|
|
90
91
|
|