jekyll 4.0.1 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +350 -163
- data/LICENSE +21 -21
- data/README.markdown +86 -90
- data/exe/jekyll +57 -57
- data/lib/blank_template/_config.yml +3 -3
- data/lib/blank_template/_layouts/default.html +12 -12
- data/lib/blank_template/_sass/main.scss +9 -9
- data/lib/blank_template/assets/css/main.scss +4 -4
- data/lib/blank_template/index.md +8 -8
- data/lib/jekyll/cache.rb +190 -190
- data/lib/jekyll/cleaner.rb +111 -111
- data/lib/jekyll/collection.rb +309 -309
- data/lib/jekyll/command.rb +105 -103
- data/lib/jekyll/commands/build.rb +93 -93
- data/lib/jekyll/commands/clean.rb +45 -45
- data/lib/jekyll/commands/doctor.rb +177 -173
- data/lib/jekyll/commands/help.rb +34 -34
- data/lib/jekyll/commands/new.rb +169 -169
- data/lib/jekyll/commands/new_theme.rb +40 -42
- data/lib/jekyll/commands/serve/live_reload_reactor.rb +122 -122
- data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
- data/lib/jekyll/commands/serve/servlet.rb +202 -202
- data/lib/jekyll/commands/serve/websockets.rb +81 -81
- data/lib/jekyll/commands/serve.rb +362 -354
- data/lib/jekyll/configuration.rb +313 -316
- data/lib/jekyll/converter.rb +54 -54
- data/lib/jekyll/converters/identity.rb +41 -41
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +199 -130
- data/lib/jekyll/converters/markdown.rb +113 -113
- data/lib/jekyll/converters/smartypants.rb +70 -70
- data/lib/jekyll/convertible.rb +257 -254
- data/lib/jekyll/deprecator.rb +50 -50
- data/lib/jekyll/document.rb +544 -522
- data/lib/jekyll/drops/collection_drop.rb +20 -20
- data/lib/jekyll/drops/document_drop.rb +70 -69
- data/lib/jekyll/drops/drop.rb +293 -215
- data/lib/jekyll/drops/excerpt_drop.rb +19 -19
- data/lib/jekyll/drops/jekyll_drop.rb +32 -32
- data/lib/jekyll/drops/site_drop.rb +66 -66
- data/lib/jekyll/drops/static_file_drop.rb +14 -14
- data/lib/jekyll/drops/unified_payload_drop.rb +26 -26
- data/lib/jekyll/drops/url_drop.rb +140 -132
- data/lib/jekyll/entry_filter.rb +121 -110
- data/lib/jekyll/errors.rb +20 -20
- data/lib/jekyll/excerpt.rb +201 -201
- data/lib/jekyll/external.rb +79 -79
- data/lib/jekyll/filters/date_filters.rb +110 -110
- data/lib/jekyll/filters/grouping_filters.rb +64 -64
- data/lib/jekyll/filters/url_filters.rb +98 -68
- data/lib/jekyll/filters.rb +535 -454
- data/lib/jekyll/frontmatter_defaults.rb +240 -245
- data/lib/jekyll/generator.rb +5 -5
- data/lib/jekyll/hooks.rb +107 -106
- data/lib/jekyll/inclusion.rb +32 -0
- data/lib/jekyll/layout.rb +67 -62
- data/lib/jekyll/liquid_extensions.rb +22 -22
- data/lib/jekyll/liquid_renderer/file.rb +77 -77
- data/lib/jekyll/liquid_renderer/table.rb +55 -75
- data/lib/jekyll/liquid_renderer.rb +80 -77
- data/lib/jekyll/log_adapter.rb +151 -151
- data/lib/jekyll/mime.types +866 -866
- data/lib/jekyll/page.rb +217 -186
- data/lib/jekyll/page_excerpt.rb +25 -0
- data/lib/jekyll/page_without_a_file.rb +14 -14
- data/lib/jekyll/path_manager.rb +74 -31
- data/lib/jekyll/plugin.rb +92 -92
- data/lib/jekyll/plugin_manager.rb +115 -115
- data/lib/jekyll/profiler.rb +58 -0
- data/lib/jekyll/publisher.rb +23 -23
- data/lib/jekyll/reader.rb +192 -187
- data/lib/jekyll/readers/collection_reader.rb +23 -22
- data/lib/jekyll/readers/data_reader.rb +79 -75
- data/lib/jekyll/readers/layout_reader.rb +62 -61
- data/lib/jekyll/readers/page_reader.rb +25 -24
- data/lib/jekyll/readers/post_reader.rb +85 -84
- data/lib/jekyll/readers/static_file_reader.rb +25 -24
- data/lib/jekyll/readers/theme_assets_reader.rb +52 -51
- data/lib/jekyll/regenerator.rb +195 -195
- data/lib/jekyll/related_posts.rb +52 -52
- data/lib/jekyll/renderer.rb +265 -267
- data/lib/jekyll/site.rb +551 -527
- data/lib/jekyll/static_file.rb +208 -203
- data/lib/jekyll/stevenson.rb +60 -60
- data/lib/jekyll/tags/highlight.rb +110 -110
- data/lib/jekyll/tags/include.rb +275 -221
- data/lib/jekyll/tags/link.rb +42 -41
- data/lib/jekyll/tags/post_url.rb +106 -107
- data/lib/jekyll/theme.rb +86 -80
- data/lib/jekyll/theme_builder.rb +121 -121
- data/lib/jekyll/url.rb +167 -164
- data/lib/jekyll/utils/ansi.rb +57 -57
- data/lib/jekyll/utils/exec.rb +26 -26
- data/lib/jekyll/utils/internet.rb +37 -37
- data/lib/jekyll/utils/platforms.rb +67 -82
- data/lib/jekyll/utils/thread_event.rb +31 -31
- data/lib/jekyll/utils/win_tz.rb +75 -75
- data/lib/jekyll/utils.rb +367 -367
- data/lib/jekyll/version.rb +5 -5
- data/lib/jekyll.rb +195 -206
- data/lib/site_template/.gitignore +5 -5
- data/lib/site_template/404.html +25 -25
- data/lib/site_template/_config.yml +55 -55
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
- data/lib/site_template/about.markdown +18 -18
- data/lib/site_template/index.markdown +6 -6
- data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
- data/lib/theme_template/Gemfile +4 -4
- data/lib/theme_template/LICENSE.txt.erb +21 -21
- data/lib/theme_template/README.md.erb +52 -52
- data/lib/theme_template/_layouts/default.html +1 -1
- data/lib/theme_template/_layouts/page.html +5 -5
- data/lib/theme_template/_layouts/post.html +5 -5
- data/lib/theme_template/example/_config.yml.erb +1 -1
- data/lib/theme_template/example/_post.md +12 -12
- data/lib/theme_template/example/index.html +14 -14
- data/lib/theme_template/example/style.scss +7 -7
- data/lib/theme_template/gitignore.erb +6 -6
- data/lib/theme_template/theme.gemspec.erb +16 -19
- data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
- data/rubocop/jekyll/no_p_allowed.rb +23 -23
- data/rubocop/jekyll/no_puts_allowed.rb +23 -23
- data/rubocop/jekyll.rb +5 -5
- metadata +20 -38
data/lib/jekyll/cache.rb
CHANGED
@@ -1,190 +1,190 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "digest"
|
4
|
-
|
5
|
-
module Jekyll
|
6
|
-
class Cache
|
7
|
-
# class-wide base cache
|
8
|
-
@base_cache = {}
|
9
|
-
|
10
|
-
# class-wide directive to write cache to disk is enabled by default
|
11
|
-
@disk_cache_enabled = true
|
12
|
-
|
13
|
-
class << self
|
14
|
-
# class-wide cache location
|
15
|
-
attr_accessor :cache_dir
|
16
|
-
|
17
|
-
# class-wide directive to write cache to disk
|
18
|
-
attr_reader :disk_cache_enabled
|
19
|
-
|
20
|
-
# class-wide base cache reader
|
21
|
-
attr_reader :base_cache
|
22
|
-
|
23
|
-
# Disable Marshaling cached items to disk
|
24
|
-
def disable_disk_cache!
|
25
|
-
@disk_cache_enabled = false
|
26
|
-
end
|
27
|
-
|
28
|
-
# Clear all caches
|
29
|
-
def clear
|
30
|
-
delete_cache_files
|
31
|
-
base_cache.each_value(&:clear)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Compare the current config to the cached config
|
35
|
-
# If they are different, clear all caches
|
36
|
-
#
|
37
|
-
# Returns nothing.
|
38
|
-
def clear_if_config_changed(config)
|
39
|
-
config = config.inspect
|
40
|
-
cache = Jekyll::Cache.new "Jekyll::Cache"
|
41
|
-
return if cache.key?("config") && cache["config"] == config
|
42
|
-
|
43
|
-
clear
|
44
|
-
cache = Jekyll::Cache.new "Jekyll::Cache"
|
45
|
-
cache["config"] = config
|
46
|
-
nil
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
# Delete all cached items from all caches
|
52
|
-
#
|
53
|
-
# Returns nothing.
|
54
|
-
def delete_cache_files
|
55
|
-
FileUtils.rm_rf(@cache_dir) if disk_cache_enabled
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
# Get an existing named cache, or create a new one if none exists
|
62
|
-
#
|
63
|
-
# name - name of the cache
|
64
|
-
#
|
65
|
-
# Returns nothing.
|
66
|
-
def initialize(name)
|
67
|
-
@cache = Jekyll::Cache.base_cache[name] ||= {}
|
68
|
-
@name = name.gsub(%r![^\w\s-]!, "-")
|
69
|
-
end
|
70
|
-
|
71
|
-
# Clear this particular cache
|
72
|
-
def clear
|
73
|
-
delete_cache_files
|
74
|
-
@cache.clear
|
75
|
-
end
|
76
|
-
|
77
|
-
# Retrieve a cached item
|
78
|
-
# Raises if key does not exist in cache
|
79
|
-
#
|
80
|
-
# Returns cached value
|
81
|
-
def [](key)
|
82
|
-
return @cache[key] if @cache.key?(key)
|
83
|
-
|
84
|
-
path = path_to(hash(key))
|
85
|
-
if disk_cache_enabled? && File.file?(path) && File.readable?(path)
|
86
|
-
@cache[key] = load(path)
|
87
|
-
else
|
88
|
-
raise
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Add an item to cache
|
93
|
-
#
|
94
|
-
# Returns nothing.
|
95
|
-
def []=(key, value)
|
96
|
-
@cache[key] = value
|
97
|
-
return unless disk_cache_enabled?
|
98
|
-
|
99
|
-
path = path_to(hash(key))
|
100
|
-
value = new Hash(value) if value.is_a?(Hash) && !value.default.nil?
|
101
|
-
dump(path, value)
|
102
|
-
rescue TypeError
|
103
|
-
Jekyll.logger.debug "Cache:", "Cannot dump object #{key}"
|
104
|
-
end
|
105
|
-
|
106
|
-
# If an item already exists in the cache, retrieve it.
|
107
|
-
# Else execute code block, and add the result to the cache, and return that result.
|
108
|
-
def getset(key)
|
109
|
-
self[key]
|
110
|
-
rescue StandardError
|
111
|
-
value = yield
|
112
|
-
self[key] = value
|
113
|
-
value
|
114
|
-
end
|
115
|
-
|
116
|
-
# Remove one particular item from the cache
|
117
|
-
#
|
118
|
-
# Returns nothing.
|
119
|
-
def delete(key)
|
120
|
-
@cache.delete(key)
|
121
|
-
File.delete(path_to(hash(key))) if disk_cache_enabled?
|
122
|
-
end
|
123
|
-
|
124
|
-
# Check if `key` already exists in this cache
|
125
|
-
#
|
126
|
-
# Returns true if key exists in the cache, false otherwise
|
127
|
-
def key?(key)
|
128
|
-
# First, check if item is already cached in memory
|
129
|
-
return true if @cache.key?(key)
|
130
|
-
# Otherwise, it might be cached on disk
|
131
|
-
# but we should not consider the disk cache if it is disabled
|
132
|
-
return false unless disk_cache_enabled?
|
133
|
-
|
134
|
-
path = path_to(hash(key))
|
135
|
-
File.file?(path) && File.readable?(path)
|
136
|
-
end
|
137
|
-
|
138
|
-
def disk_cache_enabled?
|
139
|
-
!!Jekyll::Cache.disk_cache_enabled
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
# Given a hashed key, return the path to where this item would be saved on disk.
|
145
|
-
def path_to(hash = nil)
|
146
|
-
@base_dir ||= File.join(Jekyll::Cache.cache_dir, @name)
|
147
|
-
return @base_dir if hash.nil?
|
148
|
-
|
149
|
-
File.join(@base_dir, hash[0..1], hash[2..-1]).freeze
|
150
|
-
end
|
151
|
-
|
152
|
-
# Given a key, return a SHA2 hash that can be used for caching this item to disk.
|
153
|
-
def hash(key)
|
154
|
-
Digest::SHA2.hexdigest(key).freeze
|
155
|
-
end
|
156
|
-
|
157
|
-
# Remove all this caches items from disk
|
158
|
-
#
|
159
|
-
# Returns nothing.
|
160
|
-
def delete_cache_files
|
161
|
-
FileUtils.rm_rf(path_to) if disk_cache_enabled?
|
162
|
-
end
|
163
|
-
|
164
|
-
# Load `path` from disk and return the result.
|
165
|
-
# This MUST NEVER be called in Safe Mode
|
166
|
-
# rubocop:disable Security/MarshalLoad
|
167
|
-
def load(path)
|
168
|
-
raise unless disk_cache_enabled?
|
169
|
-
|
170
|
-
cached_file = File.open(path, "rb")
|
171
|
-
value = Marshal.load(cached_file)
|
172
|
-
cached_file.close
|
173
|
-
value
|
174
|
-
end
|
175
|
-
# rubocop:enable Security/MarshalLoad
|
176
|
-
|
177
|
-
# Given a path and a value, save value to disk at path.
|
178
|
-
# This should NEVER be called in Safe Mode
|
179
|
-
#
|
180
|
-
# Returns nothing.
|
181
|
-
def dump(path, value)
|
182
|
-
return unless disk_cache_enabled?
|
183
|
-
|
184
|
-
FileUtils.mkdir_p(File.dirname(path))
|
185
|
-
File.open(path, "wb") do |cached_file|
|
186
|
-
Marshal.dump(value, cached_file)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Cache
|
7
|
+
# class-wide base cache
|
8
|
+
@base_cache = {}
|
9
|
+
|
10
|
+
# class-wide directive to write cache to disk is enabled by default
|
11
|
+
@disk_cache_enabled = true
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# class-wide cache location
|
15
|
+
attr_accessor :cache_dir
|
16
|
+
|
17
|
+
# class-wide directive to write cache to disk
|
18
|
+
attr_reader :disk_cache_enabled
|
19
|
+
|
20
|
+
# class-wide base cache reader
|
21
|
+
attr_reader :base_cache
|
22
|
+
|
23
|
+
# Disable Marshaling cached items to disk
|
24
|
+
def disable_disk_cache!
|
25
|
+
@disk_cache_enabled = false
|
26
|
+
end
|
27
|
+
|
28
|
+
# Clear all caches
|
29
|
+
def clear
|
30
|
+
delete_cache_files
|
31
|
+
base_cache.each_value(&:clear)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Compare the current config to the cached config
|
35
|
+
# If they are different, clear all caches
|
36
|
+
#
|
37
|
+
# Returns nothing.
|
38
|
+
def clear_if_config_changed(config)
|
39
|
+
config = config.inspect
|
40
|
+
cache = Jekyll::Cache.new "Jekyll::Cache"
|
41
|
+
return if cache.key?("config") && cache["config"] == config
|
42
|
+
|
43
|
+
clear
|
44
|
+
cache = Jekyll::Cache.new "Jekyll::Cache"
|
45
|
+
cache["config"] = config
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Delete all cached items from all caches
|
52
|
+
#
|
53
|
+
# Returns nothing.
|
54
|
+
def delete_cache_files
|
55
|
+
FileUtils.rm_rf(@cache_dir) if disk_cache_enabled
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
|
61
|
+
# Get an existing named cache, or create a new one if none exists
|
62
|
+
#
|
63
|
+
# name - name of the cache
|
64
|
+
#
|
65
|
+
# Returns nothing.
|
66
|
+
def initialize(name)
|
67
|
+
@cache = Jekyll::Cache.base_cache[name] ||= {}
|
68
|
+
@name = name.gsub(%r![^\w\s-]!, "-")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Clear this particular cache
|
72
|
+
def clear
|
73
|
+
delete_cache_files
|
74
|
+
@cache.clear
|
75
|
+
end
|
76
|
+
|
77
|
+
# Retrieve a cached item
|
78
|
+
# Raises if key does not exist in cache
|
79
|
+
#
|
80
|
+
# Returns cached value
|
81
|
+
def [](key)
|
82
|
+
return @cache[key] if @cache.key?(key)
|
83
|
+
|
84
|
+
path = path_to(hash(key))
|
85
|
+
if disk_cache_enabled? && File.file?(path) && File.readable?(path)
|
86
|
+
@cache[key] = load(path)
|
87
|
+
else
|
88
|
+
raise
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Add an item to cache
|
93
|
+
#
|
94
|
+
# Returns nothing.
|
95
|
+
def []=(key, value)
|
96
|
+
@cache[key] = value
|
97
|
+
return unless disk_cache_enabled?
|
98
|
+
|
99
|
+
path = path_to(hash(key))
|
100
|
+
value = new Hash(value) if value.is_a?(Hash) && !value.default.nil?
|
101
|
+
dump(path, value)
|
102
|
+
rescue TypeError
|
103
|
+
Jekyll.logger.debug "Cache:", "Cannot dump object #{key}"
|
104
|
+
end
|
105
|
+
|
106
|
+
# If an item already exists in the cache, retrieve it.
|
107
|
+
# Else execute code block, and add the result to the cache, and return that result.
|
108
|
+
def getset(key)
|
109
|
+
self[key]
|
110
|
+
rescue StandardError
|
111
|
+
value = yield
|
112
|
+
self[key] = value
|
113
|
+
value
|
114
|
+
end
|
115
|
+
|
116
|
+
# Remove one particular item from the cache
|
117
|
+
#
|
118
|
+
# Returns nothing.
|
119
|
+
def delete(key)
|
120
|
+
@cache.delete(key)
|
121
|
+
File.delete(path_to(hash(key))) if disk_cache_enabled?
|
122
|
+
end
|
123
|
+
|
124
|
+
# Check if `key` already exists in this cache
|
125
|
+
#
|
126
|
+
# Returns true if key exists in the cache, false otherwise
|
127
|
+
def key?(key)
|
128
|
+
# First, check if item is already cached in memory
|
129
|
+
return true if @cache.key?(key)
|
130
|
+
# Otherwise, it might be cached on disk
|
131
|
+
# but we should not consider the disk cache if it is disabled
|
132
|
+
return false unless disk_cache_enabled?
|
133
|
+
|
134
|
+
path = path_to(hash(key))
|
135
|
+
File.file?(path) && File.readable?(path)
|
136
|
+
end
|
137
|
+
|
138
|
+
def disk_cache_enabled?
|
139
|
+
!!Jekyll::Cache.disk_cache_enabled
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
# Given a hashed key, return the path to where this item would be saved on disk.
|
145
|
+
def path_to(hash = nil)
|
146
|
+
@base_dir ||= File.join(Jekyll::Cache.cache_dir, @name)
|
147
|
+
return @base_dir if hash.nil?
|
148
|
+
|
149
|
+
File.join(@base_dir, hash[0..1], hash[2..-1]).freeze
|
150
|
+
end
|
151
|
+
|
152
|
+
# Given a key, return a SHA2 hash that can be used for caching this item to disk.
|
153
|
+
def hash(key)
|
154
|
+
Digest::SHA2.hexdigest(key).freeze
|
155
|
+
end
|
156
|
+
|
157
|
+
# Remove all this caches items from disk
|
158
|
+
#
|
159
|
+
# Returns nothing.
|
160
|
+
def delete_cache_files
|
161
|
+
FileUtils.rm_rf(path_to) if disk_cache_enabled?
|
162
|
+
end
|
163
|
+
|
164
|
+
# Load `path` from disk and return the result.
|
165
|
+
# This MUST NEVER be called in Safe Mode
|
166
|
+
# rubocop:disable Security/MarshalLoad
|
167
|
+
def load(path)
|
168
|
+
raise unless disk_cache_enabled?
|
169
|
+
|
170
|
+
cached_file = File.open(path, "rb")
|
171
|
+
value = Marshal.load(cached_file)
|
172
|
+
cached_file.close
|
173
|
+
value
|
174
|
+
end
|
175
|
+
# rubocop:enable Security/MarshalLoad
|
176
|
+
|
177
|
+
# Given a path and a value, save value to disk at path.
|
178
|
+
# This should NEVER be called in Safe Mode
|
179
|
+
#
|
180
|
+
# Returns nothing.
|
181
|
+
def dump(path, value)
|
182
|
+
return unless disk_cache_enabled?
|
183
|
+
|
184
|
+
FileUtils.mkdir_p(File.dirname(path))
|
185
|
+
File.open(path, "wb") do |cached_file|
|
186
|
+
Marshal.dump(value, cached_file)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
data/lib/jekyll/cleaner.rb
CHANGED
@@ -1,111 +1,111 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
# Handles the cleanup of a site's destination before it is built.
|
5
|
-
class Cleaner
|
6
|
-
HIDDEN_FILE_REGEX = %r
|
7
|
-
attr_reader :site
|
8
|
-
|
9
|
-
def initialize(site)
|
10
|
-
@site = site
|
11
|
-
end
|
12
|
-
|
13
|
-
# Cleans up the site's destination directory
|
14
|
-
def cleanup!
|
15
|
-
FileUtils.rm_rf(obsolete_files)
|
16
|
-
FileUtils.rm_rf(metadata_file) unless @site.incremental?
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# Private: The list of files and directories to be deleted during cleanup process
|
22
|
-
#
|
23
|
-
# Returns an Array of the file and directory paths
|
24
|
-
def obsolete_files
|
25
|
-
out = (existing_files - new_files - new_dirs + replaced_files).to_a
|
26
|
-
Jekyll::Hooks.trigger :clean, :on_obsolete, out
|
27
|
-
out
|
28
|
-
end
|
29
|
-
|
30
|
-
# Private: The metadata file storing dependency tree and build history
|
31
|
-
#
|
32
|
-
# Returns an Array with the metdata file as the only item
|
33
|
-
def metadata_file
|
34
|
-
[site.regenerator.metadata_file]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Private: The list of existing files, apart from those included in
|
38
|
-
# keep_files and hidden files.
|
39
|
-
#
|
40
|
-
# Returns a Set with the file paths
|
41
|
-
def existing_files
|
42
|
-
files = Set.new
|
43
|
-
regex = keep_file_regex
|
44
|
-
dirs = keep_dirs
|
45
|
-
|
46
|
-
Utils.safe_glob(site.in_dest_dir, ["**", "*"], File::FNM_DOTMATCH).each do |file|
|
47
|
-
next if file
|
48
|
-
|
49
|
-
files << file
|
50
|
-
end
|
51
|
-
|
52
|
-
files
|
53
|
-
end
|
54
|
-
|
55
|
-
# Private: The list of files to be created when site is built.
|
56
|
-
#
|
57
|
-
# Returns a Set with the file paths
|
58
|
-
def new_files
|
59
|
-
@new_files ||= Set.new.tap do |files|
|
60
|
-
site.each_site_file { |item| files << item.destination(site.dest) }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Private: The list of directories to be created when site is built.
|
65
|
-
# These are the parent directories of the files in #new_files.
|
66
|
-
#
|
67
|
-
# Returns a Set with the directory paths
|
68
|
-
def new_dirs
|
69
|
-
@new_dirs ||= new_files.flat_map { |file| parent_dirs(file) }.to_set
|
70
|
-
end
|
71
|
-
|
72
|
-
# Private: The list of parent directories of a given file
|
73
|
-
#
|
74
|
-
# Returns an Array with the directory paths
|
75
|
-
def parent_dirs(file)
|
76
|
-
parent_dir = File.dirname(file)
|
77
|
-
if parent_dir == site.dest
|
78
|
-
[]
|
79
|
-
else
|
80
|
-
parent_dirs(parent_dir).unshift(parent_dir)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Private: The list of existing files that will be replaced by a directory
|
85
|
-
# during build
|
86
|
-
#
|
87
|
-
# Returns a Set with the file paths
|
88
|
-
def replaced_files
|
89
|
-
new_dirs.select { |dir| File.file?(dir) }.to_set
|
90
|
-
end
|
91
|
-
|
92
|
-
# Private: The list of directories that need to be kept because they are
|
93
|
-
# parent directories of files specified in keep_files
|
94
|
-
#
|
95
|
-
# Returns a Set with the directory paths
|
96
|
-
def keep_dirs
|
97
|
-
site.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
98
|
-
end
|
99
|
-
|
100
|
-
# Private: Creates a regular expression from the config's keep_files array
|
101
|
-
#
|
102
|
-
# Examples
|
103
|
-
# ['.git','.svn'] with site.dest "/myblog/_site" creates
|
104
|
-
# the following regex: /\A\/myblog\/_site\/(\.git|\/.svn)/
|
105
|
-
#
|
106
|
-
# Returns the regular expression
|
107
|
-
def keep_file_regex
|
108
|
-
%r!\A#{Regexp.quote(site.dest)}
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
# Handles the cleanup of a site's destination before it is built.
|
5
|
+
class Cleaner
|
6
|
+
HIDDEN_FILE_REGEX = %r!/\.{1,2}$!.freeze
|
7
|
+
attr_reader :site
|
8
|
+
|
9
|
+
def initialize(site)
|
10
|
+
@site = site
|
11
|
+
end
|
12
|
+
|
13
|
+
# Cleans up the site's destination directory
|
14
|
+
def cleanup!
|
15
|
+
FileUtils.rm_rf(obsolete_files)
|
16
|
+
FileUtils.rm_rf(metadata_file) unless @site.incremental?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Private: The list of files and directories to be deleted during cleanup process
|
22
|
+
#
|
23
|
+
# Returns an Array of the file and directory paths
|
24
|
+
def obsolete_files
|
25
|
+
out = (existing_files - new_files - new_dirs + replaced_files).to_a
|
26
|
+
Jekyll::Hooks.trigger :clean, :on_obsolete, out
|
27
|
+
out
|
28
|
+
end
|
29
|
+
|
30
|
+
# Private: The metadata file storing dependency tree and build history
|
31
|
+
#
|
32
|
+
# Returns an Array with the metdata file as the only item
|
33
|
+
def metadata_file
|
34
|
+
[site.regenerator.metadata_file]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Private: The list of existing files, apart from those included in
|
38
|
+
# keep_files and hidden files.
|
39
|
+
#
|
40
|
+
# Returns a Set with the file paths
|
41
|
+
def existing_files
|
42
|
+
files = Set.new
|
43
|
+
regex = keep_file_regex
|
44
|
+
dirs = keep_dirs
|
45
|
+
|
46
|
+
Utils.safe_glob(site.in_dest_dir, ["**", "*"], File::FNM_DOTMATCH).each do |file|
|
47
|
+
next if HIDDEN_FILE_REGEX.match?(file) || regex.match?(file) || dirs.include?(file)
|
48
|
+
|
49
|
+
files << file
|
50
|
+
end
|
51
|
+
|
52
|
+
files
|
53
|
+
end
|
54
|
+
|
55
|
+
# Private: The list of files to be created when site is built.
|
56
|
+
#
|
57
|
+
# Returns a Set with the file paths
|
58
|
+
def new_files
|
59
|
+
@new_files ||= Set.new.tap do |files|
|
60
|
+
site.each_site_file { |item| files << item.destination(site.dest) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Private: The list of directories to be created when site is built.
|
65
|
+
# These are the parent directories of the files in #new_files.
|
66
|
+
#
|
67
|
+
# Returns a Set with the directory paths
|
68
|
+
def new_dirs
|
69
|
+
@new_dirs ||= new_files.flat_map { |file| parent_dirs(file) }.to_set
|
70
|
+
end
|
71
|
+
|
72
|
+
# Private: The list of parent directories of a given file
|
73
|
+
#
|
74
|
+
# Returns an Array with the directory paths
|
75
|
+
def parent_dirs(file)
|
76
|
+
parent_dir = File.dirname(file)
|
77
|
+
if parent_dir == site.dest
|
78
|
+
[]
|
79
|
+
else
|
80
|
+
parent_dirs(parent_dir).unshift(parent_dir)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Private: The list of existing files that will be replaced by a directory
|
85
|
+
# during build
|
86
|
+
#
|
87
|
+
# Returns a Set with the file paths
|
88
|
+
def replaced_files
|
89
|
+
new_dirs.select { |dir| File.file?(dir) }.to_set
|
90
|
+
end
|
91
|
+
|
92
|
+
# Private: The list of directories that need to be kept because they are
|
93
|
+
# parent directories of files specified in keep_files
|
94
|
+
#
|
95
|
+
# Returns a Set with the directory paths
|
96
|
+
def keep_dirs
|
97
|
+
site.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
|
98
|
+
end
|
99
|
+
|
100
|
+
# Private: Creates a regular expression from the config's keep_files array
|
101
|
+
#
|
102
|
+
# Examples
|
103
|
+
# ['.git','.svn'] with site.dest "/myblog/_site" creates
|
104
|
+
# the following regex: /\A\/myblog\/_site\/(\.git|\/.svn)/
|
105
|
+
#
|
106
|
+
# Returns the regular expression
|
107
|
+
def keep_file_regex
|
108
|
+
%r!\A#{Regexp.quote(site.dest)}/(#{Regexp.union(site.keep_files).source})!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|