bridgetown-core 0.21.0.beta2 → 0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +0 -1
- data/lib/bridgetown-core.rb +16 -15
- data/lib/bridgetown-core/cleaner.rb +2 -2
- data/lib/bridgetown-core/collection.rb +13 -8
- data/lib/bridgetown-core/commands/concerns/build_options.rb +2 -2
- 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/new.rb +6 -6
- data/lib/bridgetown-core/commands/plugins.rb +14 -13
- data/lib/bridgetown-core/commands/serve.rb +1 -1
- data/lib/bridgetown-core/commands/webpack.rb +82 -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 +24 -0
- data/lib/bridgetown-core/commands/webpack/webpack.config.js +31 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +130 -0
- data/lib/bridgetown-core/component.rb +36 -31
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +2 -2
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +18 -7
- 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/validatable.rb +1 -1
- data/lib/bridgetown-core/configuration.rb +12 -5
- 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 +14 -9
- data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +2 -2
- data/lib/bridgetown-core/converters/erb_templates.rb +1 -1
- data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
- data/lib/bridgetown-core/core_ext/psych.rb +19 -0
- data/lib/bridgetown-core/document.rb +2 -2
- data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
- data/lib/bridgetown-core/drops/site_drop.rb +2 -0
- data/lib/bridgetown-core/entry_filter.rb +5 -3
- data/lib/bridgetown-core/filters/url_filters.rb +4 -8
- data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +25 -4
- data/lib/bridgetown-core/layout.rb +27 -10
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/publisher.rb +2 -2
- data/lib/bridgetown-core/reader.rb +1 -1
- data/lib/bridgetown-core/readers/data_reader.rb +1 -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/regenerator.rb +1 -1
- data/lib/bridgetown-core/related_posts.rb +5 -2
- data/lib/bridgetown-core/resource/base.rb +29 -7
- data/lib/bridgetown-core/resource/destination.rb +3 -1
- data/lib/bridgetown-core/resource/permalink_processor.rb +7 -3
- data/lib/bridgetown-core/resource/transformer.rb +4 -2
- data/lib/bridgetown-core/site.rb +4 -5
- data/lib/bridgetown-core/static_file.rb +3 -2
- data/lib/bridgetown-core/tags/highlight.rb +2 -15
- data/lib/bridgetown-core/utils.rb +1 -1
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/watcher.rb +1 -0
- data/lib/bridgetown-core/yaml_parser.rb +22 -0
- data/lib/site_template/bridgetown.config.yml +5 -1
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/package.json.erb +8 -11
- data/lib/site_template/plugins/site_builder.rb +1 -1
- data/lib/site_template/src/_data/site_metadata.yml +1 -1
- metadata +12 -17
- data/lib/site_template/webpack.config.js.erb +0 -122
@@ -4,23 +4,23 @@
|
|
4
4
|
|
5
5
|
TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
|
6
6
|
|
7
|
-
|
8
|
-
find_in_source_paths("postcss.config.js")
|
9
|
-
rescue Thor::Error
|
7
|
+
unless File.exist?("postcss.config.js")
|
10
8
|
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
11
9
|
|
12
10
|
@logger.error "\nError:".red, "🚨 #{error_message}"
|
13
|
-
@logger.info "\
|
11
|
+
@logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
|
14
12
|
|
15
13
|
return
|
16
14
|
end
|
17
15
|
|
16
|
+
confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
|
17
|
+
return unless confirm.casecmp?("Y")
|
18
|
+
|
18
19
|
plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
|
19
20
|
|
20
21
|
say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
|
21
22
|
run "yarn add -D #{plugins.join(' ')}"
|
22
23
|
|
23
|
-
|
24
|
-
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
|
24
|
+
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
|
25
25
|
|
26
26
|
# rubocop:enable all
|
@@ -4,26 +4,31 @@
|
|
4
4
|
|
5
5
|
TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
|
6
6
|
|
7
|
-
|
8
|
-
find_in_source_paths("postcss.config.js")
|
9
|
-
rescue Thor::Error
|
7
|
+
unless File.exist?("postcss.config.js")
|
10
8
|
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
11
9
|
|
12
10
|
@logger.error "\nError:".red, "🚨 #{error_message}"
|
13
|
-
@logger.info "\
|
11
|
+
@logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
|
14
12
|
|
15
13
|
return
|
16
14
|
end
|
17
15
|
|
16
|
+
confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
|
17
|
+
return unless confirm.casecmp?("Y")
|
18
|
+
|
18
19
|
run "yarn add -D tailwindcss"
|
19
20
|
run "npx tailwindcss init"
|
20
21
|
|
21
|
-
|
22
|
-
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
|
23
|
-
|
24
|
-
prepend_to_file "frontend/styles/index.css",
|
25
|
-
File.read("#{TEMPLATE_PATH}/css_imports.css")
|
22
|
+
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
|
26
23
|
|
27
24
|
run "bundle exec bridgetown configure purgecss"
|
28
25
|
|
26
|
+
if File.exist?("frontend/styles/index.css")
|
27
|
+
prepend_to_file "frontend/styles/index.css",
|
28
|
+
File.read("#{TEMPLATE_PATH}/css_imports.css")
|
29
|
+
else
|
30
|
+
say "\nPlease add the following lines to your CSS index file:"
|
31
|
+
say File.read("#{TEMPLATE_PATH}/css_imports.css")
|
32
|
+
end
|
33
|
+
|
29
34
|
# rubocop:enable all
|
@@ -104,7 +104,7 @@ 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
|
-
# @
|
107
|
+
# @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
|
108
108
|
# The instantiated object which is processing the file.
|
109
109
|
#
|
110
110
|
# @return [String] The converted content.
|
@@ -18,7 +18,7 @@ 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
|
-
# @
|
21
|
+
# @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
|
22
22
|
# The instantiated object which is processing the file.
|
23
23
|
#
|
24
24
|
# @return [String] The converted content.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module CoreExt
|
5
|
+
module Psych
|
6
|
+
module SafeLoadFile
|
7
|
+
def safe_load_file(filename, **kwargs)
|
8
|
+
File.open(filename, "r:bom|utf-8") do |f|
|
9
|
+
if RUBY_VERSION.start_with?("2.5")
|
10
|
+
safe_load f, kwargs[:permitted_classes], [], false, filename
|
11
|
+
else
|
12
|
+
safe_load f, filename: filename, **kwargs
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -224,7 +224,7 @@ module Bridgetown
|
|
224
224
|
Bridgetown.logger.debug "Reading:", relative_path
|
225
225
|
|
226
226
|
if yaml_file?
|
227
|
-
@data =
|
227
|
+
@data = YAMLParser.load_file(path)
|
228
228
|
else
|
229
229
|
begin
|
230
230
|
merge_defaults
|
@@ -358,7 +358,7 @@ module Bridgetown
|
|
358
358
|
self.content = File.read(path, **Utils.merged_file_read_opts(site, opts))
|
359
359
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
360
360
|
self.content = $POSTMATCH
|
361
|
-
data_file =
|
361
|
+
data_file = YAMLParser.load(Regexp.last_match(1))
|
362
362
|
merge_data!(data_file, source: "YAML front matter") if data_file
|
363
363
|
end
|
364
364
|
end
|
@@ -17,6 +17,7 @@ module Bridgetown
|
|
17
17
|
:data,
|
18
18
|
:output,
|
19
19
|
:content,
|
20
|
+
:summary,
|
20
21
|
:to_s,
|
21
22
|
:absolute_url,
|
22
23
|
:relative_path,
|
@@ -48,7 +49,7 @@ module Bridgetown
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def next
|
51
|
-
@next ||= @obj.
|
52
|
+
@next ||= @obj.next_resource.to_liquid
|
52
53
|
end
|
53
54
|
|
54
55
|
# Generate a Hash for use in generating JSON.
|
@@ -43,8 +43,8 @@ module Bridgetown
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def included?(entry)
|
46
|
-
glob_include?(site.include, entry) ||
|
47
|
-
glob_include?(site.include, File.basename(entry))
|
46
|
+
glob_include?(site.config.include, entry) ||
|
47
|
+
glob_include?(site.config.include, File.basename(entry))
|
48
48
|
end
|
49
49
|
|
50
50
|
def special?(entry)
|
@@ -62,7 +62,9 @@ module Bridgetown
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def excluded?(entry)
|
65
|
-
glob_include?(
|
65
|
+
glob_include?(
|
66
|
+
site.config.exclude - site.config.include, relative_to_source(entry)
|
67
|
+
).tap do |excluded|
|
66
68
|
if excluded
|
67
69
|
Bridgetown.logger.debug(
|
68
70
|
"EntryFilter:",
|
@@ -5,7 +5,7 @@ module Bridgetown
|
|
5
5
|
module URLFilters
|
6
6
|
extend self
|
7
7
|
|
8
|
-
# Produces an absolute URL based on site.url and site.
|
8
|
+
# Produces an absolute URL based on site.url and site.base_path.
|
9
9
|
#
|
10
10
|
# input - the URL to make absolute.
|
11
11
|
#
|
@@ -15,7 +15,7 @@ module Bridgetown
|
|
15
15
|
cache[input] ||= compute_absolute_url(input)
|
16
16
|
end
|
17
17
|
|
18
|
-
# Produces a URL relative to the domain root based on site.
|
18
|
+
# Produces a URL relative to the domain root based on site.base_path
|
19
19
|
# unless it is already an absolute url with an authority (host).
|
20
20
|
#
|
21
21
|
# input - the URL to make relative to the domain root
|
@@ -70,17 +70,13 @@ module Bridgetown
|
|
70
70
|
input = input.url if input.respond_to?(:url)
|
71
71
|
return input if Addressable::URI.parse(input.to_s).absolute?
|
72
72
|
|
73
|
-
|
73
|
+
site = @context.registers[:site]
|
74
|
+
parts = [site.base_path.chomp("/"), input]
|
74
75
|
Addressable::URI.parse(
|
75
76
|
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
|
76
77
|
).normalize.to_s
|
77
78
|
end
|
78
79
|
|
79
|
-
def sanitized_baseurl
|
80
|
-
site = @context.registers[:site]
|
81
|
-
site.config["baseurl"].to_s.chomp("/")
|
82
|
-
end
|
83
|
-
|
84
80
|
def ensure_leading_slash(input)
|
85
81
|
return input if input.nil? || input.empty? || input.start_with?("/")
|
86
82
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Handles
|
3
|
+
# Handles Generated Pages
|
4
4
|
Bridgetown::Hooks.register :pages, :post_init, reloadable: false do |page|
|
5
5
|
if page.class != Bridgetown::PrototypePage && page.data["prototype"].is_a?(Hash)
|
6
6
|
Bridgetown::PrototypeGenerator.add_matching_template(page)
|
@@ -14,6 +14,11 @@ Bridgetown::Hooks.register :resources, :post_read, reloadable: false do |resourc
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Ensure sites clear out templates before rebuild
|
18
|
+
Bridgetown::Hooks.register :site, :after_reset, reloadable: false do |_site|
|
19
|
+
Bridgetown::PrototypeGenerator.matching_templates.clear
|
20
|
+
end
|
21
|
+
|
17
22
|
module Bridgetown
|
18
23
|
class PrototypeGenerator < Generator
|
19
24
|
priority :low
|
@@ -21,9 +26,9 @@ module Bridgetown
|
|
21
26
|
# @return [Bridgetown::Site]
|
22
27
|
attr_reader :site
|
23
28
|
|
24
|
-
# @return [
|
29
|
+
# @return [Set<Bridgetown::Page, Bridgetown::Resource::Base>]
|
25
30
|
def self.matching_templates
|
26
|
-
@matching_templates ||=
|
31
|
+
@matching_templates ||= Set.new
|
27
32
|
end
|
28
33
|
|
29
34
|
def self.add_matching_template(template)
|
@@ -41,6 +46,8 @@ module Bridgetown
|
|
41
46
|
end
|
42
47
|
|
43
48
|
if prototype_pages.length.positive?
|
49
|
+
ensure_pagination_enabled
|
50
|
+
|
44
51
|
page_list.reject! do |page|
|
45
52
|
prototype_pages.include? page
|
46
53
|
end
|
@@ -56,6 +63,15 @@ module Bridgetown
|
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
def ensure_pagination_enabled
|
67
|
+
unless @site.config.dig(:pagination, :enabled)
|
68
|
+
Bridgetown.logger.warn(
|
69
|
+
"Pagination:",
|
70
|
+
"Must be enabled for prototype pages to contain matches"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
59
75
|
# Check incoming prototype configuration and normalize options.
|
60
76
|
#
|
61
77
|
# @param prototype_page [Bridgetown::Page, Bridgetown::Resource::Base]
|
@@ -70,7 +86,12 @@ module Bridgetown
|
|
70
86
|
@configured_collection = prototype_page.data["prototype"]["collection"]
|
71
87
|
end
|
72
88
|
|
73
|
-
|
89
|
+
unless site.collections[@configured_collection]
|
90
|
+
Bridgetown.logger.warn(
|
91
|
+
"No collection specified for prototype page #{prototype_page.relative_path}"
|
92
|
+
)
|
93
|
+
return nil
|
94
|
+
end
|
74
95
|
|
75
96
|
# Categories and Tags are unique in that singular and plural front matter
|
76
97
|
# can be present for each
|
@@ -39,12 +39,22 @@ module Bridgetown
|
|
39
39
|
# Gets/Sets the document output (for layout-compatible converters)
|
40
40
|
attr_accessor :current_document_output
|
41
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
|
+
|
42
52
|
# Initialize a new Layout.
|
43
53
|
#
|
44
|
-
# site
|
45
|
-
# base
|
46
|
-
# name
|
47
|
-
# 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.
|
48
58
|
def initialize(site, base, name, from_plugin: false)
|
49
59
|
@site = site
|
50
60
|
@base = base
|
@@ -83,17 +93,24 @@ module Bridgetown
|
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
86
|
-
# The
|
87
|
-
#
|
96
|
+
# The label of the layout (should match what would used in front matter
|
97
|
+
# references).
|
88
98
|
#
|
89
|
-
#
|
99
|
+
# @return [String]
|
100
|
+
def label
|
101
|
+
@label ||= self.class.label_for_file(name)
|
102
|
+
end
|
103
|
+
|
104
|
+
# The inspect string for this layout. Includes the relative path.
|
105
|
+
#
|
106
|
+
# @return [String]
|
90
107
|
def inspect
|
91
|
-
"#<#{self.class} #{
|
108
|
+
"#<#{self.class} #{relative_path}>"
|
92
109
|
end
|
93
110
|
|
94
|
-
# Provide this Layout's data
|
111
|
+
# Provide this Layout's data for use by Liquid.
|
95
112
|
#
|
96
|
-
#
|
113
|
+
# @return [HashWithDotAccess::Hash]
|
97
114
|
def to_liquid
|
98
115
|
data
|
99
116
|
end
|
@@ -102,7 +102,7 @@ module Bridgetown
|
|
102
102
|
when ".rb"
|
103
103
|
process_ruby_data(File.read(original_path), original_path, 1)
|
104
104
|
else
|
105
|
-
yaml_data =
|
105
|
+
yaml_data = YAMLParser.load_file(original_path)
|
106
106
|
yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data
|
107
107
|
end
|
108
108
|
end
|
@@ -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
|
@@ -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
|