Querying and formatting the data for 11ty
If you remember all the way back to Chapter 2, you’ll recall that we can add data to 11ty’s Data Cascade in many different ways. The two ways that work best for the application of a headless CMS are a global JavaScript data file and configuration-generated global data. We’ve covered JavaScript data files a couple of times already in the book, so for this project, let’s add this data via the configuration file.
Adding data via the addGlobalData
method on the eleventyConfig
option will add global data to our cascade that we can use with the added benefit of allowing this to be added to a plugin, as we’ll discover in the next chapter.
The addGlobalData
method accepts two arguments: a string to create the data key, and a function to return the data. In this case, we’ll call our data hygraph
and use an async function to fetch that data:
eleventyConfig.addGlobalData("hygraph", async function...