lib/nanoc3/data_sources/filesystem_verbose.rb in nanoc3-3.1.2 vs lib/nanoc3/data_sources/filesystem_verbose.rb in nanoc3-3.1.3
- old
+ new
@@ -62,13 +62,19 @@
File.open(content_filename, 'w') { |io| io.write(content) }
end
# See {Nanoc3::DataSources::Filesystem#filename_for}.
def filename_for(base_filename, ext)
- last_part = base_filename.split('/')[-1]
- base_glob = base_filename.split('/')[0..-2].join('/') + "/{index,#{last_part}}."
+ return nil if ext.nil?
- ext ? Dir[base_glob + ext][0] : nil
+ last_component = base_filename[%r{[^/]+$}]
+ possibilities = [
+ base_filename + (ext.empty? ? '' : '.' + ext), # foo/bar.html
+ base_filename + '/' + last_component + (ext.empty? ? '' : '.' + ext), # foo/bar/bar.html
+ base_filename + '/' + 'index' + (ext.empty? ? '' : '.' + ext) # foo/bar/index.html
+ ]
+
+ possibilities.find { |p| File.file?(p) }
end
# See {Nanoc3::DataSources::Filesystem#identifier_for_filename}.
def identifier_for_filename(filename)
filename.sub(/[^\/]+\.yaml$/, '')