lib/nanoc/data_sources/filesystem.rb in nanoc-4.12.14 vs lib/nanoc/data_sources/filesystem.rb in nanoc-4.12.15
- old
+ new
@@ -149,11 +149,11 @@
end
end
end
def read_proto_document(content_filename, meta_filename, klass)
- is_binary = content_filename && !@site_config[:text_extensions].include?(File.extname(content_filename)[1..-1])
+ is_binary = content_filename && !@site_config[:text_extensions].include?(File.extname(content_filename)[1..])
if is_binary && klass == Nanoc::Core::Item
meta = (meta_filename && YAML.safe_load_file(meta_filename, permitted_classes: PERMITTED_YAML_CLASSES)) || {}
ProtoDocument.new(is_binary: true, filename: content_filename, attributes: meta)
@@ -250,24 +250,24 @@
def extra_attributes_for(content_filename, meta_filename)
{
filename: content_filename,
content_filename: content_filename,
meta_filename: meta_filename,
- extension: content_filename ? ext_of(content_filename)[1..-1] : nil,
+ extension: content_filename ? ext_of(content_filename)[1..] : nil,
mtime: mtime_of(content_filename, meta_filename),
}
end
def attributes_for(proto_doc, content_filename, meta_filename)
extra_attributes_for(content_filename, meta_filename).merge(proto_doc.attributes)
end
def identifier_for(content_filename, meta_filename, dir_name)
if content_filename
- identifier_for_filename(content_filename[dir_name.length..-1])
+ identifier_for_filename(content_filename[dir_name.length..])
elsif meta_filename
- identifier_for_filename(meta_filename[dir_name.length..-1])
+ identifier_for_filename(meta_filename[dir_name.length..])
else
raise 'meta_filename and content_filename are both nil'
end
end
@@ -282,19 +282,15 @@
end
def mtime_of(content_filename, meta_filename)
meta_mtime = meta_filename ? File.stat(meta_filename).mtime : nil
content_mtime = content_filename ? File.stat(content_filename).mtime : nil
- if meta_mtime && content_mtime
- meta_mtime > content_mtime ? meta_mtime : content_mtime
- elsif meta_mtime
- meta_mtime
- elsif content_mtime
- content_mtime
- else
- raise 'meta_mtime and content_mtime are both nil'
- end
+
+ mtime = [meta_mtime, content_mtime].compact.max
+ raise 'meta_mtime and content_mtime are both nil' unless mtime
+
+ mtime
end
# e.g.
#
# {
@@ -328,10 +324,10 @@
all[basename] = []
all[basename][0] =
meta_filenames[0] ? 'yaml' : nil
all[basename][1] =
- content_filenames.any? ? content_filenames.map { |fn| ext_of(fn)[1..-1] || '' } : [nil]
+ content_filenames.any? ? content_filenames.map { |fn| ext_of(fn)[1..] || '' } : [nil]
end
all
end