bridgetown-core 1.0.0 → 1.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/bridgetown-core.gemspec +0 -1
- data/lib/bridgetown-core/collection.rb +39 -22
- data/lib/bridgetown-core/commands/apply.rb +3 -3
- data/lib/bridgetown-core/commands/build.rb +6 -6
- data/lib/bridgetown-core/commands/concerns/actions.rb +3 -2
- data/lib/bridgetown-core/commands/concerns/build_options.rb +2 -2
- data/lib/bridgetown-core/commands/configure.rb +1 -1
- data/lib/bridgetown-core/commands/console.rb +5 -5
- data/lib/bridgetown-core/commands/doctor.rb +7 -7
- data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +95 -12
- data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -6
- data/lib/bridgetown-core/commands/new.rb +20 -19
- data/lib/bridgetown-core/commands/plugins.rb +47 -9
- data/lib/bridgetown-core/commands/registrations.rb +2 -3
- data/lib/bridgetown-core/commands/serve.rb +2 -2
- data/lib/bridgetown-core/commands/start.rb +3 -0
- data/lib/bridgetown-core/commands/webpack/update.rb +3 -3
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +19 -14
- data/lib/bridgetown-core/component.rb +14 -8
- data/lib/bridgetown-core/concerns/localizable.rb +20 -0
- data/lib/bridgetown-core/concerns/prioritizable.rb +44 -0
- data/lib/bridgetown-core/concerns/publishable.rb +11 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +2 -10
- data/lib/bridgetown-core/concerns/site/localizable.rb +5 -1
- data/lib/bridgetown-core/concerns/site/ssr.rb +3 -3
- data/lib/bridgetown-core/concerns/site/writable.rb +28 -0
- data/lib/bridgetown-core/concerns/transformable.rb +2 -2
- data/lib/bridgetown-core/configuration.rb +4 -2
- data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +5 -3
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -1
- data/lib/bridgetown-core/configurations/lit/esbuild-plugins.js +21 -0
- data/lib/bridgetown-core/configurations/lit/happy-days.lit.js +26 -0
- data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -0
- data/lib/bridgetown-core/configurations/lit/lit-ssr.config.js +6 -0
- data/lib/bridgetown-core/configurations/lit.rb +95 -0
- data/lib/bridgetown-core/configurations/open-props/variables.css.erb +11 -0
- data/lib/bridgetown-core/configurations/open-props.rb +21 -0
- data/lib/bridgetown-core/configurations/ruby2js/hello_world.js.rb +9 -0
- data/lib/bridgetown-core/configurations/ruby2js.rb +67 -0
- data/lib/bridgetown-core/configurations/shoelace.rb +50 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +16 -2
- data/lib/bridgetown-core/configurations/turbo/turbo_transitions.js +1 -1
- data/lib/bridgetown-core/converters/erb_templates.rb +7 -2
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/serbea_templates.rb +1 -4
- data/lib/bridgetown-core/drops/generated_page_drop.rb +2 -1
- data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
- data/lib/bridgetown-core/errors.rb +5 -5
- data/lib/bridgetown-core/filters/translation_filters.rb +11 -0
- data/lib/bridgetown-core/filters/url_filters.rb +37 -10
- data/lib/bridgetown-core/filters.rb +3 -0
- data/lib/bridgetown-core/frontmatter_defaults.rb +14 -8
- data/lib/bridgetown-core/generated_page.rb +1 -0
- data/lib/bridgetown-core/kramdown/parser/gfm.rb +36 -0
- data/lib/bridgetown-core/model/base.rb +3 -4
- data/lib/bridgetown-core/plugin.rb +6 -37
- data/lib/bridgetown-core/plugin_manager.rb +3 -2
- data/lib/bridgetown-core/rack/boot.rb +7 -2
- data/lib/bridgetown-core/rack/logger.rb +14 -4
- data/lib/bridgetown-core/rack/roda.rb +106 -9
- data/lib/bridgetown-core/rack/routes.rb +67 -2
- data/lib/bridgetown-core/resource/base.rb +9 -6
- data/lib/bridgetown-core/resource/destination.rb +18 -0
- data/lib/bridgetown-core/resource/permalink_processor.rb +6 -4
- data/lib/bridgetown-core/resource/relations.rb +1 -1
- data/lib/bridgetown-core/ruby_template_view.rb +3 -3
- data/lib/bridgetown-core/static_file.rb +1 -1
- data/lib/bridgetown-core/tags/highlight.rb +1 -1
- data/lib/bridgetown-core/tags/post_url.rb +1 -1
- data/lib/bridgetown-core/url.rb +1 -1
- data/lib/bridgetown-core/utils/aux.rb +2 -1
- data/lib/bridgetown-core/utils/require_gems.rb +3 -6
- data/lib/bridgetown-core/utils.rb +24 -11
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +21 -8
- data/lib/bridgetown-core.rb +8 -2
- data/lib/site_template/Gemfile.erb +4 -0
- data/lib/site_template/README.md +2 -2
- data/lib/site_template/bridgetown.config.yml +3 -0
- data/lib/site_template/frontend/javascript/index.js.erb +1 -0
- data/lib/site_template/frontend/styles/syntax-highlighting.css +77 -0
- data/lib/site_template/package.json.erb +18 -18
- data/lib/site_template/server/roda_app.rb +3 -6
- data/lib/site_template/src/404.html +2 -1
- data/lib/site_template/src/500.html +10 -0
- metadata +20 -19
- data/lib/bridgetown-core/publisher.rb +0 -29
@@ -13,6 +13,9 @@ module Bridgetown
|
|
13
13
|
end
|
14
14
|
|
15
15
|
desc "list", "List information about installed plugins"
|
16
|
+
option :verbose,
|
17
|
+
type: :boolean,
|
18
|
+
desc: "Print the source path of each plugin"
|
16
19
|
def list
|
17
20
|
site = Bridgetown::Site.new(configuration_with_overrides(options))
|
18
21
|
site.reset
|
@@ -32,7 +35,7 @@ module Bridgetown
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
Bridgetown.logger.info("Source Manifests:", "
|
38
|
+
Bridgetown.logger.info("Source Manifests:", "----") unless pm.class.source_manifests.empty?
|
36
39
|
|
37
40
|
pm.class.source_manifests.each do |manifest|
|
38
41
|
Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
|
@@ -40,20 +43,27 @@ module Bridgetown
|
|
40
43
|
Bridgetown.logger.info("Content:", (manifest.content || "n/a").to_s.cyan)
|
41
44
|
Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
|
42
45
|
|
43
|
-
Bridgetown.logger.info("", "
|
46
|
+
Bridgetown.logger.info("", "----")
|
44
47
|
end
|
45
48
|
|
46
49
|
unless Bridgetown.autoload? :Builder
|
47
50
|
builders = Bridgetown::Builder.descendants
|
48
51
|
Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
|
49
52
|
|
50
|
-
builders.each do |builder|
|
51
|
-
name = builder
|
53
|
+
builders.sort.each do |builder|
|
54
|
+
name = plugin_name_for(builder)
|
52
55
|
name_components = name.split("::")
|
53
56
|
last_name = name_components.pop
|
54
57
|
name_components.push last_name.magenta
|
55
58
|
Bridgetown.logger.info("", name_components.join("::"))
|
59
|
+
next unless options[:verbose]
|
60
|
+
|
61
|
+
Bridgetown.logger.info(
|
62
|
+
"", "PATH: " + builder_path_for(builder)
|
63
|
+
)
|
64
|
+
Bridgetown.logger.info("")
|
56
65
|
end
|
66
|
+
Bridgetown.logger.info("", "----")
|
57
67
|
end
|
58
68
|
|
59
69
|
Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
|
@@ -64,8 +74,16 @@ module Bridgetown
|
|
64
74
|
last_name = name_components.pop
|
65
75
|
name_components.push last_name.magenta
|
66
76
|
Bridgetown.logger.info("", name_components.join("::"))
|
77
|
+
next unless options[:verbose]
|
78
|
+
|
79
|
+
Bridgetown.logger.info(
|
80
|
+
"", "PATH: " + converter_path_for(converter)
|
81
|
+
)
|
82
|
+
Bridgetown.logger.info("")
|
67
83
|
end
|
68
84
|
|
85
|
+
Bridgetown.logger.info("", "----")
|
86
|
+
|
69
87
|
Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
|
70
88
|
|
71
89
|
site.generators.each do |generator|
|
@@ -74,6 +92,12 @@ module Bridgetown
|
|
74
92
|
last_name = name_components.pop
|
75
93
|
name_components.push last_name.magenta
|
76
94
|
Bridgetown.logger.info("", name_components.join("::"))
|
95
|
+
next unless options[:verbose]
|
96
|
+
|
97
|
+
Bridgetown.logger.info(
|
98
|
+
"", "PATH: " + generator_path_for(generator)
|
99
|
+
)
|
100
|
+
Bridgetown.logger.info("")
|
77
101
|
end
|
78
102
|
end
|
79
103
|
|
@@ -120,6 +144,7 @@ module Bridgetown
|
|
120
144
|
" return to your site root.")
|
121
145
|
puts
|
122
146
|
|
147
|
+
# rubocop: disable Style/RedundantCondition
|
123
148
|
Dir.chdir dir do
|
124
149
|
ENV["BRIDGETOWN_SITE"] = site.root_dir
|
125
150
|
if ENV["SHELL"]
|
@@ -128,6 +153,7 @@ module Bridgetown
|
|
128
153
|
system("/bin/sh")
|
129
154
|
end
|
130
155
|
end
|
156
|
+
# rubocop: enable Style/RedundantCondition
|
131
157
|
|
132
158
|
puts
|
133
159
|
Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
|
@@ -194,11 +220,23 @@ module Bridgetown
|
|
194
220
|
protected
|
195
221
|
|
196
222
|
def plugin_name_for(plugin)
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
223
|
+
klass = plugin.is_a?(Class) ? plugin : plugin.class
|
224
|
+
klass.respond_to?(:custom_name) ? klass.custom_name : klass.name
|
225
|
+
end
|
226
|
+
|
227
|
+
def builder_path_for(plugin)
|
228
|
+
klass = plugin.is_a?(Class) ? plugin : plugin.class
|
229
|
+
klass.instance_method(:build).source_location[0]
|
230
|
+
end
|
231
|
+
|
232
|
+
def converter_path_for(plugin)
|
233
|
+
klass = plugin.is_a?(Class) ? plugin : plugin.class
|
234
|
+
klass.instance_method(:convert).source_location[0]
|
235
|
+
end
|
236
|
+
|
237
|
+
def generator_path_for(plugin)
|
238
|
+
klass = plugin.is_a?(Class) ? plugin : plugin.class
|
239
|
+
klass.instance_method(:generate).source_location[0]
|
202
240
|
end
|
203
241
|
end
|
204
242
|
end
|
@@ -4,12 +4,11 @@ module Bridgetown
|
|
4
4
|
module Commands
|
5
5
|
module Registrations
|
6
6
|
def self.registrations
|
7
|
-
@registrations
|
7
|
+
@registrations ||= []
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.register(&block)
|
11
|
-
|
12
|
-
@registrations.push(block)
|
11
|
+
registrations << block
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -178,8 +178,8 @@ module Bridgetown
|
|
178
178
|
|
179
179
|
Process.detach(pid)
|
180
180
|
Bridgetown.logger.info "Server detached with pid '#{pid}'.", \
|
181
|
-
"Run `pkill -f bridgetown' or `kill -9 #{pid}'" \
|
182
|
-
"
|
181
|
+
"Run `pkill -f bridgetown' or `kill -9 #{pid}' " \
|
182
|
+
"to stop the server."
|
183
183
|
else
|
184
184
|
t = Thread.new { server.start }
|
185
185
|
trap("INT") { server.shutdown }
|
@@ -7,11 +7,11 @@ say "🎉 Webpack configuration updated successfully!"
|
|
7
7
|
|
8
8
|
return if Bridgetown.environment.test?
|
9
9
|
|
10
|
-
required_packages = %w(esbuild esbuild-loader webpack@5.
|
11
|
-
redundant_packages = %w(@babel/core @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators @babel/plugin-transform-runtime @babel/preset-env babel-loader)
|
10
|
+
required_packages = %w(esbuild esbuild-loader css-loader@6.7.1 webpack@5.72.0 webpack-cli@4.9.2 webpack-manifest-plugin@5.0.0)
|
11
|
+
redundant_packages = %w(@babel/core @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators @babel/plugin-transform-runtime @babel/preset-env babel-loader file-loader)
|
12
12
|
|
13
13
|
say "Installing required packages"
|
14
|
-
run "yarn add -D #{required_packages.join(" ")}"
|
14
|
+
run "yarn add -D --tilde #{required_packages.join(" ")}"
|
15
15
|
|
16
16
|
packages_to_remove = package_json["devDependencies"].slice(*redundant_packages).keys
|
17
17
|
unless packages_to_remove.empty?
|
@@ -41,7 +41,9 @@ const cssRules = {
|
|
41
41
|
{
|
42
42
|
loader: "css-loader",
|
43
43
|
options: {
|
44
|
-
url:
|
44
|
+
url: {
|
45
|
+
filter: url => !url.startsWith('/')
|
46
|
+
},
|
45
47
|
importLoaders: 1
|
46
48
|
}
|
47
49
|
}
|
@@ -49,7 +51,14 @@ const cssRules = {
|
|
49
51
|
mode: '<%= self.config.uses_postcss? ? "postcss" : "sass" %>',
|
50
52
|
|
51
53
|
postcss: () => {
|
52
|
-
cssRules.use.push(
|
54
|
+
cssRules.use.push({
|
55
|
+
loader: "postcss-loader",
|
56
|
+
options: {
|
57
|
+
postcssOptions: {
|
58
|
+
config: "postcss.config.js"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
})
|
53
62
|
return { test: cssRules.test, use: cssRules.use }
|
54
63
|
},
|
55
64
|
|
@@ -72,22 +81,18 @@ const cssRules = {
|
|
72
81
|
|
73
82
|
const fontsRule = {
|
74
83
|
test: /\.woff2?$|\.ttf$|\.eot$/,
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
publicPath: "../fonts",
|
80
|
-
},
|
84
|
+
type: "asset/resource",
|
85
|
+
generator: {
|
86
|
+
filename: "../fonts/[name]-[hash][ext][query]"
|
87
|
+
}
|
81
88
|
}
|
82
89
|
|
83
90
|
const imagesRule = {
|
84
91
|
test: /\.png?$|\.gif$|\.jpg$|\.svg$/,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
publicPath: "../",
|
90
|
-
},
|
92
|
+
type: "asset/resource",
|
93
|
+
generator: {
|
94
|
+
filename: "../[path][name]-[hash][ext][query]"
|
95
|
+
}
|
91
96
|
}
|
92
97
|
|
93
98
|
// Default configuration object
|
@@ -4,7 +4,7 @@ module Bridgetown
|
|
4
4
|
class Component
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def_delegators :@view_context, :
|
7
|
+
def_delegators :@view_context, :liquid_render, :partial
|
8
8
|
|
9
9
|
# @return [Bridgetown::Site]
|
10
10
|
attr_reader :site # will be nil unless you explicitly set a `@site` ivar
|
@@ -32,14 +32,12 @@ module Bridgetown
|
|
32
32
|
def renderer_for_ext(ext, &block)
|
33
33
|
@_tmpl ||= case ext.to_s
|
34
34
|
when "erb"
|
35
|
-
include ERBCapture
|
36
35
|
Tilt::ErubiTemplate.new(component_template_path,
|
37
36
|
outvar: "@_erbout",
|
38
37
|
bufval: "Bridgetown::OutputBuffer.new",
|
39
38
|
engine_class: Bridgetown::ERBEngine,
|
40
39
|
&block)
|
41
|
-
when "serb"
|
42
|
-
include Serbea::Helpers
|
40
|
+
when "serb"
|
43
41
|
Tilt::SerbeaTemplate.new(component_template_path, &block)
|
44
42
|
when "slim" # requires bridgetown-slim
|
45
43
|
Slim::Template.new(component_template_path, &block)
|
@@ -138,7 +136,7 @@ module Bridgetown
|
|
138
136
|
end
|
139
137
|
rescue StandardError => e
|
140
138
|
Bridgetown.logger.error "Component error:",
|
141
|
-
"#{self.class} encountered an error while "\
|
139
|
+
"#{self.class} encountered an error while " \
|
142
140
|
"rendering `#{self.class.path_for_errors}'"
|
143
141
|
raise e
|
144
142
|
end
|
@@ -166,12 +164,20 @@ module Bridgetown
|
|
166
164
|
def _renderer
|
167
165
|
@_renderer ||= begin
|
168
166
|
ext = File.extname(self.class.component_template_path).delete_prefix(".")
|
169
|
-
self.class.renderer_for_ext(ext) { self.class.component_template_content }
|
167
|
+
self.class.renderer_for_ext(ext) { self.class.component_template_content }.tap do |rn|
|
168
|
+
self.class.include(rn.is_a?(Tilt::SerbeaTemplate) ? Serbea::Helpers : ERBCapture)
|
169
|
+
end
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
def helpers
|
174
|
+
@helpers ||= Bridgetown::RubyTemplateView::Helpers.new(
|
175
|
+
self, view_context&.site || Bridgetown::Current.site
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
173
179
|
def method_missing(method, *args, **kwargs, &block)
|
174
|
-
if
|
180
|
+
if helpers.respond_to?(method.to_sym)
|
175
181
|
helpers.send method.to_sym, *args, **kwargs, &block
|
176
182
|
else
|
177
183
|
super
|
@@ -179,7 +185,7 @@ module Bridgetown
|
|
179
185
|
end
|
180
186
|
|
181
187
|
def respond_to_missing?(method, include_private = false)
|
182
|
-
|
188
|
+
helpers.respond_to?(method.to_sym, include_private) || super
|
183
189
|
end
|
184
190
|
end
|
185
191
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Localizable
|
5
|
+
def all_locales
|
6
|
+
result_set = case self
|
7
|
+
when Bridgetown::Resource::Base
|
8
|
+
collection.resources
|
9
|
+
when Bridgetown::GeneratedPage
|
10
|
+
site.generated_pages
|
11
|
+
else
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
|
15
|
+
result_set.select { |item| item.data.slug == data.slug }.sort_by do |item|
|
16
|
+
site.config.available_locales.index item.data.locale
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Prioritizable
|
5
|
+
module ClassMethods
|
6
|
+
# @!method priorities
|
7
|
+
# @return [Hash<Symbol, Object>]
|
8
|
+
|
9
|
+
# Get or set the priority of this class. When called without an
|
10
|
+
# argument it returns the priority. When an argument is given, it will
|
11
|
+
# set the priority.
|
12
|
+
#
|
13
|
+
# @param priority [Symbol] new priority (optional)
|
14
|
+
# Valid options are: `:lowest`, `:low`, `:normal`, `:high`, `:highest`
|
15
|
+
# @return [Symbol]
|
16
|
+
def priority(priority = nil)
|
17
|
+
@priority ||= nil
|
18
|
+
@priority = priority if priority && priorities.key?(priority)
|
19
|
+
@priority || :normal
|
20
|
+
end
|
21
|
+
|
22
|
+
# Spaceship is priority [higher -> lower]
|
23
|
+
#
|
24
|
+
# @param other [Class] The class to be compared.
|
25
|
+
# @return [Integer] -1, 0, 1.
|
26
|
+
def <=>(other)
|
27
|
+
priorities[other.priority] <=> priorities[priority]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.included(klass)
|
32
|
+
klass.extend ClassMethods
|
33
|
+
klass.class_attribute :priorities, instance_accessor: false
|
34
|
+
end
|
35
|
+
|
36
|
+
# Spaceship is priority [higher -> lower]
|
37
|
+
#
|
38
|
+
# @param other [object] The object to be compared.
|
39
|
+
# @return [Integer] -1, 0, 1.
|
40
|
+
def <=>(other)
|
41
|
+
self.class <=> other.class
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -2,9 +2,19 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
module Publishable
|
5
|
-
# Whether the
|
5
|
+
# Whether the resource is published or not, as indicated in YAML front-matter
|
6
6
|
def published?
|
7
7
|
!(data.key?("published") && data["published"] == false)
|
8
8
|
end
|
9
|
+
|
10
|
+
def publishable?
|
11
|
+
return true if collection.data?
|
12
|
+
return false unless published? || @site.config.unpublished
|
13
|
+
|
14
|
+
future_allowed = collection.metadata.future || @site.config.future
|
15
|
+
this_time = date.is_a?(Date) ? date.to_time.to_i : date.to_i
|
16
|
+
|
17
|
+
future_allowed || this_time <= @site.time.to_i
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
@@ -38,7 +38,7 @@ class Bridgetown::Site
|
|
38
38
|
# @param strip_slash_only [Boolean] set to true if you wish "/" to be returned as ""
|
39
39
|
# @return [String]
|
40
40
|
def base_path(strip_slash_only: false)
|
41
|
-
(config[:base_path] || config[:baseurl]).
|
41
|
+
(config[:base_path] || config[:baseurl]).then do |path|
|
42
42
|
strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path
|
43
43
|
end
|
44
44
|
end
|
@@ -61,14 +61,6 @@ class Bridgetown::Site
|
|
61
61
|
@frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
|
62
62
|
end
|
63
63
|
|
64
|
-
# Returns the current instance of {Publisher} or creates a new instance of
|
65
|
-
# {Publisher} if one doesn't exist.
|
66
|
-
#
|
67
|
-
# @return [Publisher] Returns an instance of {Publisher}
|
68
|
-
def publisher
|
69
|
-
@publisher ||= Bridgetown::Publisher.new(self)
|
70
|
-
end
|
71
|
-
|
72
64
|
# Prefix a path or paths with the {#root_dir} directory.
|
73
65
|
#
|
74
66
|
# @see Bridgetown.sanitized_path
|
@@ -166,7 +158,7 @@ class Bridgetown::Site
|
|
166
158
|
plugin_components_load_paths = Bridgetown::PluginManager.source_manifests
|
167
159
|
.filter_map(&:components)
|
168
160
|
|
169
|
-
local_components_load_paths = config["components_dir"].
|
161
|
+
local_components_load_paths = config["components_dir"].then do |dir|
|
170
162
|
dir.is_a?(Array) ? dir : [dir]
|
171
163
|
end
|
172
164
|
local_components_load_paths.map! do |dir|
|
@@ -7,11 +7,15 @@ class Bridgetown::Site
|
|
7
7
|
def locale
|
8
8
|
@locale ||= begin
|
9
9
|
locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
|
10
|
-
Dir["#{in_source_dir("_locales")}/*.yml"].each do |locale_path|
|
10
|
+
Dir["#{in_source_dir("_locales")}/*.{json,rb,yml}"].each do |locale_path|
|
11
11
|
I18n.load_path << locale_path
|
12
12
|
end
|
13
13
|
I18n.available_locales = config[:available_locales]
|
14
14
|
I18n.default_locale = locale
|
15
|
+
I18n.fallbacks = (config[:available_locales] + [:en]).uniq.to_h do |available_locale|
|
16
|
+
[available_locale, [available_locale, locale, :en].uniq]
|
17
|
+
end
|
18
|
+
locale
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -32,7 +32,7 @@ class Bridgetown::Site
|
|
32
32
|
@ssr_enabled = true
|
33
33
|
end
|
34
34
|
|
35
|
-
def ssr_setup
|
35
|
+
def ssr_setup(&block)
|
36
36
|
config.serving = true
|
37
37
|
Bridgetown::Hooks.trigger :site, :pre_read, self
|
38
38
|
defaults_reader.tap do |d|
|
@@ -46,10 +46,10 @@ class Bridgetown::Site
|
|
46
46
|
end
|
47
47
|
Bridgetown::Hooks.trigger :site, :post_read, self
|
48
48
|
|
49
|
-
|
49
|
+
block&.call(self) # provide additional setup hook
|
50
50
|
return if Bridgetown.env.production?
|
51
51
|
|
52
|
-
Bridgetown::Watcher.watch(self, config)
|
52
|
+
Bridgetown::Watcher.watch(self, config, &block)
|
53
53
|
end
|
54
54
|
|
55
55
|
def disable_ssr
|
@@ -14,6 +14,8 @@ class Bridgetown::Site
|
|
14
14
|
# @return [void]
|
15
15
|
def write
|
16
16
|
each_site_file { |item| item.write(dest) }
|
17
|
+
write_redirecting_index if config.prefix_default_locale
|
18
|
+
|
17
19
|
Bridgetown::Hooks.trigger :site, :post_write, self
|
18
20
|
end
|
19
21
|
|
@@ -40,5 +42,31 @@ class Bridgetown::Site
|
|
40
42
|
}
|
41
43
|
end
|
42
44
|
end
|
45
|
+
|
46
|
+
def write_redirecting_index
|
47
|
+
resource = resources.find do |item|
|
48
|
+
item.data.slug == "index" && item.data.locale == config.default_locale
|
49
|
+
end
|
50
|
+
|
51
|
+
unless resource
|
52
|
+
Bridgetown.logger.warn(
|
53
|
+
"Index file not found in the source folder, cannot generate top-level redirect file"
|
54
|
+
)
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
index_html = <<~HTML
|
59
|
+
<!DOCTYPE html>
|
60
|
+
<html>
|
61
|
+
<head>
|
62
|
+
<title>Redirecting…</title>
|
63
|
+
<meta http-equiv="refresh" content="0; url=#{resource.relative_url}" />
|
64
|
+
</head>
|
65
|
+
<body></body>
|
66
|
+
</html>
|
67
|
+
HTML
|
68
|
+
|
69
|
+
File.write(in_dest_dir("index.html"), index_html, mode: "wb")
|
70
|
+
end
|
43
71
|
end
|
44
72
|
end
|
@@ -23,7 +23,7 @@ module Bridgetown
|
|
23
23
|
output.html_safe
|
24
24
|
rescue StandardError => e
|
25
25
|
Bridgetown.logger.error "Conversion error:",
|
26
|
-
"#{converter.class} encountered an error while "\
|
26
|
+
"#{converter.class} encountered an error while " \
|
27
27
|
"converting `#{document.relative_path}'"
|
28
28
|
raise e
|
29
29
|
end
|
@@ -53,7 +53,7 @@ module Bridgetown
|
|
53
53
|
layout_output
|
54
54
|
rescue StandardError => e
|
55
55
|
Bridgetown.logger.error "Conversion error:",
|
56
|
-
"#{converter.class} encountered an error while "\
|
56
|
+
"#{converter.class} encountered an error while " \
|
57
57
|
"converting `#{document.relative_path}'"
|
58
58
|
raise e
|
59
59
|
end
|
@@ -59,6 +59,7 @@ module Bridgetown
|
|
59
59
|
# Output Configuration
|
60
60
|
"available_locales" => [:en],
|
61
61
|
"default_locale" => :en,
|
62
|
+
"prefix_default_locale" => false,
|
62
63
|
"permalink" => nil, # default is set according to content engine
|
63
64
|
"timezone" => nil, # use the local timezone
|
64
65
|
|
@@ -83,6 +84,7 @@ module Bridgetown
|
|
83
84
|
"footnote_nr" => 1,
|
84
85
|
"show_warnings" => false,
|
85
86
|
"include_extraction_tags" => false,
|
87
|
+
"mark_highlighting" => true,
|
86
88
|
},
|
87
89
|
}.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
|
88
90
|
|
@@ -206,8 +208,8 @@ module Bridgetown
|
|
206
208
|
config = Utils.deep_merge_hashes(self, new_config)
|
207
209
|
end
|
208
210
|
rescue ArgumentError => e
|
209
|
-
Bridgetown.logger.warn "WARNING:", "Error reading configuration. Using defaults" \
|
210
|
-
"
|
211
|
+
Bridgetown.logger.warn "WARNING:", "Error reading configuration. Using defaults " \
|
212
|
+
"(and options)."
|
211
213
|
warn e
|
212
214
|
end
|
213
215
|
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module.exports = {
|
2
2
|
plugins: {
|
3
|
-
'postcss-easy-import': {},
|
4
3
|
'postcss-mixins': {},
|
5
|
-
'postcss-color-function': {
|
4
|
+
'postcss-color-mod-function': {
|
5
|
+
// Uncomment the following to import CSS variables for use in `color-mod`:
|
6
|
+
// importFrom: "frontend/styles/variables.css"
|
7
|
+
},
|
6
8
|
'postcss-flexbugs-fixes': {},
|
7
9
|
'postcss-preset-env': {
|
8
10
|
autoprefixer: {
|
@@ -14,7 +16,7 @@ module.exports = {
|
|
14
16
|
'custom-media-queries': true
|
15
17
|
},
|
16
18
|
},
|
17
|
-
'cssnano'
|
19
|
+
'cssnano': {
|
18
20
|
preset: 'default'
|
19
21
|
}
|
20
22
|
}
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
|
15
15
|
return unless confirm.casecmp?("Y")
|
16
16
|
|
17
|
-
plugins = %w(postcss-
|
17
|
+
plugins = %w(postcss-mixins postcss-color-mod-function cssnano)
|
18
18
|
|
19
19
|
say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
|
20
20
|
run "yarn add -D #{plugins.join(' ')}"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// You can add "full-stack" esbuild plugins here that you wish to share between
|
2
|
+
// the frontend bundles and Lit SSR. Just import your plugins and add them and
|
3
|
+
// any additional configuration to the `plugins` array below.
|
4
|
+
|
5
|
+
// This plugin will let you import `.lit.css` files as sidecar stylesheets.
|
6
|
+
// Read https://edge.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
|
7
|
+
const { litCssPlugin } = require("esbuild-plugin-lit-css")
|
8
|
+
const postCssConfig = require("postcss-load-config").sync()
|
9
|
+
const postCssProcessor = require("postcss")([...postCssConfig.plugins])
|
10
|
+
|
11
|
+
module.exports = {
|
12
|
+
plugins: [
|
13
|
+
litCssPlugin({
|
14
|
+
filter: /\.lit\.css$/,
|
15
|
+
transform: async (css, { filePath }) => {
|
16
|
+
const results = await postCssProcessor.process(css, { ...postCssConfig.options, from: filePath })
|
17
|
+
return results.css
|
18
|
+
}
|
19
|
+
}),
|
20
|
+
]
|
21
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { LitElement, html, css } from "lit"
|
2
|
+
|
3
|
+
export class HappyDaysElement extends LitElement {
|
4
|
+
static styles = css`
|
5
|
+
:host {
|
6
|
+
display: block;
|
7
|
+
border: 2px dashed gray;
|
8
|
+
padding: 20px;
|
9
|
+
max-width: 300px;
|
10
|
+
}
|
11
|
+
`
|
12
|
+
|
13
|
+
static properties = {
|
14
|
+
hello: { type: String }
|
15
|
+
}
|
16
|
+
|
17
|
+
render() {
|
18
|
+
return html`
|
19
|
+
<p>Hello ${this.hello}! ${Date.now()}</p>
|
20
|
+
`;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
// Try adding `<%= lit :happy_days, hello: "there" %>` somewhere in an ERB template
|
25
|
+
// on your site to see this example Lit component in action!
|
26
|
+
customElements.define("happy-days", HappyDaysElement)
|
@@ -0,0 +1 @@
|
|
1
|
+
import components from "bridgetownComponents/**/*.{lit.js,lit.js.rb}"
|