Last active
December 18, 2015 18:10
-
-
Save sskylar/5824224 to your computer and use it in GitHub Desktop.
Siteleaf import script. Imports a JSON dump of blog posts into a Siteleaf page. Requires the Siteleaf Gem (https://github.com/siteleaf/siteleaf-gem). Run in the command line using "ruby import-siteleaf.rb".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"title":"Post 1", | |
"body":"Body goes here.", | |
"tags":["Tag 1", "Tag 2"], | |
"slug":"post-1", | |
"published_at":"2013-06-05T18:24:59-04:00" | |
}, { | |
"title":"Post 2", | |
"body":"Body goes here.", | |
"tags":["Tag 1", "Tag 2"], | |
"slug":"post-2", | |
"published_at":"2013-06-05T18:24:59-04:00" | |
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "siteleaf" | |
require "json" | |
# API settings | |
Siteleaf.api_key = '...' | |
Siteleaf.api_secret = '...' | |
# site settings | |
site_id = '...' | |
page_id = '...' # blog page to import posts into | |
test_mode = false # change to true to test your import | |
# get entries from JSON dump | |
contents = JSON.parse(File.read("import-siteleaf.json")) | |
# loop through and add entries | |
contents.each do |content| | |
puts "Creating post..." | |
# set up post | |
post = Siteleaf::Post.new | |
post.site_id = site_id | |
post.parent_id = page_id | |
# required | |
post.title = content["title"] | |
post.body = content["body"] | |
# optional | |
post.taxonomy = [ | |
{"key" => "Tags", "values" => content["tags"]} | |
] | |
post.slug = content["slug"] | |
post.published_at = content["published_at"] | |
# save | |
puts test_mode ? post.inspect : post.save.inspect | |
end | |
# done! | |
puts "Success!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment