diff --git a/features/data.feature b/features/data.feature index e44be8a5..41f476a4 100644 --- a/features/data.feature +++ b/features/data.feature @@ -59,6 +59,20 @@ Feature: Data And I should see "Jack" in "_site/index.html" And I should see "Leon" in "_site/index.html" + Scenario: autoload *.tsv files in _data directory + Given I have a _data directory + And I have a "_data/members.tsv" file with content: + """ + name age + Jack 28 + Leon 34 + """ + And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}" + When I run jekyll build + Then the "_site/index.html" file should exist + And I should see "Jack" in "_site/index.html" + And I should see "Leon" in "_site/index.html" + Scenario: autoload *.yml files in _data directory with space in file name Given I have a _data directory And I have a "_data/team members.yml" file with content: diff --git a/lib/jekyll/readers/data_reader.rb b/lib/jekyll/readers/data_reader.rb index 1083d62b..63db7c6d 100644 --- a/lib/jekyll/readers/data_reader.rb +++ b/lib/jekyll/readers/data_reader.rb @@ -19,7 +19,7 @@ module Jekyll @content end - # Read and parse all .yaml, .yml, .json, and .csv + # Read and parse all .yaml, .yml, .json, .csv and .tsv # files under and add them to the variable. # # dir - The string absolute path of the directory to read. @@ -30,7 +30,7 @@ module Jekyll return unless File.directory?(dir) && !@entry_filter.symlink?(dir) entries = Dir.chdir(dir) do - Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) } + Dir["*.{yaml,yml,json,csv,tsv}"] + Dir["*"].select { |fn| File.directory?(fn) } end entries.each do |entry| @@ -56,6 +56,12 @@ module Jekyll :headers => true, :encoding => site.config["encoding"], }).map(&:to_hash) + when ".tsv" + CSV.read(path, { + :col_sep => "\t", + :headers => true, + :encoding => site.config["encoding"], + }).map(&:to_hash) else SafeYAML.load_file(path) end