Turn "authors" attached to blog posts into a _data file
#! /usr/bin/ruby | |
require 'jekyll' | |
config = Jekyll.configuration | |
source = config['source'] | |
data_source = File.join(source, config['data_source']) | |
posts = File.join(source, '_posts') | |
authors = [] | |
if ARGV[0].nil? | |
puts "No value passed for filename, assuming 'author.'" | |
file_name = 'author' | |
else | |
file_name = ARGV[0] | |
end | |
Dir.foreach(posts) { |p| | |
if File.extname(p) == ".html" or File.extname(p) == '.md' | |
yaml = YAML.load_file(File.join(posts, p)) | |
if yaml['author'] | |
yaml['author'].each { |a| authors.push(a) } | |
end | |
if yaml['authors'] | |
yaml['authors'].each { |a| authors.push(a) } | |
end | |
end | |
} | |
target = File.open(File.join(data_source, "#{file_name}.yml"), 'w') | |
target.write(YAML.dump(authors.uniq.to_yaml)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment