bridgetown-core 0.21.0.beta2 → 0.21.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +0 -1
- data/lib/bridgetown-core.rb +6 -14
- data/lib/bridgetown-core/cleaner.rb +2 -2
- data/lib/bridgetown-core/collection.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 +2 -2
- data/lib/bridgetown-core/commands/plugins.rb +14 -13
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +2 -2
- data/lib/bridgetown-core/concerns/site/configurable.rb +3 -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 +1 -1
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
- data/lib/bridgetown-core/configurations/netlify.rb +1 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +1 -3
- 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/entry_filter.rb +5 -3
- data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
- 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/regenerator.rb +1 -1
- data/lib/bridgetown-core/related_posts.rb +5 -2
- data/lib/bridgetown-core/resource/base.rb +3 -7
- data/lib/bridgetown-core/resource/transformer.rb +4 -2
- data/lib/bridgetown-core/site.rb +4 -5
- data/lib/bridgetown-core/tags/highlight.rb +2 -15
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/yaml_parser.rb +22 -0
- data/lib/site_template/plugins/site_builder.rb +1 -1
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc153d4826e8e0678bea76a9e2c251040123418ab9cfe0b1243b7f38cb8f1ec5
|
4
|
+
data.tar.gz: '08d6c10878993b10963dc1a89058c8b0a9dbd57a5ed2b399963a68ea537ea5f8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7151ae352509556c2b6b7e524e56186a3c782746dc1f2090756a37e9325c9153e48a03daf720e64fd0450e472a43b96c3e9b90ec53896d409881ab33b8aabea0
|
7
|
+
data.tar.gz: 42289c4f1da1116e37fa50bdb49345264e2a56a719f1e76691eb294721a1b4c834909ab7dc22691d238bec4df509c6680c479fa7b6fec8831f69d79bee8fef6b
|
data/bridgetown-core.gemspec
CHANGED
@@ -47,7 +47,6 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.add_runtime_dependency("liquid-component", ">= 0.1")
|
48
48
|
s.add_runtime_dependency("listen", "~> 3.0")
|
49
49
|
s.add_runtime_dependency("rouge", "~> 3.0")
|
50
|
-
s.add_runtime_dependency("safe_yaml", "~> 1.0")
|
51
50
|
s.add_runtime_dependency("terminal-table", "~> 1.8")
|
52
51
|
s.add_runtime_dependency("thor", "~> 1.1")
|
53
52
|
s.add_runtime_dependency("tilt", "~> 2.0")
|
data/lib/bridgetown-core.rb
CHANGED
@@ -28,6 +28,7 @@ require "logger"
|
|
28
28
|
require "set"
|
29
29
|
require "csv"
|
30
30
|
require "json"
|
31
|
+
require "yaml"
|
31
32
|
|
32
33
|
# 3rd party
|
33
34
|
require "active_support"
|
@@ -44,7 +45,6 @@ require "active_support/current_attributes"
|
|
44
45
|
require "active_support/descendants_tracker"
|
45
46
|
require "hash_with_dot_access"
|
46
47
|
require "addressable/uri"
|
47
|
-
require "safe_yaml/load"
|
48
48
|
require "liquid"
|
49
49
|
require "liquid-component"
|
50
50
|
require "kramdown"
|
@@ -62,21 +62,8 @@ module HashWithDotAccess
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
SafeYAML::OPTIONS[:suppress_warnings] = true
|
66
|
-
|
67
65
|
# Create our little String subclass for Ruby Front Matter
|
68
66
|
class Rb < String; end
|
69
|
-
SafeYAML::OPTIONS[:whitelisted_tags] = ["!ruby/string:Rb"]
|
70
|
-
|
71
|
-
if RUBY_VERSION.start_with?("3.0")
|
72
|
-
# workaround for Ruby 3 preview 2, maybe can remove later
|
73
|
-
# rubocop:disable Style/GlobalVars
|
74
|
-
old_verbose = $VERBOSE
|
75
|
-
$VERBOSE = nil
|
76
|
-
SafeYAML::SafeToRubyVisitor.const_set(:INITIALIZE_ARITY, 2)
|
77
|
-
$verbose = old_verbose
|
78
|
-
# rubocop:enable Style/GlobalVars
|
79
|
-
end
|
80
67
|
|
81
68
|
module Bridgetown
|
82
69
|
autoload :Cleaner, "bridgetown-core/cleaner"
|
@@ -128,6 +115,7 @@ module Bridgetown
|
|
128
115
|
autoload :Validatable, "bridgetown-core/concerns/validatable"
|
129
116
|
autoload :VERSION, "bridgetown-core/version"
|
130
117
|
autoload :Watcher, "bridgetown-core/watcher"
|
118
|
+
autoload :YAMLParser, "bridgetown-core/yaml_parser"
|
131
119
|
|
132
120
|
# extensions
|
133
121
|
require "bridgetown-core/commands/registrations"
|
@@ -145,6 +133,7 @@ module Bridgetown
|
|
145
133
|
require_all "bridgetown-core/drops"
|
146
134
|
require_all "bridgetown-core/generators"
|
147
135
|
require_all "bridgetown-core/tags"
|
136
|
+
require_all "bridgetown-core/core_ext"
|
148
137
|
|
149
138
|
class << self
|
150
139
|
# Tells you which Bridgetown environment you are building in so
|
@@ -271,6 +260,9 @@ module Bridgetown
|
|
271
260
|
module Resource; end
|
272
261
|
end
|
273
262
|
|
263
|
+
# This method is available in Ruby 3, monkey patching for older versions
|
264
|
+
Psych.extend Bridgetown::CoreExt::Psych::SafeLoadFile unless Psych.respond_to?(:safe_load_file)
|
265
|
+
|
274
266
|
loader = Zeitwerk::Loader.new
|
275
267
|
loader.push_dir File.join(__dir__, "bridgetown-core/model"), namespace: Bridgetown::Model
|
276
268
|
loader.push_dir File.join(__dir__, "bridgetown-core/resource"), namespace: Bridgetown::Resource
|
@@ -101,7 +101,7 @@ module Bridgetown
|
|
101
101
|
#
|
102
102
|
# Returns a Set with the directory paths
|
103
103
|
def keep_dirs
|
104
|
-
site.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
104
|
+
site.config.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
105
105
|
end
|
106
106
|
|
107
107
|
# Private: Creates a regular expression from the config's keep_files array
|
@@ -112,7 +112,7 @@ module Bridgetown
|
|
112
112
|
#
|
113
113
|
# Returns the regular expression
|
114
114
|
def keep_file_regex
|
115
|
-
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})!
|
115
|
+
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.config.keep_files).source})!
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -287,7 +287,7 @@ module Bridgetown
|
|
287
287
|
Pathname(full_path).relative_path_from(Pathname(site.source)).to_s
|
288
288
|
)
|
289
289
|
resource = Bridgetown::Model::Base.find(id).to_resource.read!
|
290
|
-
resources << resource if site.unpublished || resource.published?
|
290
|
+
resources << resource if site.config.unpublished || resource.published?
|
291
291
|
end
|
292
292
|
|
293
293
|
private
|
@@ -298,7 +298,7 @@ module Bridgetown
|
|
298
298
|
|
299
299
|
def read_document(full_path)
|
300
300
|
doc = Document.new(full_path, site: site, collection: self).tap(&:read)
|
301
|
-
docs << doc if site.unpublished || doc.published?
|
301
|
+
docs << doc if site.config.unpublished || doc.published?
|
302
302
|
end
|
303
303
|
|
304
304
|
def sort_docs!
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Commands
|
5
|
+
module GitHelpers
|
6
|
+
def initialize_new_repo
|
7
|
+
run "git init", abort_on_failure: true
|
8
|
+
`git symbolic-ref HEAD refs/heads/main` if user_default_branch.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy_existing_repo
|
12
|
+
run "rm -rf .git"
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_default_branch
|
16
|
+
@user_default_branch ||= `git config init.defaultbranch`.strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,6 +4,7 @@ module Bridgetown
|
|
4
4
|
module Commands
|
5
5
|
class Configure < Thor::Group
|
6
6
|
include Thor::Actions
|
7
|
+
include Actions
|
7
8
|
extend Summarizable
|
8
9
|
|
9
10
|
Registrations.register do
|
@@ -20,13 +21,13 @@ module Bridgetown
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def perform_configurations
|
23
|
-
logger = Bridgetown.logger
|
24
|
+
@logger = Bridgetown.logger
|
24
25
|
list_configurations if args.empty?
|
25
26
|
|
26
27
|
args.each do |configuration|
|
27
28
|
configure configuration
|
28
29
|
rescue Thor::Error
|
29
|
-
logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
|
30
|
+
@logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -40,7 +41,7 @@ module Bridgetown
|
|
40
41
|
configuration_file = find_in_source_paths("#{configuration}.rb")
|
41
42
|
|
42
43
|
inside(New.created_site_dir || Dir.pwd) do
|
43
|
-
|
44
|
+
apply configuration_file, verbose: false
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -4,6 +4,7 @@ module Bridgetown
|
|
4
4
|
module Commands
|
5
5
|
class New < Thor::Group
|
6
6
|
include Thor::Actions
|
7
|
+
include GitHelpers
|
7
8
|
extend Summarizable
|
8
9
|
|
9
10
|
Registrations.register do
|
@@ -157,8 +158,7 @@ module Bridgetown
|
|
157
158
|
def git_init(path)
|
158
159
|
unless Bridgetown.environment == "test"
|
159
160
|
inside(path) do
|
160
|
-
|
161
|
-
run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
|
161
|
+
initialize_new_repo
|
162
162
|
end
|
163
163
|
end
|
164
164
|
rescue SystemExit
|
@@ -5,6 +5,7 @@ module Bridgetown
|
|
5
5
|
class Plugins < Thor
|
6
6
|
include Thor::Actions
|
7
7
|
include ConfigurationOverridable
|
8
|
+
include GitHelpers
|
8
9
|
|
9
10
|
Registrations.register do
|
10
11
|
desc "plugins <command>", "List installed plugins or access plugin content"
|
@@ -144,15 +145,15 @@ module Bridgetown
|
|
144
145
|
name = folder_name.dasherize
|
145
146
|
module_name = folder_name.camelize
|
146
147
|
|
147
|
-
|
148
|
+
# TODO: upon 0.21 release, remove the explicit branch name!
|
149
|
+
run "git clone -b switch-to-minitest https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
|
148
150
|
new_gemspec = "#{name}.gemspec"
|
149
151
|
|
150
152
|
inside name do # rubocop:todo Metrics/BlockLength
|
151
|
-
|
152
|
-
|
153
|
-
run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
|
153
|
+
destroy_existing_repo
|
154
|
+
initialize_new_repo
|
154
155
|
|
155
|
-
|
156
|
+
FileUtils.mv "bridgetown-sample-plugin.gemspec", new_gemspec.to_s
|
156
157
|
gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
157
158
|
gsub_file new_gemspec, "bridgetown-sample-plugin", name
|
158
159
|
gsub_file new_gemspec, "sample-plugin", name
|
@@ -161,21 +162,21 @@ module Bridgetown
|
|
161
162
|
gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
162
163
|
gsub_file "package.json", "bridgetown-sample-plugin", name
|
163
164
|
|
164
|
-
|
165
|
+
FileUtils.mv "lib/sample-plugin.rb", "lib/#{name}.rb"
|
165
166
|
gsub_file "lib/#{name}.rb", "sample-plugin", name
|
166
167
|
gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
|
167
168
|
|
168
|
-
|
169
|
+
FileUtils.mv "lib/sample-plugin", "lib/#{name}"
|
169
170
|
gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
|
170
171
|
gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
|
171
172
|
|
172
|
-
|
173
|
-
gsub_file "
|
174
|
-
gsub_file "
|
173
|
+
FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
|
174
|
+
gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
|
175
|
+
gsub_file "test/helper.rb", "sample-plugin", name
|
175
176
|
|
176
|
-
|
177
|
-
|
178
|
-
|
177
|
+
FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
|
178
|
+
FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
|
179
|
+
FileUtils.mv "layouts/sample_plugin", "layouts/#{folder_name}"
|
179
180
|
|
180
181
|
gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
|
181
182
|
gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
|
@@ -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
|
-
|
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 =
|
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
|
@@ -18,18 +18,13 @@ 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
|
30
24
|
configure_include_paths
|
31
25
|
configure_file_read_opts
|
32
26
|
|
27
|
+
self.baseurl = config.baseurl
|
33
28
|
self.permalink_style = (config["permalink"] || "pretty").to_sym
|
34
29
|
|
35
30
|
@config
|
@@ -153,7 +148,8 @@ class Bridgetown::Site
|
|
153
148
|
|
154
149
|
# Disable Marshaling cache to disk in Safe Mode
|
155
150
|
def configure_cache
|
156
|
-
|
151
|
+
@cache_dir = in_root_dir(config["cache_dir"]).freeze
|
152
|
+
Bridgetown::Cache.cache_dir = File.join(cache_dir, "Bridgetown/Cache")
|
157
153
|
Bridgetown::Cache.disable_disk_cache! if config["disable_disk_cache"]
|
158
154
|
end
|
159
155
|
|
@@ -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
|
-
|
9
|
-
|
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 =
|
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
|
-
|
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 =
|
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}"
|
@@ -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
|
-
|
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."
|
@@ -4,9 +4,7 @@
|
|
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}"
|
@@ -4,9 +4,7 @@
|
|
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}"
|
@@ -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
|
@@ -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:",
|
@@ -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
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bridgetown
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
4
5
|
class RelatedPosts
|
5
6
|
class << self
|
6
7
|
attr_accessor :lsi
|
@@ -11,13 +12,15 @@ module Bridgetown
|
|
11
12
|
def initialize(post)
|
12
13
|
@post = post
|
13
14
|
@site = post.site
|
14
|
-
|
15
|
+
if site.config.lsi
|
16
|
+
Bridgetown::Utils::RequireGems.require_with_graceful_fail("classifier-reborn")
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
def build
|
18
21
|
return [] unless site.collections.posts.docs.size > 1
|
19
22
|
|
20
|
-
if site.lsi
|
23
|
+
if site.config.lsi
|
21
24
|
build_index
|
22
25
|
lsi_related_posts
|
23
26
|
else
|
@@ -98,7 +98,7 @@ module Bridgetown
|
|
98
98
|
alias_method :read, :read! # TODO: eventually use the bang version only
|
99
99
|
|
100
100
|
def transform!
|
101
|
-
transformer.process!
|
101
|
+
transformer.process! unless collection.data?
|
102
102
|
end
|
103
103
|
|
104
104
|
def trigger_hooks(hook_name, *args)
|
@@ -178,12 +178,8 @@ module Bridgetown
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
def output_allowed?
|
182
|
-
!collection.data? && data.config&.output != false
|
183
|
-
end
|
184
|
-
|
185
181
|
def requires_destination?
|
186
|
-
collection.write? &&
|
182
|
+
collection.write? && data.config&.output != false
|
187
183
|
end
|
188
184
|
|
189
185
|
def write?
|
@@ -262,7 +258,7 @@ module Bridgetown
|
|
262
258
|
alias_method :next_doc, :next_resource
|
263
259
|
|
264
260
|
def previous_resource
|
265
|
-
pos = collection.
|
261
|
+
pos = collection.resources.index { |item| item.equal?(self) }
|
266
262
|
collection.resources[pos - 1] if pos&.positive?
|
267
263
|
end
|
268
264
|
alias_method :previous_doc, :previous_resource
|
@@ -15,6 +15,7 @@ module Bridgetown
|
|
15
15
|
def initialize(resource)
|
16
16
|
@resource = resource
|
17
17
|
@site = resource.site
|
18
|
+
@conversions = []
|
18
19
|
end
|
19
20
|
|
20
21
|
# @return [String]
|
@@ -110,7 +111,7 @@ module Bridgetown
|
|
110
111
|
|
111
112
|
### Transformation Actions
|
112
113
|
|
113
|
-
def run_conversions # rubocop:disable Metrics/AbcSize
|
114
|
+
def run_conversions # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
114
115
|
input = resource.content.to_s
|
115
116
|
|
116
117
|
# @param content [String]
|
@@ -125,7 +126,8 @@ module Bridgetown
|
|
125
126
|
type: :content,
|
126
127
|
converter: converter,
|
127
128
|
output: Bridgetown.env.production? ? nil : output,
|
128
|
-
output_ext: conversions[index]
|
129
|
+
output_ext: conversions[index]&.dig(:output_ext) ||
|
130
|
+
converter.output_ext(resource.extname),
|
129
131
|
}
|
130
132
|
output.html_safe
|
131
133
|
rescue StandardError => e
|
data/lib/bridgetown-core/site.rb
CHANGED
@@ -30,12 +30,11 @@ module Bridgetown
|
|
30
30
|
# is default
|
31
31
|
alias_method :generated_pages, :pages
|
32
32
|
|
33
|
-
attr_accessor :
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:plugin_manager, :converters, :generators, :reader
|
33
|
+
attr_accessor :permalink_style, :time, :baseurl, :data,
|
34
|
+
:file_read_opts, :plugin_manager, :converters,
|
35
|
+
:generators, :reader
|
37
36
|
|
38
|
-
#
|
37
|
+
# Initialize a new Site.
|
39
38
|
#
|
40
39
|
# config - A Hash containing site configuration details.
|
41
40
|
def initialize(config)
|
@@ -36,13 +36,11 @@ module Bridgetown
|
|
36
36
|
code = super.to_s.gsub(LEADING_OR_TRAILING_LINE_TERMINATORS, "")
|
37
37
|
|
38
38
|
output =
|
39
|
-
case context.registers[:site].highlighter
|
39
|
+
case context.registers[:site].config.highlighter
|
40
40
|
when "rouge"
|
41
41
|
render_rouge(code)
|
42
|
-
when "pygments"
|
43
|
-
render_pygments(code, context)
|
44
42
|
else
|
45
|
-
|
43
|
+
h(code).strip
|
46
44
|
end
|
47
45
|
|
48
46
|
rendered_output = add_code_tag(output)
|
@@ -72,13 +70,6 @@ module Bridgetown
|
|
72
70
|
options
|
73
71
|
end
|
74
72
|
|
75
|
-
def render_pygments(code, _context)
|
76
|
-
Bridgetown.logger.warn "Warning:", "Highlight Tag no longer supports" \
|
77
|
-
" rendering with Pygments."
|
78
|
-
Bridgetown.logger.warn "", "Using the default highlighter, Rouge, instead."
|
79
|
-
render_rouge(code)
|
80
|
-
end
|
81
|
-
|
82
73
|
def render_rouge(code)
|
83
74
|
require "rouge"
|
84
75
|
formatter = ::Rouge::Formatters::HTMLLegacy.new(
|
@@ -92,10 +83,6 @@ module Bridgetown
|
|
92
83
|
formatter.format(lexer.lex(code))
|
93
84
|
end
|
94
85
|
|
95
|
-
def render_codehighlighter(code)
|
96
|
-
h(code).strip
|
97
|
-
end
|
98
|
-
|
99
86
|
def add_code_tag(code)
|
100
87
|
code_attributes = [
|
101
88
|
"class=\"language-#{@lang.to_s.tr("+", "-")}\"",
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
class YAMLParser
|
5
|
+
PERMITTED_CLASSES = [Date, Time, Rb].freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def load_file(filename, **kwargs)
|
9
|
+
kwargs = { permitted_classes: PERMITTED_CLASSES }.merge(kwargs)
|
10
|
+
YAML.safe_load_file(filename, **kwargs)
|
11
|
+
end
|
12
|
+
|
13
|
+
def load(yaml)
|
14
|
+
if RUBY_VERSION.start_with?("2.5")
|
15
|
+
YAML.safe_load yaml, PERMITTED_CLASSES
|
16
|
+
else
|
17
|
+
YAML.safe_load yaml, permitted_classes: PERMITTED_CLASSES
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.0.
|
4
|
+
version: 0.21.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -234,20 +234,6 @@ dependencies:
|
|
234
234
|
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '3.0'
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: safe_yaml
|
239
|
-
requirement: !ruby/object:Gem::Requirement
|
240
|
-
requirements:
|
241
|
-
- - "~>"
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: '1.0'
|
244
|
-
type: :runtime
|
245
|
-
prerelease: false
|
246
|
-
version_requirements: !ruby/object:Gem::Requirement
|
247
|
-
requirements:
|
248
|
-
- - "~>"
|
249
|
-
- !ruby/object:Gem::Version
|
250
|
-
version: '1.0'
|
251
237
|
- !ruby/object:Gem::Dependency
|
252
238
|
name: terminal-table
|
253
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -327,6 +313,7 @@ files:
|
|
327
313
|
- lib/bridgetown-core/commands/concerns/actions.rb
|
328
314
|
- lib/bridgetown-core/commands/concerns/build_options.rb
|
329
315
|
- lib/bridgetown-core/commands/concerns/configuration_overridable.rb
|
316
|
+
- lib/bridgetown-core/commands/concerns/git_helpers.rb
|
330
317
|
- lib/bridgetown-core/commands/concerns/summarizable.rb
|
331
318
|
- lib/bridgetown-core/commands/configure.rb
|
332
319
|
- lib/bridgetown-core/commands/console.rb
|
@@ -373,6 +360,7 @@ files:
|
|
373
360
|
- lib/bridgetown-core/converters/markdown/kramdown_parser.rb
|
374
361
|
- lib/bridgetown-core/converters/ruby_templates.rb
|
375
362
|
- lib/bridgetown-core/converters/smartypants.rb
|
363
|
+
- lib/bridgetown-core/core_ext/psych.rb
|
376
364
|
- lib/bridgetown-core/current.rb
|
377
365
|
- lib/bridgetown-core/deprecator.rb
|
378
366
|
- lib/bridgetown-core/document.rb
|
@@ -457,6 +445,7 @@ files:
|
|
457
445
|
- lib/bridgetown-core/utils/ruby_front_matter.rb
|
458
446
|
- lib/bridgetown-core/version.rb
|
459
447
|
- lib/bridgetown-core/watcher.rb
|
448
|
+
- lib/bridgetown-core/yaml_parser.rb
|
460
449
|
- lib/site_template/.gitignore
|
461
450
|
- lib/site_template/Gemfile.erb
|
462
451
|
- lib/site_template/README.md
|