bridgetown-core 0.21.0.beta2 → 0.21.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +0 -1
  3. data/lib/bridgetown-core.rb +16 -15
  4. data/lib/bridgetown-core/cleaner.rb +2 -2
  5. data/lib/bridgetown-core/collection.rb +13 -8
  6. data/lib/bridgetown-core/commands/concerns/build_options.rb +2 -2
  7. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  8. data/lib/bridgetown-core/commands/configure.rb +4 -3
  9. data/lib/bridgetown-core/commands/new.rb +6 -6
  10. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  11. data/lib/bridgetown-core/commands/serve.rb +1 -1
  12. data/lib/bridgetown-core/commands/webpack.rb +82 -0
  13. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
  14. data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
  15. data/lib/bridgetown-core/commands/webpack/update.rb +24 -0
  16. data/lib/bridgetown-core/commands/webpack/webpack.config.js +31 -0
  17. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +130 -0
  18. data/lib/bridgetown-core/component.rb +36 -31
  19. data/lib/bridgetown-core/concerns/front_matter_importer.rb +2 -2
  20. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  21. data/lib/bridgetown-core/concerns/site/configurable.rb +18 -7
  22. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  23. data/lib/bridgetown-core/concerns/site/processable.rb +5 -4
  24. data/lib/bridgetown-core/concerns/validatable.rb +1 -1
  25. data/lib/bridgetown-core/configuration.rb +12 -5
  26. data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
  27. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  28. data/lib/bridgetown-core/configurations/tailwindcss.rb +14 -9
  29. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +2 -2
  30. data/lib/bridgetown-core/converters/erb_templates.rb +1 -1
  31. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  32. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  33. data/lib/bridgetown-core/document.rb +2 -2
  34. data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
  35. data/lib/bridgetown-core/drops/site_drop.rb +2 -0
  36. data/lib/bridgetown-core/entry_filter.rb +5 -3
  37. data/lib/bridgetown-core/filters/url_filters.rb +4 -8
  38. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  39. data/lib/bridgetown-core/generators/prototype_generator.rb +25 -4
  40. data/lib/bridgetown-core/layout.rb +27 -10
  41. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  42. data/lib/bridgetown-core/publisher.rb +2 -2
  43. data/lib/bridgetown-core/reader.rb +1 -1
  44. data/lib/bridgetown-core/readers/data_reader.rb +1 -1
  45. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  46. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  47. data/lib/bridgetown-core/regenerator.rb +1 -1
  48. data/lib/bridgetown-core/related_posts.rb +5 -2
  49. data/lib/bridgetown-core/resource/base.rb +29 -7
  50. data/lib/bridgetown-core/resource/destination.rb +3 -1
  51. data/lib/bridgetown-core/resource/permalink_processor.rb +7 -3
  52. data/lib/bridgetown-core/resource/transformer.rb +4 -2
  53. data/lib/bridgetown-core/site.rb +4 -5
  54. data/lib/bridgetown-core/static_file.rb +3 -2
  55. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  56. data/lib/bridgetown-core/utils.rb +1 -1
  57. data/lib/bridgetown-core/version.rb +1 -1
  58. data/lib/bridgetown-core/watcher.rb +1 -0
  59. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  60. data/lib/site_template/bridgetown.config.yml +5 -1
  61. data/lib/site_template/config/.keep +0 -0
  62. data/lib/site_template/package.json.erb +8 -11
  63. data/lib/site_template/plugins/site_builder.rb +1 -1
  64. data/lib/site_template/src/_data/site_metadata.yml +1 -1
  65. metadata +12 -17
  66. data/lib/site_template/webpack.config.js.erb +0 -122
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ template "webpack.defaults.js.erb", "config/webpack.defaults.js"
4
+ copy_file "webpack.config.js", force: true
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Layout/LineLength
4
+
5
+ required_packages = %w(esbuild esbuild-loader webpack@5.39.1 webpack-cli@4.7.2 webpack-manifest-plugin@3.1.1)
6
+ redundant_packages = %w(@babel/core @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators @babel/plugin-transform-runtime @babel/preset-env babel-loader)
7
+
8
+ template "webpack.defaults.js.erb", "config/webpack.defaults.js", force: true
9
+ say "🎉 Webpack configuration updated successfully!"
10
+
11
+ return if Bridgetown.environment.test?
12
+
13
+ say "Installing required packages"
14
+ run "yarn add -D #{required_packages.join(" ")}"
15
+
16
+ packages_to_remove = package_json["devDependencies"].slice(*redundant_packages).keys
17
+ unless packages_to_remove.empty?
18
+ confirm = ask "\nThe following packages will be removed: \n\n#{packages_to_remove.join("\n")}\n\nWould you like to continue? [Yn]"
19
+ return unless confirm.casecmp?("Y")
20
+
21
+ run "yarn remove #{packages_to_remove.join(" ")}"
22
+ end
23
+
24
+ # rubocop:enable Layout/LineLength
@@ -0,0 +1,31 @@
1
+ const { merge } = require('webpack-merge')
2
+
3
+ var config = require("./config/webpack.defaults.js")
4
+
5
+ // Add any overrides to the default webpack config here:
6
+ //
7
+ // Eg:
8
+ //
9
+ // ```
10
+ // const path = require("path")
11
+ // config.resolve.modules.push(path.resolve(__dirname, 'frontend', 'components'))
12
+ // config.resolve.alias.frontendComponents = path.resolve(__dirname, 'frontend', 'components')
13
+ // ```
14
+ //
15
+ // You can also merge in a custom config using the included `webpack-merge` package.
16
+ // Complete docs available at: https://github.com/survivejs/webpack-merge
17
+ //
18
+ // Eg:
19
+ //
20
+ // ```
21
+ // const customConfig = { ..... }
22
+ // config = merge(config, customConfig)
23
+ // ```
24
+
25
+
26
+
27
+
28
+
29
+ ////////////////////////////////////////////////////////
30
+
31
+ module.exports = config
@@ -0,0 +1,130 @@
1
+ // This file is created and managed by Bridgetown.
2
+ // Instead of editing this file, add your overrides to `webpack.config.js`
3
+ //
4
+ // To update this file to the latest version provided by Bridgetown,
5
+ // run `bridgetown webpack update`. Any changes to this file will be overwritten
6
+ // when an update is applied hence we strongly recommend adding overrides to
7
+ // `webpack.config.js` instead of editing this file.
8
+ //
9
+ // Shipped with Bridgetown v<%= Bridgetown::VERSION %>
10
+
11
+ const path = require("path");
12
+ const rootDir = path.resolve(__dirname, "..")
13
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
14
+ const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
15
+
16
+ // Input and output
17
+
18
+ const entry = { main: path.resolve(rootDir, "frontend", "javascript", "index.js") }
19
+ const output = {
20
+ path: path.resolve(rootDir, "output", "_bridgetown", "static", "js"),
21
+ filename: "[name].[contenthash].js",
22
+ publicPath: "",
23
+ }
24
+
25
+ // Rules and Loaders
26
+
27
+ const jsRule = {
28
+ test: /\.(js|jsx)/,
29
+ use: {
30
+ loader: "esbuild-loader",
31
+ options: {
32
+ target: 'es2016'
33
+ },
34
+ },
35
+ }
36
+
37
+ const cssRules = {
38
+ test: /\.(s[ac]|c)ss$/,
39
+ use: [
40
+ MiniCssExtractPlugin.loader,
41
+ {
42
+ loader: "css-loader",
43
+ options: {
44
+ url: url => !url.startsWith('/'),
45
+ importLoaders: 1
46
+ }
47
+ }
48
+ ],
49
+ mode: '<%= self.config.uses_postcss? ? "postcss" : "sass" %>',
50
+
51
+ postcss: () => {
52
+ cssRules.use.push("postcss-loader")
53
+ return { test: cssRules.test, use: cssRules.use }
54
+ },
55
+
56
+ sass: () => {
57
+ cssRules.use.push({
58
+ loader: "sass-loader",
59
+ options: {
60
+ implementation: require("sass"),
61
+ sassOptions: {
62
+ fiber: false,
63
+ includePaths: [
64
+ path.resolve(rootDir, "src/_components")
65
+ ],
66
+ },
67
+ },
68
+ })
69
+ return { test: cssRules.test, use: cssRules.use }
70
+ }
71
+ }
72
+
73
+ const fontsRule = {
74
+ test: /\.woff2?$|\.ttf$|\.eot$/,
75
+ loader: "file-loader",
76
+ options: {
77
+ name: "[name]-[contenthash].[ext]",
78
+ outputPath: "../fonts",
79
+ publicPath: "../fonts",
80
+ },
81
+ }
82
+
83
+ const imagesRule = {
84
+ test: /\.png?$|\.gif$|\.jpg$|\.svg$/,
85
+ loader: "file-loader",
86
+ options: {
87
+ name: "[path][name]-[contenthash].[ext]",
88
+ outputPath: "../",
89
+ publicPath: "../",
90
+ },
91
+ }
92
+
93
+ // Default configuration object
94
+
95
+ module.exports = {
96
+ entry: entry,
97
+ devtool: "source-map",
98
+ // Set some or all of these to true if you want more verbose logging:
99
+ stats: {
100
+ modules: false,
101
+ builtAt: false,
102
+ timings: false,
103
+ children: false,
104
+ },
105
+ output: output,
106
+ resolve: {
107
+ extensions: [".js", ".jsx"],
108
+ modules: [
109
+ path.resolve(rootDir, 'frontend', 'javascript'),
110
+ path.resolve(rootDir, 'frontend', 'styles'),
111
+ path.resolve(rootDir, 'node_modules')
112
+ ],
113
+ alias: {
114
+ bridgetownComponents: path.resolve(rootDir, "src", "_components")
115
+ }
116
+ },
117
+ plugins: [
118
+ new MiniCssExtractPlugin({
119
+ filename: "../css/[name].[contenthash].css",
120
+ }),
121
+ new WebpackManifestPlugin({
122
+ fileName: path.resolve(rootDir, ".bridgetown-webpack", "manifest.json"),
123
+ }),
124
+ ],
125
+ module: {
126
+ rules: [
127
+ jsRule, cssRules[cssRules.mode](), fontsRule, imagesRule
128
+ ]
129
+ }
130
+ }
@@ -30,24 +30,24 @@ module Bridgetown
30
30
  #
31
31
  # @param ext [String] erb, slim, etc.
32
32
  def renderer_for_ext(ext, &block)
33
- case ext
34
- when "erb"
35
- include ERBCapture
36
- Tilt::ErubiTemplate.new(component_template_path,
37
- outvar: "@_erbout",
38
- bufval: "Bridgetown::OutputBuffer.new",
39
- engine_class: Bridgetown::ERBEngine,
40
- &block)
41
- when "serb" # requires serbea
42
- include Serbea::Helpers
43
- Tilt::SerbeaTemplate.new(component_template_path, &block)
44
- when "slim" # requires bridgetown-slim
45
- Slim::Template.new(component_template_path, &block)
46
- when "haml" # requires bridgetown-haml
47
- Tilt::HamlTemplate.new(component_template_path, &block)
48
- else
49
- raise NameError
50
- end
33
+ @_tmpl ||= case ext
34
+ when "erb"
35
+ include ERBCapture
36
+ Tilt::ErubiTemplate.new(component_template_path,
37
+ outvar: "@_erbout",
38
+ bufval: "Bridgetown::OutputBuffer.new",
39
+ engine_class: Bridgetown::ERBEngine,
40
+ &block)
41
+ when "serb" # requires serbea
42
+ include Serbea::Helpers
43
+ Tilt::SerbeaTemplate.new(component_template_path, &block)
44
+ when "slim" # requires bridgetown-slim
45
+ Slim::Template.new(component_template_path, &block)
46
+ when "haml" # requires bridgetown-haml
47
+ Tilt::HamlTemplate.new(component_template_path, &block)
48
+ else
49
+ raise NameError
50
+ end
51
51
  rescue NameError, LoadError
52
52
  raise "No component rendering engine could be found for .#{ext} templates"
53
53
  end
@@ -56,26 +56,32 @@ module Bridgetown
56
56
  #
57
57
  # @return [String]
58
58
  def component_template_path
59
- stripped_path = File.join(
60
- File.dirname(source_location),
61
- File.basename(source_location, ".*")
62
- )
63
- supported_template_extensions.each do |ext|
64
- test_path = "#{stripped_path}.#{ext}"
65
- return test_path if File.exist?(test_path)
66
-
67
- test_path = "#{stripped_path}.html.#{ext}"
68
- return test_path if File.exist?(test_path)
59
+ @_tmpl_path ||= begin
60
+ stripped_path = File.join(
61
+ File.dirname(source_location),
62
+ File.basename(source_location, ".*")
63
+ )
64
+ supported_template_extensions.each do |ext|
65
+ test_path = "#{stripped_path}.#{ext}"
66
+ break test_path if File.exist?(test_path)
67
+
68
+ test_path = "#{stripped_path}.html.#{ext}"
69
+ break test_path if File.exist?(test_path)
70
+ end
71
+ end
72
+
73
+ unless @_tmpl_path.is_a?(String)
74
+ raise "#{name}: no matching template could be found in #{File.dirname(source_location)}"
69
75
  end
70
76
 
71
- raise "No matching templates could be found in #{File.dirname(source_location)}"
77
+ @_tmpl_path
72
78
  end
73
79
 
74
80
  # Read the template file.
75
81
  #
76
82
  # @return [String]
77
83
  def component_template_content
78
- File.read(component_template_path)
84
+ @_tmpl_content ||= File.read(component_template_path)
79
85
  end
80
86
 
81
87
  # A list of extensions supported by the renderer
@@ -154,7 +160,6 @@ module Bridgetown
154
160
  end
155
161
 
156
162
  def _renderer
157
- # TODO: figure out a way to compile templates for increased performance
158
163
  @_renderer ||= begin
159
164
  ext = File.extname(self.class.component_template_path).delete_prefix(".")
160
165
  self.class.renderer_for_ext(ext) { self.class.component_template_content }
@@ -25,7 +25,7 @@ module Bridgetown
25
25
  if yaml_content
26
26
  self.content = yaml_content.post_match
27
27
  self.front_matter_line_count = yaml_content[1].lines.size - 1
28
- SafeYAML.load(yaml_content[1])
28
+ YAMLParser.load(yaml_content[1])
29
29
  elsif ruby_content
30
30
  # rbfm header + content underneath
31
31
  self.content = ruby_content.post_match
@@ -37,7 +37,7 @@ module Bridgetown
37
37
  self.content = file_contents
38
38
  {}
39
39
  else
40
- yaml_data = SafeYAML.load_file(file_path)
40
+ yaml_data = YAMLParser.load_file(file_path)
41
41
  yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data
42
42
  end
43
43
  end
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  end
12
12
 
13
13
  def no_layout?
14
- data["layout"] == "none" || data["layout"] == false
14
+ data.layout.nil? || data.layout == "none" || data.layout == false
15
15
  end
16
16
  end
17
17
  end
@@ -18,12 +18,6 @@ class Bridgetown::Site
18
18
  @root_dir = File.expand_path(config["root_dir"]).freeze
19
19
  @source = File.expand_path(config["source"]).freeze
20
20
  @dest = File.expand_path(config["destination"]).freeze
21
- @cache_dir = in_root_dir(config["cache_dir"]).freeze
22
-
23
- %w(lsi highlighter baseurl exclude include future unpublished
24
- limit_posts keep_files).each do |opt|
25
- send("#{opt}=", config[opt])
26
- end
27
21
 
28
22
  configure_cache
29
23
  configure_component_paths
@@ -39,6 +33,22 @@ class Bridgetown::Site
39
33
  config[:content_engine] == "resource"
40
34
  end
41
35
 
36
+ # Returns a base path from which the site is served (aka `/cool-site`) or
37
+ # `/` if served from root.
38
+ #
39
+ # @param strip_slash_only [Boolean] set to true if you wish "/" to be returned as ""
40
+ # @return [String]
41
+ def base_path(strip_slash_only: false)
42
+ (config[:base_path] || config[:baseurl]).yield_self do |path|
43
+ strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path
44
+ end
45
+ end
46
+
47
+ def baseurl
48
+ Bridgetown::Deprecator.deprecation_message "Site#baseurl is now Site#base_path"
49
+ base_path(strip_slash_only: true).presence
50
+ end
51
+
42
52
  def defaults_reader
43
53
  @defaults_reader ||= Bridgetown::DefaultsReader.new(self)
44
54
  end
@@ -153,7 +163,8 @@ class Bridgetown::Site
153
163
 
154
164
  # Disable Marshaling cache to disk in Safe Mode
155
165
  def configure_cache
156
- Bridgetown::Cache.cache_dir = in_root_dir(config["cache_dir"], "Bridgetown/Cache")
166
+ @cache_dir = in_root_dir(config["cache_dir"]).freeze
167
+ Bridgetown::Cache.cache_dir = File.join(cache_dir, "Bridgetown/Cache")
157
168
  Bridgetown::Cache.disable_disk_cache! if config["disable_disk_cache"]
158
169
  end
159
170
 
@@ -5,13 +5,11 @@ class Bridgetown::Site
5
5
  # Returns the current and/or default configured locale
6
6
  # @return String
7
7
  def locale
8
- if @locale
9
- @locale
10
- else
11
- @locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
8
+ @locale ||= begin
9
+ locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
12
10
  I18n.load_path << Dir[in_source_dir("_locales") + "/*.yml"]
13
11
  I18n.available_locales = config[:available_locales]
14
- I18n.default_locale = @locale
12
+ I18n.default_locale = locale
15
13
  end
16
14
  end
17
15
 
@@ -42,8 +42,6 @@ class Bridgetown::Site
42
42
  @liquid_renderer.reset
43
43
  frontmatter_defaults.reset
44
44
 
45
- raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative?
46
-
47
45
  Bridgetown::Cache.clear_if_config_changed config
48
46
  Bridgetown::Hooks.trigger :site, :after_reset, self
49
47
  end
@@ -61,8 +59,11 @@ class Bridgetown::Site
61
59
 
62
60
  # Limits the current posts; removes the posts which exceed the limit_posts
63
61
  def limit_posts!
64
- if limit_posts.positive?
65
- limit = posts.docs.length < limit_posts ? posts.docs.length : 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
66
67
  posts.docs = posts.docs[-limit, limit]
67
68
  end
68
69
  end
@@ -19,7 +19,7 @@ module Bridgetown
19
19
  **Utils.merged_file_read_opts(site, opts))
20
20
  if content =~ Document::YAML_FRONT_MATTER_REGEXP
21
21
  self.content = $POSTMATCH
22
- self.data = SafeYAML.load(Regexp.last_match(1))&.with_dot_access
22
+ self.data = YAMLParser.load(Regexp.last_match(1))&.with_dot_access
23
23
  end
24
24
  rescue Psych::SyntaxError => e
25
25
  Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
@@ -54,7 +54,7 @@ module Bridgetown
54
54
  "detach" => false, # default to not detaching the server
55
55
  "port" => "4000",
56
56
  "host" => "127.0.0.1",
57
- "baseurl" => nil, # this mounts at /, i.e. no subdirectory
57
+ "base_path" => "/",
58
58
  "show_dir_listing" => false,
59
59
 
60
60
  # Output Configuration
@@ -118,7 +118,7 @@ module Bridgetown
118
118
  # override - the command-line options hash
119
119
  #
120
120
  # Returns the path to the Bridgetown root directory
121
- def root_dir(override)
121
+ def root_dir(override = "")
122
122
  get_config_value_with_override("root_dir", override)
123
123
  end
124
124
 
@@ -127,7 +127,7 @@ module Bridgetown
127
127
  # override - the command-line options hash
128
128
  #
129
129
  # Returns the path to the Bridgetown source directory
130
- def source(override)
130
+ def source(override = "")
131
131
  get_config_value_with_override("source", override)
132
132
  end
133
133
 
@@ -147,7 +147,7 @@ module Bridgetown
147
147
  Bridgetown::Utils::RequireGems.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
148
148
  Tomlrb.load_file(filename)
149
149
  when %r!\.ya?ml!i
150
- SafeYAML.load_file(filename) || {}
150
+ YAMLParser.load_file(filename) || {}
151
151
  else
152
152
  raise ArgumentError,
153
153
  "No parser for '#{filename}' is available. Use a .y(a)ml or .toml file instead."
@@ -226,7 +226,7 @@ module Bridgetown
226
226
  raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
227
227
  end
228
228
 
229
- Bridgetown.logger.info "Configuration file:", file
229
+ Bridgetown.logger.debug "Configuration file:", file
230
230
  next_config
231
231
  rescue SystemCallError
232
232
  if @default_config_file ||= nil
@@ -340,5 +340,12 @@ module Bridgetown
340
340
 
341
341
  self
342
342
  end
343
+
344
+ # Whether or not PostCSS is being used to process stylesheets.
345
+ #
346
+ # @return [Boolean] true if `postcss.config.js` exists, false if not
347
+ def uses_postcss?
348
+ File.exist?(Bridgetown.sanitized_path(root_dir, "postcss.config.js"))
349
+ end
343
350
  end
344
351
  end