Skip to content

Instantly share code, notes, and snippets.

@BPScott
Created February 7, 2012 23:27
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 BPScott/1762954 to your computer and use it in GitHub Desktop.
Save BPScott/1762954 to your computer and use it in GitHub Desktop.
Fuckingawesomesongs.com songs object => one file per song
#Place in the root of your fuckingawesomesongs.com folder
#I convert the current contents of songs.rb into a one file per song structure
require 'YAML'
require_relative 'lib/songs'
def slugify string
string.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
end
Songs.all.each do |song|
artist = song[:artist]
track = song[:track]
url = song[:url]
yaml_filename = "songs/#{slugify(artist)}-#{slugify(track)}.yml"
yaml_content = "artist: #{artist}\ntrack: #{track}\nurl: #{url}"
File.open yaml_filename, 'w' do |f|
f.write yaml_content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment