Skip to content

Instantly share code, notes, and snippets.

@sskylar
Last active December 18, 2015 18:10
Show Gist options
  • Select an option

  • Save sskylar/5824224 to your computer and use it in GitHub Desktop.

Select an option

Save sskylar/5824224 to your computer and use it in GitHub Desktop.

Revisions

  1. sskylar revised this gist Jun 21, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion import-siteleaf.rb
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@
    # 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"))
    @@ -33,7 +34,7 @@
    post.published_at = content["published_at"]

    # save
    puts post.save.inspect
    puts test_mode ? post.inspect : post.save.inspect
    end

    # done!
  2. sskylar revised this gist Jun 21, 2013. 2 changed files with 2 additions and 1 deletion.
    File renamed without changes.
    3 changes: 2 additions & 1 deletion import.rb → import-siteleaf.rb
    Original file line number Diff line number Diff line change
    @@ -10,12 +10,13 @@
    page_id = '...' # blog page to import posts into

    # get entries from JSON dump
    contents = JSON.parse(File.read("import.json"))
    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
  3. sskylar renamed this gist Jun 21, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. sskylar revised this gist Jun 20, 2013. 2 changed files with 11 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions import.json
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    [{
    "title":"Post 1",
    "body":"Body goes here.",
    "slug":"post-1",
    "tags":["Tag 1", "Tag 2"],
    "slug":"post-1",
    "published_at":"2013-06-05T18:24:59-04:00"
    }, {
    "title":"Post 2",
    "body":"Body goes here.",
    "slug":"post-2",
    "tags":["Tag 1", "Tag 2"],
    "slug":"post-2",
    "published_at":"2013-06-05T18:24:59-04:00"
    }]
    11 changes: 9 additions & 2 deletions import.ru
    Original file line number Diff line number Diff line change
    @@ -15,16 +15,23 @@ contents = JSON.parse(File.read("import.json"))
    # loop through and add entries
    contents.each do |content|
    puts "Creating post..."

    post = Siteleaf::Post.new
    post.site_id = site_id
    post.parent_id = page_id

    # required
    post.title = content["title"]
    post.slug = content["slug"] # optional
    post.body = content["body"]

    # optional
    post.taxonomy = [
    {"key" => "Tags", "values" => content["tags"]} # optional
    {"key" => "Tags", "values" => content["tags"]}
    ]
    post.slug = content["slug"]
    post.published_at = content["published_at"]

    # save
    puts post.save.inspect
    end

  5. sskylar revised this gist Jun 20, 2013. 2 changed files with 1 addition and 1 deletion.
    File renamed without changes.
    2 changes: 1 addition & 1 deletion import.ru
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ site_id = '...'
    page_id = '...' # blog page to import posts into

    # get entries from JSON dump
    contents = JSON.parse(File.read("export.json"))
    contents = JSON.parse(File.read("import.json"))

    # loop through and add entries
    contents.each do |content|
  6. sskylar created this gist Jun 20, 2013.
    13 changes: 13 additions & 0 deletions export.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    [{
    "title":"Post 1",
    "body":"Body goes here.",
    "slug":"post-1",
    "tags":["Tag 1", "Tag 2"],
    "published_at":"2013-06-05T18:24:59-04:00"
    }, {
    "title":"Post 2",
    "body":"Body goes here.",
    "slug":"post-2",
    "tags":["Tag 1", "Tag 2"],
    "published_at":"2013-06-05T18:24:59-04:00"
    }]
    32 changes: 32 additions & 0 deletions import.ru
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    require "siteleaf"
    require "json"

    # API settings
    Siteleaf.api_key = '...'
    Siteleaf.api_secret = '...'

    # site settings
    site_id = '...'
    page_id = '...' # blog page to import posts into

    # get entries from JSON dump
    contents = JSON.parse(File.read("export.json"))

    # loop through and add entries
    contents.each do |content|
    puts "Creating post..."
    post = Siteleaf::Post.new
    post.site_id = site_id
    post.parent_id = page_id
    post.title = content["title"]
    post.slug = content["slug"] # optional
    post.body = content["body"]
    post.taxonomy = [
    {"key" => "Tags", "values" => content["tags"]} # optional
    ]
    post.published_at = content["published_at"]
    puts post.save.inspect
    end

    # done!
    puts "Success!"