bridgetown-core 0.21.4 → 1.0.0.alpha4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/Rakefile +5 -5
- data/bin/bridgetown +2 -0
- data/bridgetown-core.gemspec +3 -0
- data/lib/bridgetown-core/cache.rb +3 -5
- data/lib/bridgetown-core/cleaner.rb +2 -10
- data/lib/bridgetown-core/collection.rb +62 -86
- data/lib/bridgetown-core/commands/base.rb +62 -2
- data/lib/bridgetown-core/commands/build.rb +33 -12
- data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
- data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
- data/lib/bridgetown-core/commands/console.rb +3 -3
- data/lib/bridgetown-core/commands/doctor.rb +13 -11
- data/lib/bridgetown-core/commands/new.rb +14 -6
- data/lib/bridgetown-core/commands/plugins.rb +8 -11
- data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
- data/lib/bridgetown-core/commands/serve.rb +37 -37
- data/lib/bridgetown-core/commands/start.rb +106 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
- data/lib/bridgetown-core/commands/webpack.rb +1 -1
- data/lib/bridgetown-core/component.rb +2 -6
- data/lib/bridgetown-core/concerns/liquid_renderable.rb +2 -2
- data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
- data/lib/bridgetown-core/concerns/site/content.rb +7 -118
- data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
- data/lib/bridgetown-core/concerns/site/processable.rb +8 -20
- data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
- data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
- data/lib/bridgetown-core/configuration.rb +19 -48
- data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
- data/lib/bridgetown-core/configurations/turbo.rb +1 -1
- data/lib/bridgetown-core/converter.rb +1 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +8 -5
- data/lib/bridgetown-core/converters/liquid_templates.rb +5 -2
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/smartypants.rb +1 -0
- data/lib/bridgetown-core/current.rb +4 -0
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/drop.rb +4 -4
- data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
- data/lib/bridgetown-core/drops/site_drop.rb +3 -47
- data/lib/bridgetown-core/entry_filter.rb +1 -0
- data/lib/bridgetown-core/filters/url_filters.rb +2 -0
- data/lib/bridgetown-core/filters.rb +11 -12
- data/lib/bridgetown-core/frontmatter_defaults.rb +44 -82
- data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
- data/lib/bridgetown-core/generators/prototype_generator.rb +46 -58
- data/lib/bridgetown-core/helpers.rb +8 -3
- data/lib/bridgetown-core/hooks.rb +2 -2
- data/lib/bridgetown-core/layout.rb +15 -4
- data/lib/bridgetown-core/liquid_renderer.rb +1 -3
- data/lib/bridgetown-core/log_adapter.rb +1 -1
- data/lib/bridgetown-core/log_writer.rb +7 -1
- data/lib/bridgetown-core/model/base.rb +12 -4
- data/lib/bridgetown-core/model/builder_origin.rb +23 -11
- data/lib/bridgetown-core/model/origin.rb +3 -0
- data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +10 -10
- data/lib/bridgetown-core/publisher.rb +1 -1
- data/lib/bridgetown-core/rack/boot.rb +55 -0
- data/lib/bridgetown-core/rack/logger.rb +22 -0
- data/lib/bridgetown-core/rack/roda.rb +66 -0
- data/lib/bridgetown-core/rack/routes.rb +88 -0
- data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
- data/lib/bridgetown-core/reader.rb +16 -48
- data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
- data/lib/bridgetown-core/renderer.rb +2 -12
- data/lib/bridgetown-core/resource/base.rb +34 -11
- data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
- data/lib/bridgetown-core/resource/relations.rb +2 -3
- data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
- data/lib/bridgetown-core/resource/transformer.rb +8 -6
- data/lib/bridgetown-core/ruby_template_view.rb +6 -8
- data/lib/bridgetown-core/site.rb +4 -8
- data/lib/bridgetown-core/static_file.rb +14 -21
- data/lib/bridgetown-core/tags/find.rb +6 -6
- data/lib/bridgetown-core/tags/highlight.rb +5 -5
- data/lib/bridgetown-core/tags/include.rb +22 -32
- data/lib/bridgetown-core/tags/link.rb +4 -0
- data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
- data/lib/bridgetown-core/tags/post_url.rb +9 -14
- data/lib/bridgetown-core/tags/render_content.rb +2 -2
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +60 -0
- data/lib/bridgetown-core/url.rb +5 -4
- data/lib/bridgetown-core/utils/aux.rb +57 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
- data/lib/bridgetown-core/utils.rb +44 -11
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +4 -6
- data/lib/bridgetown-core.rb +16 -23
- data/lib/site_template/Gemfile.erb +6 -2
- data/lib/site_template/README.md +6 -6
- data/lib/site_template/Rakefile +49 -0
- data/lib/site_template/bridgetown.config.yml +2 -3
- data/lib/site_template/config/puma.rb +27 -0
- data/lib/site_template/config.ru +7 -0
- data/lib/site_template/package.json.erb +1 -9
- data/lib/site_template/server/roda_app.rb +22 -0
- data/lib/site_template/server/routes/hello.rb.sample +10 -0
- data/lib/site_template/src/_components/head.liquid +2 -1
- data/lib/site_template/src/_layouts/default.liquid +1 -1
- data/lib/site_template/src/about.md +0 -1
- data/lib/site_template/src/posts.md +2 -3
- metadata +63 -18
- data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
- data/lib/bridgetown-core/concerns/validatable.rb +0 -56
- data/lib/bridgetown-core/document.rb +0 -437
- data/lib/bridgetown-core/drops/document_drop.rb +0 -80
- data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
- data/lib/bridgetown-core/drops/page_drop.rb +0 -18
- data/lib/bridgetown-core/excerpt.rb +0 -200
- data/lib/bridgetown-core/readers/data_reader.rb +0 -89
- data/lib/bridgetown-core/readers/page_reader.rb +0 -26
- data/lib/bridgetown-core/readers/post_reader.rb +0 -109
- data/lib/bridgetown-core/regenerator.rb +0 -202
- data/lib/bridgetown-core/related_posts.rb +0 -55
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/start.js +0 -17
- data/lib/site_template/sync.js +0 -35
data/lib/bridgetown-core/site.rb
CHANGED
@@ -10,10 +10,11 @@ module Bridgetown
|
|
10
10
|
include Localizable
|
11
11
|
include Processable
|
12
12
|
include Renderable
|
13
|
+
include SSR
|
13
14
|
include Writable
|
14
15
|
|
15
16
|
attr_reader :root_dir, :source, :dest, :cache_dir, :config,
|
16
|
-
:
|
17
|
+
:liquid_renderer, :components_load_paths,
|
17
18
|
:includes_load_paths
|
18
19
|
|
19
20
|
# All files not pages/documents or structured data in the source folder
|
@@ -23,12 +24,8 @@ module Bridgetown
|
|
23
24
|
# @return [Array<Layout>]
|
24
25
|
attr_accessor :layouts
|
25
26
|
|
26
|
-
# @return [Array<
|
27
|
-
attr_accessor :
|
28
|
-
|
29
|
-
# NOTE: Eventually pages will be deprecated once the Resource content engine
|
30
|
-
# is default
|
31
|
-
alias_method :generated_pages, :pages
|
27
|
+
# @return [Array<GeneratedPage>]
|
28
|
+
attr_accessor :generated_pages
|
32
29
|
|
33
30
|
attr_accessor :permalink_style, :time, :data,
|
34
31
|
:file_read_opts, :plugin_manager, :converters,
|
@@ -44,7 +41,6 @@ module Bridgetown
|
|
44
41
|
@plugin_manager = PluginManager.new(self)
|
45
42
|
@cleaner = Cleaner.new(self)
|
46
43
|
@reader = Reader.new(self)
|
47
|
-
@regenerator = Regenerator.new(self)
|
48
44
|
@liquid_renderer = LiquidRenderer.new(self)
|
49
45
|
|
50
46
|
ensure_not_in_dest
|
@@ -21,10 +21,11 @@ module Bridgetown
|
|
21
21
|
|
22
22
|
# Initialize a new StaticFile.
|
23
23
|
#
|
24
|
-
# site
|
25
|
-
# base
|
26
|
-
# dir
|
27
|
-
# name
|
24
|
+
# @param site [Bridgetown::Site]
|
25
|
+
# @param base [String] path to the <source>.
|
26
|
+
# @param dir [String] path between <source> and the file.
|
27
|
+
# @param name [String] filename of the file.
|
28
|
+
# @param collection [Bridgetown::Collection] optional collection the file is attached to
|
28
29
|
def initialize(site, base, dir, name, collection = nil) # rubocop:disable Metrics/ParameterLists
|
29
30
|
@site = site
|
30
31
|
@base = base
|
@@ -34,20 +35,16 @@ module Bridgetown
|
|
34
35
|
@relative_path = File.join(*[@dir, @name].compact)
|
35
36
|
@extname = File.extname(@name)
|
36
37
|
@data = @site.frontmatter_defaults.all(relative_path, type).with_dot_access
|
37
|
-
if
|
38
|
-
|
39
|
-
"/:collection/:path.*"
|
38
|
+
data.permalink ||= if collection && !collection.builtin?
|
39
|
+
"#{collection.default_permalink.chomp("/").chomp(".*")}.*"
|
40
40
|
else
|
41
41
|
"/:path.*"
|
42
42
|
end
|
43
|
-
end
|
44
43
|
end
|
45
44
|
|
46
45
|
# Returns source file path.
|
47
46
|
def path
|
48
|
-
@path ||=
|
49
|
-
File.join(*[@base, @dir, @name].compact)
|
50
|
-
end
|
47
|
+
@path ||= File.join(*[@base, @dir, @name].compact)
|
51
48
|
end
|
52
49
|
|
53
50
|
# Obtain destination path.
|
@@ -58,7 +55,7 @@ module Bridgetown
|
|
58
55
|
def destination(dest)
|
59
56
|
dest = site.in_dest_dir(dest)
|
60
57
|
dest_url = url
|
61
|
-
if site.
|
58
|
+
if site.base_path.present? && collection
|
62
59
|
dest_url = dest_url.delete_prefix site.base_path(strip_slash_only: true)
|
63
60
|
end
|
64
61
|
site.in_dest_dir(dest, Bridgetown::URL.unescape_path(dest_url))
|
@@ -112,6 +109,7 @@ module Bridgetown
|
|
112
109
|
|
113
110
|
FileUtils.mkdir_p(File.dirname(dest_path))
|
114
111
|
FileUtils.rm(dest_path) if File.exist?(dest_path)
|
112
|
+
Bridgetown.logger.debug "Saving file:", dest_path
|
115
113
|
copy_file(dest_path)
|
116
114
|
|
117
115
|
true
|
@@ -177,14 +175,9 @@ module Bridgetown
|
|
177
175
|
site.config.content_engine != "resource"
|
178
176
|
base = if @collection.nil? || special_posts_case
|
179
177
|
cleaned_relative_path
|
180
|
-
|
178
|
+
else
|
181
179
|
newly_processed = true
|
182
180
|
Bridgetown::Resource::PermalinkProcessor.new(self).transform
|
183
|
-
else
|
184
|
-
Bridgetown::URL.new(
|
185
|
-
template: @collection.url_template,
|
186
|
-
placeholders: placeholders
|
187
|
-
)
|
188
181
|
end.to_s.chomp("/")
|
189
182
|
newly_processed ? base : "#{base}#{extname}"
|
190
183
|
end
|
@@ -212,9 +205,9 @@ module Bridgetown
|
|
212
205
|
def copy_file(dest_path)
|
213
206
|
FileUtils.copy_entry(path, dest_path)
|
214
207
|
|
215
|
-
|
216
|
-
|
217
|
-
|
208
|
+
return if File.symlink?(dest_path)
|
209
|
+
|
210
|
+
File.utime(self.class.mtimes[path], self.class.mtimes[path], dest_path)
|
218
211
|
end
|
219
212
|
end
|
220
213
|
end
|
@@ -11,12 +11,7 @@ module Bridgetown
|
|
11
11
|
|
12
12
|
def initialize(tag_name, markup, tokens)
|
13
13
|
super
|
14
|
-
|
15
|
-
@new_var_name = Regexp.last_match(1).strip
|
16
|
-
@single_or_group = Regexp.last_match(2)
|
17
|
-
@arr_name = Regexp.last_match(3).strip
|
18
|
-
@conditions = process_conditions(Regexp.last_match(4).strip)
|
19
|
-
else
|
14
|
+
unless markup.strip =~ SYNTAX
|
20
15
|
raise SyntaxError, <<~MSG
|
21
16
|
Syntax Error in tag 'find' while parsing the following markup:
|
22
17
|
|
@@ -25,6 +20,11 @@ module Bridgetown
|
|
25
20
|
Valid syntax: find <varname> where|in <array>, <condition(s)>
|
26
21
|
MSG
|
27
22
|
end
|
23
|
+
|
24
|
+
@new_var_name = Regexp.last_match(1).strip
|
25
|
+
@single_or_group = Regexp.last_match(2)
|
26
|
+
@arr_name = Regexp.last_match(3).strip
|
27
|
+
@conditions = process_conditions(Regexp.last_match(4).strip)
|
28
28
|
end
|
29
29
|
|
30
30
|
def render(context)
|
@@ -14,10 +14,7 @@ module Bridgetown
|
|
14
14
|
|
15
15
|
def initialize(tag_name, markup, tokens)
|
16
16
|
super
|
17
|
-
|
18
|
-
@lang = Regexp.last_match(1).downcase
|
19
|
-
@highlight_options = parse_options(Regexp.last_match(2))
|
20
|
-
else
|
17
|
+
unless markup.strip =~ SYNTAX
|
21
18
|
raise SyntaxError, <<~MSG
|
22
19
|
Syntax Error in tag 'highlight' while parsing the following markup:
|
23
20
|
|
@@ -26,6 +23,9 @@ module Bridgetown
|
|
26
23
|
Valid syntax: highlight <lang> [linenos]
|
27
24
|
MSG
|
28
25
|
end
|
26
|
+
|
27
|
+
@lang = Regexp.last_match(1).downcase
|
28
|
+
@highlight_options = parse_options(Regexp.last_match(2))
|
29
29
|
end
|
30
30
|
|
31
31
|
LEADING_OR_TRAILING_LINE_TERMINATORS = %r!\A(\n|\r)+|(\n|\r)+\z!.freeze
|
@@ -89,7 +89,7 @@ module Bridgetown
|
|
89
89
|
"data-lang=\"#{@lang}\"",
|
90
90
|
].join(" ")
|
91
91
|
"<figure class=\"highlight\"><pre><code #{code_attributes}>"\
|
92
|
-
|
92
|
+
"#{code.chomp}</code></pre></figure>"
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -9,15 +9,18 @@ module Bridgetown
|
|
9
9
|
|
10
10
|
VALID_SYNTAX = %r!
|
11
11
|
([\w-]+)\s*=\s*
|
12
|
-
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w
|
12
|
+
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
|
13
13
|
!x.freeze
|
14
|
+
|
15
|
+
# rubocop:disable Lint/MixedRegexpCaptureTypes
|
14
16
|
VARIABLE_SYNTAX = %r!
|
15
|
-
(?<variable>[^{]*(\{\{\s*[\w
|
17
|
+
(?<variable>[^{]*(\{\{\s*[\w\-.]+\s*(\|.*)?\}\}[^\s{}]*)+)
|
16
18
|
(?<params>.*)
|
17
19
|
!mx.freeze
|
20
|
+
# rubocop:enable Lint/MixedRegexpCaptureTypes
|
18
21
|
|
19
22
|
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
|
20
|
-
VALID_FILENAME_CHARS = %r!^[\w
|
23
|
+
VALID_FILENAME_CHARS = %r!^[\w/.-]+$!.freeze
|
21
24
|
INVALID_SEQUENCES = %r![./]{2,}!.freeze
|
22
25
|
|
23
26
|
def initialize(tag_name, markup, tokens)
|
@@ -66,33 +69,33 @@ module Bridgetown
|
|
66
69
|
end
|
67
70
|
|
68
71
|
def validate_file_name(file)
|
69
|
-
|
70
|
-
raise ArgumentError, <<~MSG
|
71
|
-
Invalid syntax for include tag. File contains invalid characters or sequences:
|
72
|
+
return unless INVALID_SEQUENCES.match?(file) || !VALID_FILENAME_CHARS.match?(file)
|
72
73
|
|
73
|
-
|
74
|
+
raise ArgumentError, <<~MSG
|
75
|
+
Invalid syntax for include tag. File contains invalid characters or sequences:
|
74
76
|
|
75
|
-
|
77
|
+
#{file}
|
76
78
|
|
77
|
-
|
79
|
+
Valid syntax:
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
+
#{syntax_example}
|
82
|
+
|
83
|
+
MSG
|
81
84
|
end
|
82
85
|
|
83
86
|
def validate_params
|
84
|
-
|
85
|
-
raise ArgumentError, <<~MSG
|
86
|
-
Invalid syntax for include tag:
|
87
|
+
return if FULL_VALID_SYNTAX.match?(@params)
|
87
88
|
|
88
|
-
|
89
|
+
raise ArgumentError, <<~MSG
|
90
|
+
Invalid syntax for include tag:
|
89
91
|
|
90
|
-
|
92
|
+
#{@params}
|
91
93
|
|
92
|
-
|
94
|
+
Valid syntax:
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
+
#{syntax_example}
|
97
|
+
|
98
|
+
MSG
|
96
99
|
end
|
97
100
|
|
98
101
|
# Grab file read opts in the context
|
@@ -119,16 +122,12 @@ module Bridgetown
|
|
119
122
|
end
|
120
123
|
|
121
124
|
def render(context)
|
122
|
-
site = context.registers[:site]
|
123
|
-
|
124
125
|
file = render_variable(context) || @file
|
125
126
|
validate_file_name(file)
|
126
127
|
|
127
128
|
path = locate_include_file(context, file)
|
128
129
|
return unless path
|
129
130
|
|
130
|
-
add_include_to_dependency(site, path, context)
|
131
|
-
|
132
131
|
partial = load_cached_partial(path, context)
|
133
132
|
|
134
133
|
context.stack do
|
@@ -143,15 +142,6 @@ module Bridgetown
|
|
143
142
|
end
|
144
143
|
end
|
145
144
|
|
146
|
-
def add_include_to_dependency(site, path, context)
|
147
|
-
if context.registers[:page]&.key?("path")
|
148
|
-
site.regenerator.add_dependency(
|
149
|
-
site.in_source_dir(context.registers[:page]["path"]),
|
150
|
-
path
|
151
|
-
)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
145
|
def load_cached_partial(path, context)
|
156
146
|
context.registers[:cached_partials] ||= {}
|
157
147
|
cached_partial = context.registers[:cached_partials]
|
@@ -23,6 +23,10 @@ module Bridgetown
|
|
23
23
|
relative_path = Liquid::Template.parse(@relative_path).render(context)
|
24
24
|
|
25
25
|
site.each_site_file do |item|
|
26
|
+
# Resource engine:
|
27
|
+
if item.respond_to?(:relative_url) && item.relative_path.to_s == relative_path
|
28
|
+
return item.relative_url
|
29
|
+
end
|
26
30
|
return relative_url(item) if item.relative_path == relative_path
|
27
31
|
# This takes care of the case for static files that have a leading /
|
28
32
|
return relative_url(item) if item.relative_path == "/#{relative_path}"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Tags
|
5
|
+
class LiveReloadJsTag < Liquid::Tag
|
6
|
+
def render(context)
|
7
|
+
Bridgetown::Utils.live_reload_js(context.registers[:site])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Liquid::Template.register_tag("live_reload_dev_js", Bridgetown::Tags::LiveReloadJsTag)
|
@@ -29,7 +29,7 @@ module Bridgetown
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def ==(other)
|
32
|
-
other.relative_path.match(@name_regex)
|
32
|
+
other.relative_path.to_s.match(@name_regex)
|
33
33
|
end
|
34
34
|
|
35
35
|
def deprecated_equality(other)
|
@@ -47,12 +47,7 @@ module Bridgetown
|
|
47
47
|
#
|
48
48
|
# Returns the post slug with the subdirectory (relative to _posts)
|
49
49
|
def post_slug(other)
|
50
|
-
|
51
|
-
if path.nil? || path == ""
|
52
|
-
other.data["slug"]
|
53
|
-
else
|
54
|
-
path + "/" + other.data["slug"]
|
55
|
-
end
|
50
|
+
other.data.slug
|
56
51
|
end
|
57
52
|
end
|
58
53
|
|
@@ -77,21 +72,21 @@ module Bridgetown
|
|
77
72
|
@context = context
|
78
73
|
site = context.registers[:site]
|
79
74
|
|
80
|
-
site.collections.posts.
|
75
|
+
site.collections.posts.resources.each do |document|
|
81
76
|
return relative_url(document) if @post == document
|
82
|
-
end
|
83
77
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
site.collections.posts.docs.each do |document|
|
78
|
+
# New matching method did not match, fall back to old method
|
79
|
+
# with deprecation warning if this matches
|
88
80
|
next unless @post.deprecated_equality document
|
89
81
|
|
90
|
-
Bridgetown::Deprecator.deprecation_message
|
82
|
+
Bridgetown::Deprecator.deprecation_message(
|
83
|
+
"A call to "\
|
91
84
|
"'{% post_url #{@post.name} %}' did not match " \
|
92
85
|
"a post using the new matching method of checking name " \
|
93
86
|
"(path-date-slug) equality. Please make sure that you " \
|
94
87
|
"change this tag to match the post's name exactly."
|
88
|
+
)
|
89
|
+
|
95
90
|
return relative_url(document)
|
96
91
|
end
|
97
92
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Bridgetown
|
4
4
|
module Tags
|
5
5
|
class BlockRenderTag < Liquid::Block
|
6
|
-
# rubocop:disable Metrics/MethodLength
|
6
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
7
7
|
def render(context)
|
8
8
|
context.stack({}) do
|
9
9
|
# unindent the incoming text
|
@@ -37,7 +37,7 @@ module Bridgetown
|
|
37
37
|
.render_tag(context, +"")
|
38
38
|
end
|
39
39
|
end
|
40
|
-
# rubocop:enable Metrics/MethodLength
|
40
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
41
41
|
|
42
42
|
private
|
43
43
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc "Generate a secret key for use in sessions, token generation, and beyond"
|
4
|
+
task :secret do
|
5
|
+
require "securerandom"
|
6
|
+
puts SecureRandom.hex(64) # rubocop:disable Bridgetown/NoPutsAllowed
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :frontend do
|
10
|
+
desc "Run frontend bundler independently"
|
11
|
+
task :watcher, :sidecar do |_task, args|
|
12
|
+
# sidecar is when the task is running alongside the start command
|
13
|
+
sidecar = args[:sidecar] == true
|
14
|
+
Bridgetown::Utils::Aux.group do
|
15
|
+
run_process "Frontend", :yellow, "bundle exec bridgetown frontend:dev"
|
16
|
+
end
|
17
|
+
if sidecar
|
18
|
+
sleep 4 # give Webpack time to boot before returning control to the start command
|
19
|
+
else
|
20
|
+
trap("INT") do
|
21
|
+
Bridgetown::Utils::Aux.kill_processes
|
22
|
+
sleep 0.5
|
23
|
+
exit(0)
|
24
|
+
end
|
25
|
+
loop { sleep 1000 }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Prerequisite task which loads site and provides automation"
|
31
|
+
task :environment do
|
32
|
+
class HammerActions < Thor # rubocop:disable Lint/ConstantDefinitionInBlock
|
33
|
+
include Thor::Actions
|
34
|
+
include Bridgetown::Commands::Actions
|
35
|
+
|
36
|
+
def self.source_root
|
37
|
+
Dir.pwd
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.exit_on_failure?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def site
|
47
|
+
@site ||= Bridgetown::Site.new(Bridgetown.configuration)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
define_singleton_method :automation do |*args, &block|
|
52
|
+
@hammer ||= HammerActions.new
|
53
|
+
@hammer.instance_exec(*args, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
define_singleton_method :site do
|
57
|
+
@hammer ||= HammerActions.new
|
58
|
+
@hammer.send(:site)
|
59
|
+
end
|
60
|
+
end
|
data/lib/bridgetown-core/url.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Public: Methods that generate a URL for
|
3
|
+
# Public: Methods that generate a URL for GeneratedPage.
|
4
4
|
#
|
5
5
|
# Examples
|
6
6
|
#
|
@@ -10,6 +10,7 @@
|
|
10
10
|
# }).to_s
|
11
11
|
#
|
12
12
|
module Bridgetown
|
13
|
+
# TODO: remove this class in favor of the new Resource permalink processor
|
13
14
|
class URL
|
14
15
|
# options - One of :permalink or :template must be supplied.
|
15
16
|
# :template - The String used as template for URL generation,
|
@@ -27,9 +28,9 @@ module Bridgetown
|
|
27
28
|
@placeholders = options[:placeholders] || {}
|
28
29
|
@permalink = options[:permalink]
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
return unless (@template || @permalink).nil?
|
32
|
+
|
33
|
+
raise ArgumentError, "One of :template or :permalink must be supplied."
|
33
34
|
end
|
34
35
|
|
35
36
|
# The generated relative URL of the resource
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Utils
|
5
|
+
module Aux
|
6
|
+
def self.with_color(name, message)
|
7
|
+
return message unless !name.nil? && Bridgetown::Utils::Ansi::COLORS[name.to_sym]
|
8
|
+
|
9
|
+
Bridgetown::Utils::Ansi.send(name, message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.running_pids
|
13
|
+
@running_pids ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.add_pid(pid)
|
17
|
+
running_pids << pid
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run_process(name, color, cmd)
|
21
|
+
Thread.new do
|
22
|
+
rd, wr = IO.pipe("BINARY")
|
23
|
+
pid = Process.spawn(cmd, out: wr, err: wr, pgroup: true)
|
24
|
+
@mutex.synchronize do
|
25
|
+
add_pid pid
|
26
|
+
end
|
27
|
+
|
28
|
+
loop do
|
29
|
+
line = rd.gets
|
30
|
+
line.to_s.lines.map(&:chomp).each do |message|
|
31
|
+
output = +""
|
32
|
+
output << with_color(color, "[#{name}] ") if color
|
33
|
+
output << message
|
34
|
+
@mutex.synchronize do
|
35
|
+
$stdout.puts output
|
36
|
+
$stdout.flush
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.group(&block)
|
44
|
+
@mutex = Thread::Mutex.new
|
45
|
+
instance_exec(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.kill_processes
|
49
|
+
Bridgetown.logger.info "Stopping auxiliary processes..."
|
50
|
+
running_pids.each do |pid|
|
51
|
+
Process.kill("SIGTERM", -Process.getpgid(pid))
|
52
|
+
rescue Errno::ESRCH, Errno::EPERM, Errno::ECHILD # rubocop:disable Lint/SuppressedException
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -3,10 +3,7 @@
|
|
3
3
|
module Bridgetown
|
4
4
|
module Utils
|
5
5
|
module RubyExec
|
6
|
-
|
7
|
-
|
8
|
-
# TODO: Deprecate storing Ruby code in YAML, Rb, etc. and just use native Ruby Front Matter
|
9
|
-
def search_data_for_ruby_code(convertible, renderer) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
6
|
+
def self.search_data_for_ruby_code(convertible)
|
10
7
|
return if convertible.data.empty?
|
11
8
|
|
12
9
|
# Iterate using `keys` here so inline Ruby script can add new data keys
|
@@ -14,49 +11,10 @@ module Bridgetown
|
|
14
11
|
data_keys = convertible.data.keys
|
15
12
|
data_keys.each do |k|
|
16
13
|
v = convertible.data[k]
|
17
|
-
next unless v.is_a?(
|
18
|
-
|
19
|
-
if v.is_a?(Proc)
|
20
|
-
convertible.data[k] = convertible.instance_exec(&v)
|
21
|
-
elsif v.is_a?(Hash)
|
22
|
-
v.each do |nested_k, nested_v|
|
23
|
-
next unless nested_v.is_a?(Rb)
|
24
|
-
|
25
|
-
convertible.data[k][nested_k] = run(nested_v, convertible, renderer)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
convertible.data[k] = run(v, convertible, renderer)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Sets up a new context in which to eval Ruby coming from front matter.
|
34
|
-
#
|
35
|
-
# ruby_code - a string of code
|
36
|
-
# convertible - the Document/Page/Layout with the Ruby front matter
|
37
|
-
# renderer - the Renderer instance that's processing the document (optional)
|
38
|
-
#
|
39
|
-
# Returns the transformed output of the code
|
40
|
-
def run(ruby_code, convertible, renderer)
|
41
|
-
return unless ruby_code.is_a?(Rb)
|
14
|
+
next unless v.is_a?(Proc)
|
42
15
|
|
43
|
-
|
44
|
-
obj = klass.new
|
45
|
-
|
46
|
-
if convertible.is_a?(Layout)
|
47
|
-
klass.attr_accessor :layout, :site, :data
|
48
|
-
obj.layout = convertible
|
49
|
-
else
|
50
|
-
klass.attr_accessor :document, :page, :renderer, :site, :data
|
51
|
-
obj.document = obj.page = convertible
|
52
|
-
obj.renderer = renderer
|
16
|
+
convertible.data[k] = convertible.instance_exec(&v)
|
53
17
|
end
|
54
|
-
obj.site = convertible.site
|
55
|
-
obj.data = convertible.data
|
56
|
-
|
57
|
-
# This is where the magic happens! DON'T BE EVIL!!! ;-)
|
58
|
-
output = obj.instance_eval(ruby_code)
|
59
|
-
output.is_a?(Hash) ? output.with_dot_access : output
|
60
18
|
end
|
61
19
|
end
|
62
20
|
end
|
@@ -3,20 +3,23 @@
|
|
3
3
|
module Bridgetown
|
4
4
|
module Utils
|
5
5
|
module RubyFrontMatterDSL
|
6
|
-
def front_matter(&block)
|
7
|
-
RubyFrontMatter.new.tap { |fm| fm.instance_exec(&block) }
|
6
|
+
def front_matter(scope: nil, &block)
|
7
|
+
RubyFrontMatter.new(scope: scope).tap { |fm| fm.instance_exec(&block) }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
class RubyFrontMatter
|
12
|
-
def initialize
|
12
|
+
def initialize(scope: nil)
|
13
13
|
@data = {}
|
14
|
+
@scope = scope
|
14
15
|
end
|
15
16
|
|
16
|
-
def method_missing(key, value) # rubocop:disable Style/MissingRespondToMissing
|
17
|
-
return super if respond_to?(key)
|
17
|
+
def method_missing(key, *value, &block) # rubocop:disable Metrics/CyclomaticComplexity, Style/MissingRespondToMissing
|
18
|
+
return super if respond_to?(key) || (value.length.zero? && block.nil? && !@data.key?(key))
|
18
19
|
|
19
|
-
|
20
|
+
return get(key) if value.length.zero? && block.nil? && @data.key?(key)
|
21
|
+
|
22
|
+
set(key, value[0], &block)
|
20
23
|
end
|
21
24
|
|
22
25
|
def each(&block)
|
@@ -27,7 +30,19 @@ module Bridgetown
|
|
27
30
|
@data[key]
|
28
31
|
end
|
29
32
|
|
30
|
-
def set(key, value)
|
33
|
+
def set(key, value = nil, &block)
|
34
|
+
# Handle nested data within a block
|
35
|
+
if block
|
36
|
+
value = self.class.new(scope: @scope).tap do |fm|
|
37
|
+
fm.instance_exec(&block)
|
38
|
+
end.to_h
|
39
|
+
end
|
40
|
+
|
41
|
+
# Execute lambda value within the resolver
|
42
|
+
if @scope && value.is_a?(Hash) && value[:from].is_a?(Proc)
|
43
|
+
value = @scope.instance_exec(&value[:from])
|
44
|
+
end
|
45
|
+
|
31
46
|
@data[key] = value
|
32
47
|
end
|
33
48
|
|