Deep Dive

“The fastest auto dealership site in the world” How relentless optimization 8xed conversions

ContactSign Up for Free
Official Plugin
View plugin on GitHub

gatsby-transformer-toml

Parses TOML files.

Install

npm install gatsby-transformer-toml

How to use

// In your gatsby-config.js
plugins: [`gatsby-transformer-toml`]

Parsing algorithm

This plugin is using NPM toml package to parse TOML documents. As long as your TOML is valid, you shouldn’t have any issues.

Live demo of TOML to JSON conversion using toml is here.

If you have user.toml in your project, with contents like this:

userName = "Random User"
userAvatar = "https://api.adorable.io/avatars/150/test.png"
userDescription = "Lorem..."
[userLink]
     label='Website'
     url='//mywebsite.example.local'
     icon='fa fa-link'

Then you’ll be able to query your data using:

query {
  userToml {
    userName
    userAvatar
    userDescription
    userLink {
      label
      url
      icon
    }
  }
}

And the result will be:

{
  "data": {
    "userToml": {
      "userName": "Random User",
      "userAvatar": "https://api.adorable.io/avatars/150/test.png",
      "userDescription": "Lorem...",
      "userLink": {
        "label": "Website",
        "url": "//mywebsite.example.local",
        "icon": "fa fa-link"
      }
    }
  }
}
© 2022 Gatsby, Inc.