hn-classics/add-metadata.rb

18 lines
404 B
Ruby
Raw Normal View History

require 'json'
require 'yaml'
stories = JSON.parse File.read 'stories.json'
stories.each do |year, storiesByYear|
storiesByYear.each do |story|
story.delete '_highlightResult'
id = story['objectID']
fn = "_stories/#{year}/#{id}.md"
if File.exists? fn
content = File.read fn
content = "#{story.to_yaml}\n---\n#{content}"
File.open(fn, "w") { |file| file.write content }
end
end
end