Instead of specifying the API token as a parameter, you can pass it as an environment variable:
$ export DATO_API_TOKEN=abc123$ bundle exec dato dump
The CLI tool also loads environment variables from a .env
file, so you can place the token there and forget about it (just make sure not to publish your .env
file on Github):
$ echo '.env' >> .gitignore$ echo 'DATO_API_TOKEN=abc123' >> .env$ bundle exec dato dump
To explicitely read data from a specific environment and not from the primary one you can use the --environment
flag:
$ bundle exec dato dump --environment=my-sandbox-environment
If you are working on development/staging environment, you might want to preview the latest version of records instead of the published one. In this case, you can add a --preview
flag:
$ bundle exec dato dump --preview
The dump
command will read a file dato.config.rb
(or the file passed by the --config
option). This file should contain instructions to transform the content stored remotely in DatoCMS into local files.
Let's watch a simple example to get started:
# dato.config.rbcontent = { hello: "world" }create_data_file("_data/foobar.yml", :yaml, content)
Here, create_data_file
is a method made available to you that can generate YAML/TOML/JSON files. It's perfect to generate Jekyll data files.
You can also generate Jekyll posts and collections with the create_post
method:
create_post "_posts/article.md" docontent("Lorem **ipsum dolor sit amet**, consectetur adipiscing elit.")end
If you need to place a collection of posts within a folder, you can use the directory
method, so that every time the dump
command is executed, previous content of the directory will be erased:
directory "_posts" do10.times do |i|create_post "article-#{i}.md" docontent("Lorem **ipsum dolor sit amet**, consectetur adipiscing elit.")endendend
Now that you know how you can create local files, the final step is to start generating them with data coming from DatoCMS. An object called dato
is available exactly for this purpose:
# inside a "_posts" directory...directory "_posts" do# ...iterate over the "Blog post" records...dato.blog_posts.each do |article|# ...and create a markdown file for each article!create_post "#{article.slug}.md" dofrontmatter(:yaml,title: article.title,)content(article.content)endendend
Once your dato.config.rb
is ready, just run the dato dump
command: you should see your Jekyll project populated with content. Run jekyll serve
and enjoy!
Obviously, that's just a quick tour: you can learn all the details about how to access your records inside your config file in the following sections.