Last active
January 14, 2018 19:22
-
-
Save Convincible/32deb5b4ed66df2e2e4948d6818daaf2 to your computer and use it in GitHub Desktop.
DatoCMS Tree Iteration
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
def tree_iterate(tree, path) | |
directory path do | |
tree.each { |branch| | |
create_post "#{branch.slug}.md" do | |
frontmatter :yaml, { | |
title: branch.title | |
} | |
content(branch.body) | |
end | |
if (branch.children.length > 0) | |
tree_iterate(branch.children, path + "/" + branch.slug) | |
end | |
} | |
end | |
end | |
roots = dato.subpages.select{|page| page.parent.nil? }.sort_by(&:position) | |
tree_iterate(roots, "source/_pages") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turn a Tree structure in DatoCMS into files and folders matching the same hierarchy.