From 3688640d59a5b53a85cb6f31d336b474165ef4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20P=C3=A4per?= Date: Wed, 29 Mar 2017 00:36:29 +0200 Subject: [PATCH] add /_data/*.tsv support (#5985) * Update data.feature - add .tsv - add .csv with `\t` - add .csv with `;` * Fix Appveyor with dst-aware cucumber steps * Check for given content in posts * mention Ruby > 2.1.0 in docs * Update history to reflect merge of #5983 [ci skip] * Update history to reflect merge of #5961 [ci skip] * Update data_reader.rb - add .tsv support with tab separated columns - not adding support for auto-detecting `:col_sep` ftp://ftp.iana.org/assignments/media-types/text/tab-separated-values https://www.ietf.org/rfc/rfc4180.txt (CSV) https://ruby-doc.org/stdlib-2.4.1/libdoc/csv/rdoc/CSV.html * Update data.feature don't do semicolons and tabs in .csv within this patch * Update data.feature I don't know which component replaced my tab characters by space before. * Update data.feature t * Update data_reader.rb add a single space to satisfy format checker --- features/data.feature | 14 ++++++++++++++ lib/jekyll/readers/data_reader.rb | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) 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