Skip to content

Instantly share code, notes, and snippets.

@gboone
Created June 8, 2015 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboone/4f4dee1290278b483e24 to your computer and use it in GitHub Desktop.
Save gboone/4f4dee1290278b483e24 to your computer and use it in GitHub Desktop.
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