Skip to content

Instantly share code, notes, and snippets.

@Convincible
Last active January 14, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Convincible/32deb5b4ed66df2e2e4948d6818daaf2 to your computer and use it in GitHub Desktop.
Save Convincible/32deb5b4ed66df2e2e4948d6818daaf2 to your computer and use it in GitHub Desktop.
DatoCMS Tree Iteration
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")
@Convincible
Copy link
Author

Turn a Tree structure in DatoCMS into files and folders matching the same hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment