Skip to main content
Official Plugin
View plugin on GitHub
See starters using this

gatsby-transformer-toml

Parses TOML files.

Install

npm install --save 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"
      }
    }
  }
}

Edit this page on GitHubLast updated: