Skip to content

Instantly share code, notes, and snippets.

@capjamesg
Created September 11, 2022 17:11
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 capjamesg/394221dd551d25d44a5b821c4bd2f2cf to your computer and use it in GitHub Desktop.
Save capjamesg/394221dd551d25d44a5b821c4bd2f2cf to your computer and use it in GitHub Desktop.
Script for generating checkins from a CSV on my website
require "csv"
for c in CSV.foreach("cafes.csv", :quote_char => '"', :col_sep =>', ', :headers => true)
slug = c['place_name'].downcase.gsub(/[^a-z0-9]+/i, '-')
front_matter = "
---
layout: checkin
latitude: #{c["lat"]}
longitude: #{c["long"]}
title: #{c['place_name']}
city: #{c['city']}
country: #{c['country']}
permalink: /checkins/#{c['city'].downcase + "/" + slug}
map: true
"
if c['rating']
front_matter += "rating: #{c['rating']}\n"
end
if c['description']
front_matter += "notes: #{c['description']}"
else
front_matter += "zoom: 10"
end
front_matter += "\n---\n\n"
city_folder = "_checkins/#{c["city"].downcase}"
if !File.directory?(city_folder)
Dir.mkdir(city_folder)
end
File.open("_checkins/#{slug}.md", "w+") do |f|
f.write(front_matter)
end
puts front_matter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment