Skip to content

Instantly share code, notes, and snippets.

@guayom
Created September 5, 2017 21:39
Show Gist options
  • Save guayom/8baf2c1fb6f828157eb23c0ac1ced5ed to your computer and use it in GitHub Desktop.
Save guayom/8baf2c1fb6f828157eb23c0ac1ced5ed to your computer and use it in GitHub Desktop.
Hugo import from yml database with ruby
require 'yaml'
require 'parameterize'
require 'open-uri'
require 'fileutils'
idustries = YAML.load_file('import/v5n_novatec_idustries.yml')
idustries.each_with_index do |idustry, index|
unless idustry['state'] == -2
FileUtils::mkdir_p "content/idustries/#{idustry['titulo'].parameterize}"
draft = if idustry['state'] == 1 then "false" else "true" end
File.open("content/idustries/#{idustry['title'].parameterize}/_index.md", "w+") do |file|
file.write("---\n")
file.write("title: \"#{idustry['title']}\"\n")
file.write("id: #{idustry['id']}\n")
file.write("image: \"#{idustry['image']}\"\n")
file.write("meta_keywords: \"#{idustry['meta_keywords']}\"\n")
file.write("meta_description: \"#{idustry['meta_description']}\"\n")
file.write("menu:\n")
file.write(" principal:\n")
file.write(" parent: 'idustries'\n")
file.write(" weight: #{index}\n")
file.write("weight: #{idustry['ordering']}\n")
file.write("draft: #{draft}\n")
file.write("---\n")
file.write(idustry['description'])
end
puts "idustry - #{idustry['title']}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment