lib/jekyll/utils.rb in jekyll-4.2.2 vs lib/jekyll/utils.rb in jekyll-4.3.0

- old
+ new

@@ -45,11 +45,18 @@ target end def mergable?(value) - value.is_a?(Hash) || value.is_a?(Drops::Drop) + case value + when Hash, Drops::Drop, DataHash + true + when DataEntry + mergable?(value.data) + else + false + end end def duplicable?(obj) case obj when nil, false, true, Symbol, Numeric @@ -126,11 +133,12 @@ # msg - (optional) the error message to show the user # # Returns the parsed date if successful, throws a FatalException # if not def parse_date(input, msg = "Input could not be parsed.") - Time.parse(input).localtime + @parse_date_cache ||= {} + @parse_date_cache[input] ||= Time.parse(input).localtime rescue ArgumentError raise Errors::InvalidDateError, "Invalid date '#{input}': #{msg}" end # Determines whether a given file has @@ -141,11 +149,11 @@ File.open(file, "rb", &:readline).match? %r!\A---\s*\r?\n! rescue EOFError false end - # Determine whether the given content string contains Liquid Tags or Vaiables + # Determine whether the given content string contains Liquid Tags or Variables # # Returns true is the string contains sequences of `{%` or `{{` def has_liquid_construct?(content) return false if content.nil? || content.empty? @@ -263,11 +271,11 @@ end template end - # Work the same way as Dir.glob but seperating the input into two parts + # Work the same way as Dir.glob but separating the input into two parts # ('dir' + '/' + 'pattern') to make sure the first part('dir') does not act # as a pattern. # # For example, Dir.glob("path[/*") always returns an empty array, # because the method fails to find the closing pattern to '[' which is ']' @@ -285,11 +293,11 @@ # dir - the dir where glob will be executed under # (the dir will be included to each result) # patterns - the patterns (or the pattern) which will be applied under the dir # flags - the flags which will be applied to the pattern # - # Returns matched pathes + # Returns matched paths def safe_glob(dir, patterns, flags = 0) return [] unless Dir.exist?(dir) pattern = File.join(Array(patterns)) return [dir] if pattern.empty? @@ -301,15 +309,18 @@ # Returns merged option hash for File.read of self.site (if exists) # and a given param def merged_file_read_opts(site, opts) merged = (site ? site.file_read_opts : {}).merge(opts) - if merged[:encoding] && !merged[:encoding].start_with?("bom|") + + # always use BOM when reading UTF-encoded files + if merged[:encoding]&.downcase&.start_with?("utf-") merged[:encoding] = "bom|#{merged[:encoding]}" end - if merged["encoding"] && !merged["encoding"].start_with?("bom|") + if merged["encoding"]&.downcase&.start_with?("utf-") merged["encoding"] = "bom|#{merged["encoding"]}" end + merged end private