jekyll 4.2.1 → 4.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +474 -350
  3. data/LICENSE +21 -21
  4. data/README.markdown +83 -86
  5. data/exe/jekyll +57 -57
  6. data/lib/blank_template/_config.yml +3 -3
  7. data/lib/blank_template/_layouts/default.html +12 -12
  8. data/lib/blank_template/_sass/{main.scss → base.scss} +9 -9
  9. data/lib/blank_template/assets/css/main.scss +4 -4
  10. data/lib/blank_template/index.md +8 -8
  11. data/lib/jekyll/cache.rb +186 -190
  12. data/lib/jekyll/cleaner.rb +111 -111
  13. data/lib/jekyll/collection.rb +310 -309
  14. data/lib/jekyll/command.rb +105 -105
  15. data/lib/jekyll/commands/build.rb +82 -93
  16. data/lib/jekyll/commands/clean.rb +44 -45
  17. data/lib/jekyll/commands/doctor.rb +177 -177
  18. data/lib/jekyll/commands/help.rb +34 -34
  19. data/lib/jekyll/commands/new.rb +168 -169
  20. data/lib/jekyll/commands/new_theme.rb +39 -40
  21. data/lib/jekyll/commands/serve/live_reload_reactor.rb +119 -122
  22. data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
  23. data/lib/jekyll/commands/serve/mime_types_charset.json +71 -0
  24. data/lib/jekyll/commands/serve/servlet.rb +206 -202
  25. data/lib/jekyll/commands/serve/websockets.rb +81 -81
  26. data/lib/jekyll/commands/serve.rb +367 -362
  27. data/lib/jekyll/configuration.rb +313 -313
  28. data/lib/jekyll/converter.rb +54 -54
  29. data/lib/jekyll/converters/identity.rb +41 -41
  30. data/lib/jekyll/converters/markdown/kramdown_parser.rb +197 -199
  31. data/lib/jekyll/converters/markdown.rb +113 -113
  32. data/lib/jekyll/converters/smartypants.rb +70 -70
  33. data/lib/jekyll/convertible.rb +257 -257
  34. data/lib/jekyll/deprecator.rb +50 -50
  35. data/lib/jekyll/document.rb +543 -544
  36. data/lib/jekyll/drops/collection_drop.rb +20 -20
  37. data/lib/jekyll/drops/document_drop.rb +74 -70
  38. data/lib/jekyll/drops/drop.rb +293 -293
  39. data/lib/jekyll/drops/excerpt_drop.rb +23 -19
  40. data/lib/jekyll/drops/jekyll_drop.rb +32 -32
  41. data/lib/jekyll/drops/site_drop.rb +66 -66
  42. data/lib/jekyll/drops/static_file_drop.rb +14 -14
  43. data/lib/jekyll/drops/theme_drop.rb +36 -0
  44. data/lib/jekyll/drops/unified_payload_drop.rb +30 -26
  45. data/lib/jekyll/drops/url_drop.rb +140 -140
  46. data/lib/jekyll/entry_filter.rb +117 -121
  47. data/lib/jekyll/errors.rb +20 -20
  48. data/lib/jekyll/excerpt.rb +200 -201
  49. data/lib/jekyll/external.rb +75 -79
  50. data/lib/jekyll/filters/date_filters.rb +110 -110
  51. data/lib/jekyll/filters/grouping_filters.rb +64 -64
  52. data/lib/jekyll/filters/url_filters.rb +98 -98
  53. data/lib/jekyll/filters.rb +532 -535
  54. data/lib/jekyll/frontmatter_defaults.rb +238 -240
  55. data/lib/jekyll/generator.rb +5 -5
  56. data/lib/jekyll/hooks.rb +107 -107
  57. data/lib/jekyll/inclusion.rb +32 -32
  58. data/lib/jekyll/layout.rb +55 -67
  59. data/lib/jekyll/liquid_extensions.rb +22 -22
  60. data/lib/jekyll/liquid_renderer/file.rb +77 -77
  61. data/lib/jekyll/liquid_renderer/table.rb +45 -55
  62. data/lib/jekyll/liquid_renderer.rb +80 -80
  63. data/lib/jekyll/log_adapter.rb +151 -151
  64. data/lib/jekyll/mime.types +939 -866
  65. data/lib/jekyll/page.rb +215 -217
  66. data/lib/jekyll/page_excerpt.rb +25 -25
  67. data/lib/jekyll/page_without_a_file.rb +14 -14
  68. data/lib/jekyll/path_manager.rb +74 -74
  69. data/lib/jekyll/plugin.rb +92 -92
  70. data/lib/jekyll/plugin_manager.rb +123 -115
  71. data/lib/jekyll/profiler.rb +51 -58
  72. data/lib/jekyll/publisher.rb +23 -23
  73. data/lib/jekyll/reader.rb +209 -192
  74. data/lib/jekyll/readers/collection_reader.rb +23 -23
  75. data/lib/jekyll/readers/data_reader.rb +113 -79
  76. data/lib/jekyll/readers/layout_reader.rb +62 -62
  77. data/lib/jekyll/readers/page_reader.rb +25 -25
  78. data/lib/jekyll/readers/post_reader.rb +85 -85
  79. data/lib/jekyll/readers/static_file_reader.rb +25 -25
  80. data/lib/jekyll/readers/theme_assets_reader.rb +52 -52
  81. data/lib/jekyll/regenerator.rb +195 -195
  82. data/lib/jekyll/related_posts.rb +52 -52
  83. data/lib/jekyll/renderer.rb +263 -265
  84. data/lib/jekyll/site.rb +576 -551
  85. data/lib/jekyll/static_file.rb +205 -208
  86. data/lib/jekyll/stevenson.rb +60 -60
  87. data/lib/jekyll/tags/highlight.rb +114 -110
  88. data/lib/jekyll/tags/include.rb +275 -275
  89. data/lib/jekyll/tags/link.rb +42 -42
  90. data/lib/jekyll/tags/post_url.rb +106 -106
  91. data/lib/jekyll/theme.rb +90 -86
  92. data/lib/jekyll/theme_builder.rb +121 -121
  93. data/lib/jekyll/url.rb +167 -167
  94. data/lib/jekyll/utils/ansi.rb +57 -57
  95. data/lib/jekyll/utils/exec.rb +26 -26
  96. data/lib/jekyll/utils/internet.rb +37 -37
  97. data/lib/jekyll/utils/platforms.rb +67 -67
  98. data/lib/jekyll/utils/thread_event.rb +31 -31
  99. data/lib/jekyll/utils/win_tz.rb +46 -75
  100. data/lib/jekyll/utils.rb +371 -367
  101. data/lib/jekyll/version.rb +5 -5
  102. data/lib/jekyll.rb +195 -195
  103. data/lib/site_template/.gitignore +5 -5
  104. data/lib/site_template/404.html +25 -25
  105. data/lib/site_template/_config.yml +55 -55
  106. data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
  107. data/lib/site_template/about.markdown +18 -18
  108. data/lib/site_template/index.markdown +6 -6
  109. data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
  110. data/lib/theme_template/Gemfile +4 -4
  111. data/lib/theme_template/LICENSE.txt.erb +21 -21
  112. data/lib/theme_template/README.md.erb +50 -52
  113. data/lib/theme_template/_layouts/default.html +1 -1
  114. data/lib/theme_template/_layouts/page.html +5 -5
  115. data/lib/theme_template/_layouts/post.html +5 -5
  116. data/lib/theme_template/example/_config.yml.erb +1 -1
  117. data/lib/theme_template/example/_post.md +12 -12
  118. data/lib/theme_template/example/index.html +14 -14
  119. data/lib/theme_template/example/style.scss +7 -7
  120. data/lib/theme_template/gitignore.erb +6 -6
  121. data/lib/theme_template/theme.gemspec.erb +16 -16
  122. data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
  123. data/rubocop/jekyll/no_p_allowed.rb +23 -23
  124. data/rubocop/jekyll/no_puts_allowed.rb +23 -23
  125. data/rubocop/jekyll.rb +5 -5
  126. metadata +64 -18
data/lib/jekyll/cache.rb CHANGED
@@ -1,190 +1,186 @@
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
+ attr_accessor :cache_dir # class-wide cache location
15
+
16
+ attr_reader :base_cache, # class-wide base cache reader
17
+ :disk_cache_enabled # class-wide directive to write cache to disk
18
+
19
+ # Disable Marshaling cached items to disk
20
+ def disable_disk_cache!
21
+ @disk_cache_enabled = false
22
+ end
23
+
24
+ # Clear all caches
25
+ def clear
26
+ delete_cache_files
27
+ base_cache.each_value(&:clear)
28
+ end
29
+
30
+ # Compare the current config to the cached config
31
+ # If they are different, clear all caches
32
+ #
33
+ # Returns nothing.
34
+ def clear_if_config_changed(config)
35
+ config = config.inspect
36
+ cache = Jekyll::Cache.new "Jekyll::Cache"
37
+ return if cache.key?("config") && cache["config"] == config
38
+
39
+ clear
40
+ cache = Jekyll::Cache.new "Jekyll::Cache"
41
+ cache["config"] = config
42
+ nil
43
+ end
44
+
45
+ private
46
+
47
+ # Delete all cached items from all caches
48
+ #
49
+ # Returns nothing.
50
+ def delete_cache_files
51
+ FileUtils.rm_rf(@cache_dir) if disk_cache_enabled
52
+ end
53
+ end
54
+
55
+ #
56
+
57
+ # Get an existing named cache, or create a new one if none exists
58
+ #
59
+ # name - name of the cache
60
+ #
61
+ # Returns nothing.
62
+ def initialize(name)
63
+ @cache = Jekyll::Cache.base_cache[name] ||= {}
64
+ @name = name.gsub(%r![^\w\s-]!, "-")
65
+ end
66
+
67
+ # Clear this particular cache
68
+ def clear
69
+ delete_cache_files
70
+ @cache.clear
71
+ end
72
+
73
+ # Retrieve a cached item
74
+ # Raises if key does not exist in cache
75
+ #
76
+ # Returns cached value
77
+ def [](key)
78
+ return @cache[key] if @cache.key?(key)
79
+
80
+ path = path_to(hash(key))
81
+ if disk_cache_enabled? && File.file?(path) && File.readable?(path)
82
+ @cache[key] = load(path)
83
+ else
84
+ raise
85
+ end
86
+ end
87
+
88
+ # Add an item to cache
89
+ #
90
+ # Returns nothing.
91
+ def []=(key, value)
92
+ @cache[key] = value
93
+ return unless disk_cache_enabled?
94
+
95
+ path = path_to(hash(key))
96
+ value = new Hash(value) if value.is_a?(Hash) && !value.default.nil?
97
+ dump(path, value)
98
+ rescue TypeError
99
+ Jekyll.logger.debug "Cache:", "Cannot dump object #{key}"
100
+ end
101
+
102
+ # If an item already exists in the cache, retrieve it.
103
+ # Else execute code block, and add the result to the cache, and return that result.
104
+ def getset(key)
105
+ self[key]
106
+ rescue StandardError
107
+ value = yield
108
+ self[key] = value
109
+ value
110
+ end
111
+
112
+ # Remove one particular item from the cache
113
+ #
114
+ # Returns nothing.
115
+ def delete(key)
116
+ @cache.delete(key)
117
+ File.delete(path_to(hash(key))) if disk_cache_enabled?
118
+ end
119
+
120
+ # Check if `key` already exists in this cache
121
+ #
122
+ # Returns true if key exists in the cache, false otherwise
123
+ def key?(key)
124
+ # First, check if item is already cached in memory
125
+ return true if @cache.key?(key)
126
+ # Otherwise, it might be cached on disk
127
+ # but we should not consider the disk cache if it is disabled
128
+ return false unless disk_cache_enabled?
129
+
130
+ path = path_to(hash(key))
131
+ File.file?(path) && File.readable?(path)
132
+ end
133
+
134
+ def disk_cache_enabled?
135
+ !!Jekyll::Cache.disk_cache_enabled
136
+ end
137
+
138
+ private
139
+
140
+ # Given a hashed key, return the path to where this item would be saved on disk.
141
+ def path_to(hash = nil)
142
+ @base_dir ||= File.join(Jekyll::Cache.cache_dir, @name)
143
+ return @base_dir if hash.nil?
144
+
145
+ File.join(@base_dir, hash[0..1], hash[2..-1]).freeze
146
+ end
147
+
148
+ # Given a key, return a SHA2 hash that can be used for caching this item to disk.
149
+ def hash(key)
150
+ Digest::SHA2.hexdigest(key).freeze
151
+ end
152
+
153
+ # Remove all this caches items from disk
154
+ #
155
+ # Returns nothing.
156
+ def delete_cache_files
157
+ FileUtils.rm_rf(path_to) if disk_cache_enabled?
158
+ end
159
+
160
+ # Load `path` from disk and return the result.
161
+ # This MUST NEVER be called in Safe Mode
162
+ # rubocop:disable Security/MarshalLoad
163
+ def load(path)
164
+ raise unless disk_cache_enabled?
165
+
166
+ cached_file = File.open(path, "rb")
167
+ value = Marshal.load(cached_file)
168
+ cached_file.close
169
+ value
170
+ end
171
+ # rubocop:enable Security/MarshalLoad
172
+
173
+ # Given a path and a value, save value to disk at path.
174
+ # This should NEVER be called in Safe Mode
175
+ #
176
+ # Returns nothing.
177
+ def dump(path, value)
178
+ return unless disk_cache_enabled?
179
+
180
+ FileUtils.mkdir_p(File.dirname(path))
181
+ File.open(path, "wb") do |cached_file|
182
+ Marshal.dump(value, cached_file)
183
+ end
184
+ end
185
+ end
186
+ end
@@ -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!/\.{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
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 metadata 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