bridgetown-core 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridgetown-core/collection.rb +12 -6
- data/lib/bridgetown-core/command.rb +1 -1
- data/lib/bridgetown-core/commands/build.rb +28 -15
- data/lib/bridgetown-core/commands/clean.rb +3 -3
- data/lib/bridgetown-core/commands/serve.rb +16 -23
- data/lib/bridgetown-core/configuration.rb +2 -2
- data/lib/bridgetown-core/convertible.rb +1 -1
- data/lib/bridgetown-core/document.rb +7 -7
- data/lib/bridgetown-core/drops/collection_drop.rb +2 -2
- data/lib/bridgetown-core/drops/document_drop.rb +6 -3
- data/lib/bridgetown-core/drops/url_drop.rb +2 -2
- data/lib/bridgetown-core/filters.rb +2 -2
- data/lib/bridgetown-core/hooks.rb +31 -31
- data/lib/bridgetown-core/liquid_renderer/file.rb +1 -1
- data/lib/bridgetown-core/liquid_renderer/table.rb +1 -1
- data/lib/bridgetown-core/log_adapter.rb +4 -4
- data/lib/bridgetown-core/page.rb +6 -6
- data/lib/bridgetown-core/plugin.rb +5 -5
- data/lib/bridgetown-core/reader.rb +4 -1
- data/lib/bridgetown-core/readers/data_reader.rb +5 -5
- data/lib/bridgetown-core/readers/post_reader.rb +27 -7
- data/lib/bridgetown-core/related_posts.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +3 -3
- data/lib/bridgetown-core/static_file.rb +10 -15
- data/lib/bridgetown-core/tags/highlight.rb +5 -5
- data/lib/bridgetown-core/utils.rb +1 -1
- data/lib/bridgetown-core/utils/ansi.rb +8 -8
- data/lib/bridgetown-core/utils/platforms.rb +2 -2
- data/lib/bridgetown-core/utils/win_tz.rb +1 -1
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/watcher.rb +5 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d54c0a2a041830e819a8f60b45164f00fa833bc5d795941599969bb967e550ae
|
4
|
+
data.tar.gz: 81bf01e9efec7ea134d9c76de18a0b19bdd4d9addc7d0011a03fc038d18890f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8746742cc41353b34c8f91549b1981034014fb35cb23ea4b3077b96c9c41ca10470e688c78b106b1d7b1655ca0503e01e9095bcc0f17ac3afdc8aadd891f49f9
|
7
|
+
data.tar.gz: 50c6e804f3712ab3a30fafddbde9c5a0c9c04487b8a3f671fb9bc8cdd1d5fb14b64913b0f048672592ef15fad8d2c5aad1e0f3c348c6fce5479fdfa13f718aa2
|
@@ -109,14 +109,20 @@ module Bridgetown
|
|
109
109
|
@relative_directory ||= "_#{label}"
|
110
110
|
end
|
111
111
|
|
112
|
+
# The relative path to the directory containing the collection.
|
113
|
+
#
|
114
|
+
# Returns a String containing the directory name where the collection
|
115
|
+
# is stored relative to the source directory
|
116
|
+
def relative_path
|
117
|
+
Pathname.new(container).join(relative_directory).to_s
|
118
|
+
end
|
119
|
+
|
112
120
|
# The full path to the directory containing the collection.
|
113
121
|
#
|
114
|
-
# Returns a String containing
|
122
|
+
# Returns a String containing the directory name where the collection
|
115
123
|
# is stored on the filesystem.
|
116
124
|
def directory
|
117
|
-
@directory ||= site.in_source_dir(
|
118
|
-
File.join(container, relative_directory)
|
119
|
-
)
|
125
|
+
@directory ||= site.in_source_dir(relative_path)
|
120
126
|
end
|
121
127
|
|
122
128
|
# The full path to the directory containing the collection, with
|
@@ -209,7 +215,7 @@ module Bridgetown
|
|
209
215
|
end
|
210
216
|
|
211
217
|
def read_document(full_path)
|
212
|
-
doc = Document.new(full_path, :
|
218
|
+
doc = Document.new(full_path, site: site, collection: self)
|
213
219
|
doc.read
|
214
220
|
docs << doc if site.unpublished || doc.published?
|
215
221
|
end
|
@@ -263,7 +269,7 @@ module Bridgetown
|
|
263
269
|
|
264
270
|
def read_static_file(file_path, full_path)
|
265
271
|
relative_dir = Bridgetown.sanitized_path(
|
266
|
-
|
272
|
+
relative_path,
|
267
273
|
File.dirname(file_path)
|
268
274
|
).chomp("/.")
|
269
275
|
|
@@ -66,7 +66,7 @@ module Bridgetown
|
|
66
66
|
"Serve the website from the given base URL"
|
67
67
|
cmd.option "force_polling", "--force_polling", "Force watch to use polling"
|
68
68
|
cmd.option "lsi", "--lsi", "Use LSI for improved related posts"
|
69
|
-
cmd.option "unpublished", "--unpublished",
|
69
|
+
cmd.option "unpublished", "-U", "--unpublished",
|
70
70
|
"Render posts that were marked as unpublished"
|
71
71
|
cmd.option "disable_disk_cache", "--disable-disk-cache",
|
72
72
|
"Disable caching to disk"
|
@@ -30,20 +30,20 @@ module Bridgetown
|
|
30
30
|
" build is about to begin…"
|
31
31
|
|
32
32
|
options = configuration_from_options(options)
|
33
|
-
site = Bridgetown::Site.new(options)
|
33
|
+
@site = Bridgetown::Site.new(options)
|
34
34
|
|
35
35
|
if options.fetch("skip_initial_build", false)
|
36
36
|
Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
|
37
37
|
" This may result in an out-of-date site."
|
38
38
|
else
|
39
|
-
build(
|
39
|
+
build(options)
|
40
40
|
end
|
41
41
|
|
42
42
|
if options.fetch("detach", false)
|
43
43
|
Bridgetown.logger.info "Auto-regeneration:",
|
44
44
|
"disabled when running server detached."
|
45
45
|
elsif options.fetch("watch", false)
|
46
|
-
watch(
|
46
|
+
watch(options)
|
47
47
|
else
|
48
48
|
Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
|
49
49
|
end
|
@@ -51,31 +51,30 @@ module Bridgetown
|
|
51
51
|
|
52
52
|
# Build your Bridgetown site.
|
53
53
|
#
|
54
|
-
#
|
55
|
-
# options - A Hash of options passed to the command
|
54
|
+
# options - A Hash of options passed to the command or loaded from config
|
56
55
|
#
|
57
56
|
# Returns nothing.
|
58
|
-
def build(
|
57
|
+
def build(options)
|
59
58
|
t = Time.now
|
60
|
-
|
61
|
-
|
59
|
+
display_folder_paths(options)
|
60
|
+
if options["unpublished"]
|
61
|
+
Bridgetown.logger.info "Unpublished mode:",
|
62
|
+
"enabled. Processing documents marked unpublished"
|
63
|
+
end
|
62
64
|
incremental = options["incremental"]
|
63
|
-
Bridgetown.logger.info "Source:", source
|
64
|
-
Bridgetown.logger.info "Destination:", destination
|
65
65
|
Bridgetown.logger.info "Incremental build:",
|
66
66
|
(incremental ? "enabled" : "disabled. Enable with --incremental")
|
67
67
|
Bridgetown.logger.info "Generating…"
|
68
|
-
process_site(site)
|
68
|
+
process_site(@site)
|
69
69
|
Bridgetown.logger.info "Done! 🎉", "Completed in #{(Time.now - t).round(3)} seconds."
|
70
70
|
end
|
71
71
|
|
72
72
|
# Private: Watch for file changes and rebuild the site.
|
73
73
|
#
|
74
|
-
#
|
75
|
-
# options - A Hash of options passed to the command
|
74
|
+
# options - A Hash of options passed to the command or loaded from config
|
76
75
|
#
|
77
76
|
# Returns nothing.
|
78
|
-
def watch(
|
77
|
+
def watch(options)
|
79
78
|
# Warn Windows users that they might need to upgrade.
|
80
79
|
if Utils::Platforms.bash_on_windows?
|
81
80
|
Bridgetown.logger.warn "",
|
@@ -88,7 +87,21 @@ module Bridgetown
|
|
88
87
|
end
|
89
88
|
|
90
89
|
# External.require_with_graceful_fail "bridgetown-watch"
|
91
|
-
Bridgetown::Watcher.watch(
|
90
|
+
Bridgetown::Watcher.watch(@site, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Private: display the source and destination folder paths
|
94
|
+
#
|
95
|
+
# options - A Hash of options passed to the command
|
96
|
+
#
|
97
|
+
# Returns nothing.
|
98
|
+
def display_folder_paths(options)
|
99
|
+
source = File.expand_path(options["source"])
|
100
|
+
destination = File.expand_path(options["destination"])
|
101
|
+
plugins_dir = File.expand_path(options["plugins_dir"])
|
102
|
+
Bridgetown.logger.info "Source:", source
|
103
|
+
Bridgetown.logger.info "Destination:", destination
|
104
|
+
Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
|
92
105
|
end
|
93
106
|
end
|
94
107
|
end
|
@@ -24,9 +24,9 @@ module Bridgetown
|
|
24
24
|
metadata_file = File.join(options["source"], ".bridgetown-metadata")
|
25
25
|
cache_dir = File.join(options["source"], options["cache_dir"])
|
26
26
|
|
27
|
-
remove(destination, :
|
28
|
-
remove(metadata_file, :
|
29
|
-
remove(cache_dir, :
|
27
|
+
remove(destination, checker_func: :directory?)
|
28
|
+
remove(metadata_file, checker_func: :file?)
|
29
|
+
remove(cache_dir, checker_func: :directory?)
|
30
30
|
end
|
31
31
|
|
32
32
|
def remove(filename, checker_func: :file?)
|
@@ -58,6 +58,7 @@ module Bridgetown
|
|
58
58
|
opts["serving"] = true
|
59
59
|
opts["watch"] = true unless opts.key?("watch")
|
60
60
|
|
61
|
+
# TODO: this prints the configuration file log message out-of-order
|
61
62
|
config = configuration_from_options(opts)
|
62
63
|
config["url"] = default_url(config) if Bridgetown.env == "development"
|
63
64
|
|
@@ -102,15 +103,15 @@ module Bridgetown
|
|
102
103
|
|
103
104
|
def webrick_opts(opts)
|
104
105
|
opts = {
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
106
|
+
BridgetownOptions: opts,
|
107
|
+
DoNotReverseLookup: true,
|
108
|
+
MimeTypes: mime_types,
|
109
|
+
DocumentRoot: opts["destination"],
|
110
|
+
StartCallback: start_callback(opts["detach"]),
|
111
|
+
StopCallback: stop_callback(opts["detach"]),
|
112
|
+
BindAddress: opts["host"],
|
113
|
+
Port: opts["port"],
|
114
|
+
DirectoryIndex: DIRECTORY_INDEX,
|
114
115
|
}
|
115
116
|
|
116
117
|
opts[:DirectoryIndex] = [] if opts[:BridgetownOptions]["show_dir_listing"]
|
@@ -121,8 +122,6 @@ module Bridgetown
|
|
121
122
|
end
|
122
123
|
|
123
124
|
def start_up_webrick(opts, destination)
|
124
|
-
@reload_reactor.start(opts) if opts["livereload"]
|
125
|
-
|
126
125
|
@server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
127
126
|
@server.mount(opts["baseurl"].to_s, Servlet, destination, file_handler_opts)
|
128
127
|
|
@@ -134,8 +133,8 @@ module Bridgetown
|
|
134
133
|
# Recreate NondisclosureName under utf-8 circumstance
|
135
134
|
def file_handler_opts
|
136
135
|
WEBrick::Config::FileHandler.merge(
|
137
|
-
:
|
138
|
-
:
|
136
|
+
FancyIndexing: true,
|
137
|
+
NondisclosureName: [
|
139
138
|
".ht*", "~*",
|
140
139
|
]
|
141
140
|
)
|
@@ -152,10 +151,10 @@ module Bridgetown
|
|
152
151
|
|
153
152
|
def format_url(ssl_enabled, address, port, baseurl = nil)
|
154
153
|
format("%<prefix>s://%<address>s:%<port>i%<baseurl>s",
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
154
|
+
prefix: ssl_enabled ? "https" : "http",
|
155
|
+
address: address,
|
156
|
+
port: port,
|
157
|
+
baseurl: baseurl ? "#{baseurl}/" : "")
|
159
158
|
end
|
160
159
|
|
161
160
|
def default_url(opts)
|
@@ -234,8 +233,6 @@ module Bridgetown
|
|
234
233
|
unless detached
|
235
234
|
proc do
|
236
235
|
mutex.synchronize do
|
237
|
-
# Block until EventMachine reactor starts
|
238
|
-
@reload_reactor&.started_event&.wait
|
239
236
|
@running = true
|
240
237
|
Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
|
241
238
|
@run_cond.broadcast
|
@@ -248,10 +245,6 @@ module Bridgetown
|
|
248
245
|
unless detached
|
249
246
|
proc do
|
250
247
|
mutex.synchronize do
|
251
|
-
unless @reload_reactor.nil?
|
252
|
-
@reload_reactor.stop
|
253
|
-
@reload_reactor.stopped_event.wait
|
254
|
-
end
|
255
248
|
@running = false
|
256
249
|
@run_cond.broadcast
|
257
250
|
end
|
@@ -150,8 +150,8 @@ module Bridgetown
|
|
150
150
|
def config_files(override)
|
151
151
|
# Adjust verbosity quickly
|
152
152
|
Bridgetown.logger.adjust_verbosity(
|
153
|
-
:
|
154
|
-
:
|
153
|
+
quiet: quiet?(override),
|
154
|
+
verbose: verbose?(override)
|
155
155
|
)
|
156
156
|
|
157
157
|
# Get configuration from <root_dir>/<matching_default_config>
|
@@ -208,7 +208,7 @@ module Bridgetown
|
|
208
208
|
path = destination(dest)
|
209
209
|
FileUtils.mkdir_p(File.dirname(path))
|
210
210
|
Bridgetown.logger.debug "Writing:", path
|
211
|
-
File.write(path, output, :
|
211
|
+
File.write(path, output, mode: "wb")
|
212
212
|
Bridgetown::Hooks.trigger hook_owner, :post_write, self
|
213
213
|
end
|
214
214
|
|
@@ -203,9 +203,9 @@ module Bridgetown
|
|
203
203
|
# Returns the computed URL for the document.
|
204
204
|
def url
|
205
205
|
@url ||= URL.new(
|
206
|
-
:
|
207
|
-
:
|
208
|
-
:
|
206
|
+
template: url_template,
|
207
|
+
placeholders: url_placeholders,
|
208
|
+
permalink: permalink
|
209
209
|
).to_s
|
210
210
|
end
|
211
211
|
|
@@ -238,7 +238,7 @@ module Bridgetown
|
|
238
238
|
path = destination(dest)
|
239
239
|
FileUtils.mkdir_p(File.dirname(path))
|
240
240
|
Bridgetown.logger.debug "Writing:", path
|
241
|
-
File.write(path, output, :
|
241
|
+
File.write(path, output, mode: "wb")
|
242
242
|
|
243
243
|
trigger_hooks(:post_write)
|
244
244
|
end
|
@@ -412,7 +412,7 @@ module Bridgetown
|
|
412
412
|
|
413
413
|
def merge_defaults
|
414
414
|
defaults = @site.frontmatter_defaults.all(relative_path, type)
|
415
|
-
merge_data!(defaults, :
|
415
|
+
merge_data!(defaults, source: "front matter defaults") unless defaults.empty?
|
416
416
|
end
|
417
417
|
|
418
418
|
def read_content(**opts)
|
@@ -420,7 +420,7 @@ module Bridgetown
|
|
420
420
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
421
421
|
self.content = $POSTMATCH
|
422
422
|
data_file = SafeYAML.load(Regexp.last_match(1))
|
423
|
-
merge_data!(data_file, :
|
423
|
+
merge_data!(data_file, source: "YAML front matter") if data_file
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
@@ -464,7 +464,7 @@ module Bridgetown
|
|
464
464
|
|
465
465
|
def modify_date(date)
|
466
466
|
if !data["date"] || data["date"].to_i == site.time.to_i
|
467
|
-
merge_data!({ "date" => date }, :
|
467
|
+
merge_data!({ "date" => date }, source: "filename")
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
@@ -8,12 +8,12 @@ module Bridgetown
|
|
8
8
|
mutable false
|
9
9
|
|
10
10
|
def_delegator :@obj, :write?, :output
|
11
|
-
def_delegators :@obj, :label, :docs, :files, :
|
11
|
+
def_delegators :@obj, :label, :docs, :files, :relative_path
|
12
12
|
|
13
13
|
private def_delegator :@obj, :metadata, :fallback_data
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
|
16
|
+
label
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -17,7 +17,7 @@ module Bridgetown
|
|
17
17
|
private def_delegator :@obj, :data, :fallback_data
|
18
18
|
|
19
19
|
def collection
|
20
|
-
@obj.collection.
|
20
|
+
@collection ||= @obj.collection.to_liquid
|
21
21
|
end
|
22
22
|
|
23
23
|
def excerpt
|
@@ -33,11 +33,11 @@ module Bridgetown
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def previous
|
36
|
-
@obj.previous_doc.to_liquid
|
36
|
+
@previous ||= @obj.previous_doc.to_liquid
|
37
37
|
end
|
38
38
|
|
39
39
|
def next
|
40
|
-
@obj.next_doc.to_liquid
|
40
|
+
@next ||= @obj.next_doc.to_liquid
|
41
41
|
end
|
42
42
|
|
43
43
|
# Generate a Hash for use in generating JSON.
|
@@ -48,6 +48,9 @@ module Bridgetown
|
|
48
48
|
# Returns a Hash ready for JSON generation.
|
49
49
|
def hash_for_json(state = nil)
|
50
50
|
to_h.tap do |hash|
|
51
|
+
# use collection label in the hash
|
52
|
+
hash["collection"] = hash["collection"]["label"] if hash["collection"]
|
53
|
+
|
51
54
|
if state && state.depth >= 2
|
52
55
|
hash["previous"] = collapse_document(hash["previous"]) if hash["previous"]
|
53
56
|
hash["next"] = collapse_document(hash["next"]) if hash["next"]
|
@@ -19,8 +19,8 @@ module Bridgetown
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def title
|
22
|
-
Utils.slugify(@obj.data["slug"], :
|
23
|
-
Utils.slugify(@obj.basename_without_ext, :
|
22
|
+
Utils.slugify(@obj.data["slug"], mode: "pretty", cased: true) ||
|
23
|
+
Utils.slugify(@obj.basename_without_ext, mode: "pretty", cased: true)
|
24
24
|
end
|
25
25
|
|
26
26
|
def slug
|
@@ -60,7 +60,7 @@ module Bridgetown
|
|
60
60
|
# Returns the given filename or title as a lowercase URL String.
|
61
61
|
# See Utils.slugify for more detail.
|
62
62
|
def slugify(input, mode = nil)
|
63
|
-
Utils.slugify(input, :
|
63
|
+
Utils.slugify(input, mode: mode)
|
64
64
|
end
|
65
65
|
|
66
66
|
# XML escape a string for use. Replaces any special characters with
|
@@ -75,7 +75,7 @@ module Bridgetown
|
|
75
75
|
#
|
76
76
|
# Returns the escaped String.
|
77
77
|
def xml_escape(input)
|
78
|
-
input.to_s.encode(:
|
78
|
+
input.to_s.encode(xml: :attr).gsub(%r!\A"|"\Z!, "")
|
79
79
|
end
|
80
80
|
|
81
81
|
# CGI escape a string for use in a URL. Replaces any special characters
|
@@ -6,41 +6,41 @@ module Bridgetown
|
|
6
6
|
|
7
7
|
# compatibility layer for octopress-hooks users
|
8
8
|
PRIORITY_MAP = {
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
9
|
+
low: 10,
|
10
|
+
normal: 20,
|
11
|
+
high: 30,
|
12
12
|
}.freeze
|
13
13
|
|
14
14
|
# initial empty hooks
|
15
15
|
@registry = {
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
16
|
+
site: {
|
17
|
+
after_init: [],
|
18
|
+
after_reset: [],
|
19
|
+
post_read: [],
|
20
|
+
pre_render: [],
|
21
|
+
post_render: [],
|
22
|
+
post_write: [],
|
23
23
|
},
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
24
|
+
pages: {
|
25
|
+
post_init: [],
|
26
|
+
pre_render: [],
|
27
|
+
post_render: [],
|
28
|
+
post_write: [],
|
29
29
|
},
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
30
|
+
posts: {
|
31
|
+
post_init: [],
|
32
|
+
pre_render: [],
|
33
|
+
post_render: [],
|
34
|
+
post_write: [],
|
35
35
|
},
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
36
|
+
documents: {
|
37
|
+
post_init: [],
|
38
|
+
pre_render: [],
|
39
|
+
post_render: [],
|
40
|
+
post_write: [],
|
41
41
|
},
|
42
|
-
:
|
43
|
-
:
|
42
|
+
clean: {
|
43
|
+
on_obsolete: [],
|
44
44
|
},
|
45
45
|
}
|
46
46
|
|
@@ -67,10 +67,10 @@ module Bridgetown
|
|
67
67
|
# register a single hook to be called later, internal API
|
68
68
|
def self.register_one(owner, event, priority, &block)
|
69
69
|
@registry[owner] ||= {
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
70
|
+
post_init: [],
|
71
|
+
pre_render: [],
|
72
|
+
post_render: [],
|
73
|
+
post_write: [],
|
74
74
|
}
|
75
75
|
|
76
76
|
unless @registry[owner][event]
|
@@ -10,7 +10,7 @@ module Bridgetown
|
|
10
10
|
|
11
11
|
def parse(content)
|
12
12
|
measure_time do
|
13
|
-
@renderer.cache[@filename] ||= Liquid::Template.parse(content, :
|
13
|
+
@renderer.cache[@filename] ||= Liquid::Template.parse(content, line_numbers: true)
|
14
14
|
end
|
15
15
|
@template = @renderer.cache[@filename]
|
16
16
|
|
@@ -28,7 +28,7 @@ module Bridgetown
|
|
28
28
|
data.each { |row| t << row }
|
29
29
|
t << :separator
|
30
30
|
t << footer
|
31
|
-
t.style = { :
|
31
|
+
t.style = { alignment: :right, border_top: false, border_bottom: false }
|
32
32
|
t.align_column(0, :left)
|
33
33
|
end
|
34
34
|
|
@@ -5,10 +5,10 @@ module Bridgetown
|
|
5
5
|
attr_reader :writer, :messages, :level
|
6
6
|
|
7
7
|
LOG_LEVELS = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
8
|
+
debug: ::Logger::DEBUG,
|
9
|
+
info: ::Logger::INFO,
|
10
|
+
warn: ::Logger::WARN,
|
11
|
+
error: ::Logger::ERROR,
|
12
12
|
}.freeze
|
13
13
|
|
14
14
|
# Public: Create a new instance of a log writer
|
data/lib/bridgetown-core/page.rb
CHANGED
@@ -124,9 +124,9 @@ module Bridgetown
|
|
124
124
|
# Returns the String url.
|
125
125
|
def url
|
126
126
|
@url ||= URL.new(
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
127
|
+
template: template,
|
128
|
+
placeholders: url_placeholders,
|
129
|
+
permalink: permalink
|
130
130
|
).to_s
|
131
131
|
end
|
132
132
|
|
@@ -134,9 +134,9 @@ module Bridgetown
|
|
134
134
|
# desired placeholder replacements. For details see "url.rb"
|
135
135
|
def url_placeholders
|
136
136
|
{
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
137
|
+
path: @dir,
|
138
|
+
basename: basename,
|
139
|
+
output_ext: output_ext,
|
140
140
|
}
|
141
141
|
end
|
142
142
|
|
@@ -70,7 +70,10 @@ module Bridgetown
|
|
70
70
|
def retrieve_posts(dir)
|
71
71
|
return if outside_configured_directory?(dir)
|
72
72
|
|
73
|
-
|
73
|
+
post_reader.read_posts(dir).tap do |entries|
|
74
|
+
site.posts.docs.concat(entries.select { |entry| entry.is_a?(Document) })
|
75
|
+
site.posts.files.concat(entries.select { |entry| entry.is_a?(StaticFile) })
|
76
|
+
end
|
74
77
|
end
|
75
78
|
|
76
79
|
# Recursively traverse directories with the read_directories function.
|
@@ -55,13 +55,13 @@ module Bridgetown
|
|
55
55
|
case File.extname(path).downcase
|
56
56
|
when ".csv"
|
57
57
|
CSV.read(path,
|
58
|
-
:
|
59
|
-
:
|
58
|
+
headers: true,
|
59
|
+
encoding: site.config["encoding"]).map(&:to_hash)
|
60
60
|
when ".tsv"
|
61
61
|
CSV.read(path,
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
62
|
+
col_sep: "\t",
|
63
|
+
headers: true,
|
64
|
+
encoding: site.config["encoding"]).map(&:to_hash)
|
65
65
|
else
|
66
66
|
SafeYAML.load_file(path)
|
67
67
|
end
|
@@ -25,8 +25,8 @@ module Bridgetown
|
|
25
25
|
# Returns nothing.
|
26
26
|
def read_publishable(dir, magic_dir, matcher)
|
27
27
|
read_content(dir, magic_dir, matcher)
|
28
|
-
.tap { |
|
29
|
-
.select { |
|
28
|
+
.tap { |entries| entries.select { |entry| entry.respond_to?(:read) }.each(&:read) }
|
29
|
+
.select { |entry| processable?(entry) }
|
30
30
|
end
|
31
31
|
|
32
32
|
# Read all the content files from <source>/<dir>/magic_dir
|
@@ -40,18 +40,38 @@ module Bridgetown
|
|
40
40
|
# Returns klass type of content files
|
41
41
|
def read_content(dir, magic_dir, matcher)
|
42
42
|
@site.reader.get_entries(dir, magic_dir).map do |entry|
|
43
|
-
next unless matcher.match?(entry)
|
44
|
-
|
45
43
|
path = @site.in_source_dir(File.join(dir, magic_dir, entry))
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
|
45
|
+
if matcher.match?(entry) || Utils.has_yaml_header?(path)
|
46
|
+
# Process as Document
|
47
|
+
Document.new(path,
|
48
|
+
site: @site,
|
49
|
+
collection: @site.posts)
|
50
|
+
else
|
51
|
+
# Process as Static File
|
52
|
+
read_static_file(
|
53
|
+
path,
|
54
|
+
File.join(dir, magic_dir, File.dirname(entry).sub(".", ""))
|
55
|
+
)
|
56
|
+
end
|
49
57
|
end.reject(&:nil?)
|
50
58
|
end
|
51
59
|
|
52
60
|
private
|
53
61
|
|
62
|
+
def read_static_file(full_path, relative_dir)
|
63
|
+
StaticFile.new(
|
64
|
+
site,
|
65
|
+
site.source,
|
66
|
+
relative_dir,
|
67
|
+
File.basename(full_path),
|
68
|
+
@site.posts
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
54
72
|
def processable?(doc)
|
73
|
+
return true if doc.is_a?(StaticFile)
|
74
|
+
|
55
75
|
if doc.content.nil?
|
56
76
|
Bridgetown.logger.debug "Skipping:", "Content in #{doc.relative_path} is nil"
|
57
77
|
false
|
@@ -27,7 +27,7 @@ module Bridgetown
|
|
27
27
|
|
28
28
|
def build_index
|
29
29
|
self.class.lsi ||= begin
|
30
|
-
lsi = ClassifierReborn::LSI.new(:
|
30
|
+
lsi = ClassifierReborn::LSI.new(auto_rebuild: false)
|
31
31
|
Bridgetown.logger.info("Populating LSI...")
|
32
32
|
|
33
33
|
site.posts.docs.each do |x|
|
@@ -69,9 +69,9 @@ module Bridgetown
|
|
69
69
|
# rubocop: disable Metrics/AbcSize
|
70
70
|
def render_document
|
71
71
|
info = {
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
72
|
+
registers: { site: site, page: payload["page"] },
|
73
|
+
strict_filters: liquid_options["strict_filters"],
|
74
|
+
strict_variables: liquid_options["strict_variables"],
|
75
75
|
}
|
76
76
|
|
77
77
|
output = document.content
|
@@ -41,12 +41,7 @@ module Bridgetown
|
|
41
41
|
# Returns source file path.
|
42
42
|
def path
|
43
43
|
@path ||= begin
|
44
|
-
|
45
|
-
if !@collection.nil? && !@site.config["collections_dir"].empty?
|
46
|
-
File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact)
|
47
|
-
else
|
48
|
-
File.join(*[@base, @dir, @name].compact)
|
49
|
-
end
|
44
|
+
File.join(*[@base, @dir, @name].compact)
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
@@ -125,11 +120,11 @@ module Bridgetown
|
|
125
120
|
|
126
121
|
def placeholders
|
127
122
|
{
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
123
|
+
collection: @collection.label,
|
124
|
+
path: cleaned_relative_path,
|
125
|
+
output_ext: "",
|
126
|
+
name: "",
|
127
|
+
title: "",
|
133
128
|
}
|
134
129
|
end
|
135
130
|
|
@@ -149,7 +144,7 @@ module Bridgetown
|
|
149
144
|
@cleaned_relative_path ||= begin
|
150
145
|
cleaned = relative_path[0..-extname.length - 1]
|
151
146
|
cleaned.gsub!(%r!\.*\z!, "")
|
152
|
-
cleaned.sub!(@collection.
|
147
|
+
cleaned.sub!(@collection.relative_path, "") if @collection
|
153
148
|
cleaned
|
154
149
|
end
|
155
150
|
end
|
@@ -159,12 +154,12 @@ module Bridgetown
|
|
159
154
|
# be overriden in the collection's configuration in bridgetown.config.yml.
|
160
155
|
def url
|
161
156
|
@url ||= begin
|
162
|
-
base = if @collection.nil?
|
157
|
+
base = if @collection.nil? || @collection.label == "posts"
|
163
158
|
cleaned_relative_path
|
164
159
|
else
|
165
160
|
Bridgetown::URL.new(
|
166
|
-
:
|
167
|
-
:
|
161
|
+
template: @collection.url_template,
|
162
|
+
placeholders: placeholders
|
168
163
|
)
|
169
164
|
end.to_s.chomp("/")
|
170
165
|
base << extname
|
@@ -82,11 +82,11 @@ module Bridgetown
|
|
82
82
|
def render_rouge(code)
|
83
83
|
require "rouge"
|
84
84
|
formatter = ::Rouge::Formatters::HTMLLegacy.new(
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
85
|
+
line_numbers: @highlight_options[:linenos],
|
86
|
+
wrap: false,
|
87
|
+
css_class: "highlight",
|
88
|
+
gutter_class: "gutter",
|
89
|
+
code_class: "code"
|
90
90
|
)
|
91
91
|
lexer = ::Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
92
92
|
formatter.format(lexer.lex(code))
|
@@ -212,7 +212,7 @@ module Bridgetown
|
|
212
212
|
string = I18n.transliterate(string)
|
213
213
|
end
|
214
214
|
|
215
|
-
slug = replace_character_sequence_with_hyphen(string, :
|
215
|
+
slug = replace_character_sequence_with_hyphen(string, mode: mode)
|
216
216
|
|
217
217
|
# Remove leading/trailing hyphen
|
218
218
|
slug.gsub!(%r!^\-|\-$!i, "")
|
@@ -8,14 +8,14 @@ module Bridgetown
|
|
8
8
|
ESCAPE = format("%c", 27)
|
9
9
|
MATCH = %r!#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m!ix.freeze
|
10
10
|
COLORS = {
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
11
|
+
red: 31,
|
12
|
+
green: 32,
|
13
|
+
black: 30,
|
14
|
+
magenta: 35,
|
15
|
+
yellow: 33,
|
16
|
+
white: 37,
|
17
|
+
blue: 34,
|
18
|
+
cyan: 36,
|
19
19
|
}.freeze
|
20
20
|
|
21
21
|
# Strip ANSI from the current string. It also strips cursor stuff,
|
@@ -7,7 +7,7 @@ module Bridgetown
|
|
7
7
|
|
8
8
|
# TODO: jruby is NOT supported by Bridgetown. This should probably
|
9
9
|
# get removed.
|
10
|
-
{
|
10
|
+
{ jruby?: "jruby", mri?: "ruby" }.each do |k, v|
|
11
11
|
define_method k do
|
12
12
|
::RUBY_ENGINE == v
|
13
13
|
end
|
@@ -55,7 +55,7 @@ module Bridgetown
|
|
55
55
|
# platforms. This is mostly useful for `bridgetown doctor` and for testing
|
56
56
|
# where we kick off certain tests based on the platform.
|
57
57
|
|
58
|
-
{
|
58
|
+
{ osx?: %r!darwin|mac os!, unix?: %r!solaris|bsd! }.each do |k, v|
|
59
59
|
define_method k do
|
60
60
|
!!(
|
61
61
|
RbConfig::CONFIG["host_os"] =~ v
|
@@ -30,7 +30,7 @@ module Bridgetown
|
|
30
30
|
#
|
31
31
|
# Format the hour as a two-digit number.
|
32
32
|
# Establish the minutes based on modulo expression.
|
33
|
-
hh = format("%<hour>02d", :
|
33
|
+
hh = format("%<hour>02d", hour: absolute_hour(difference).ceil)
|
34
34
|
mm = modulo.zero? ? "00" : "30"
|
35
35
|
|
36
36
|
Bridgetown.logger.debug "Timezone:", "#{timezone} #{offset}#{hh}:#{mm}"
|
@@ -9,23 +9,17 @@ module Bridgetown
|
|
9
9
|
# Public: Continuously watch for file changes and rebuild the site
|
10
10
|
# whenever a change is detected.
|
11
11
|
#
|
12
|
-
#
|
13
|
-
# reused and the options Hash ignored. Otherwise, a new site instance will
|
14
|
-
# be instantiated from the options Hash and used.
|
15
|
-
#
|
12
|
+
# site - The current site instance
|
16
13
|
# options - A Hash containing the site configuration
|
17
|
-
# site - The current site instance (populated starting with Bridgetown 3.2)
|
18
|
-
# (optional, default: nil)
|
19
14
|
#
|
20
15
|
# Returns nothing.
|
21
|
-
def watch(
|
16
|
+
def watch(site, options)
|
22
17
|
ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options["verbose"]
|
23
18
|
|
24
|
-
site ||= Bridgetown::Site.new(options)
|
25
19
|
listener = build_listener(site, options)
|
26
20
|
listener.start
|
27
21
|
|
28
|
-
Bridgetown.logger.info "Auto-regeneration:", "enabled
|
22
|
+
Bridgetown.logger.info "Auto-regeneration:", "enabled."
|
29
23
|
|
30
24
|
unless options["serving"]
|
31
25
|
trap("INT") do
|
@@ -45,8 +39,8 @@ module Bridgetown
|
|
45
39
|
def build_listener(site, options)
|
46
40
|
Listen.to(
|
47
41
|
options["source"],
|
48
|
-
:
|
49
|
-
:
|
42
|
+
ignore: listen_ignore_paths(options),
|
43
|
+
force_polling: options["force_polling"],
|
50
44
|
&listen_handler(site)
|
51
45
|
)
|
52
46
|
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.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|