Created
September 5, 2017 21:39
-
-
Save guayom/8baf2c1fb6f828157eb23c0ac1ced5ed to your computer and use it in GitHub Desktop.
Hugo import from yml database with ruby
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 '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