Skip to content

Commit

Permalink
Expose more configuration for CSV parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCordingley committed Nov 15, 2021
1 parent b091606 commit ce0f298
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/jekyll/readers/data_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ def sanitize_filename(name)
private

def convert_csv(path)
config = (site.config["csv_reader"] || {}).transform_keys(&:to_sym)

CSV.read(path,
:converters => site.config["csv_converters"]&.map(&:to_sym),
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
:converters => config.fetch(:converters, []).map(&:to_sym),
:headers => config.fetch(:headers, true),
:encoding => config.fetch(:encoding, site.config["encoding"])).map(&:to_hash)
end

def convert_tsv(path)
config = (site.config["tsv_reader"] || {}).transform_keys(&:to_sym)

CSV.read(path,
:col_sep => "\t",
:converters => site.config["tsv_converters"]&.map(&:to_sym),
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
:converters => config.fetch(:converters, []).map(&:to_sym),
:headers => config.fetch(:headers, true),
:encoding => config.fetch(:encoding, site.config["encoding"])).map(&:to_hash)
end
end
end

0 comments on commit ce0f298

Please sign in to comment.