Gatsby Transformer JavaScript Frontmatter

5.16.0 · active · verified Sun Apr 19

This is a Gatsby transformer plugin designed to extract metadata, commonly known as "frontmatter," directly from JavaScript, TypeScript, JSX, or TSX files within a Gatsby project. It operates by statically analyzing `exports.frontmatter` or `export const frontmatter` declarations using `@babel/parser` and `@babel/traverse`. The current stable version, `5.16.0`, aligns with the Gatsby v5 ecosystem. Its release cadence is tied to the main Gatsby monorepo, receiving updates alongside Gatsby core to ensure compatibility with new Node.js versions (e.g., Node.js 24 support in `5.16.0`) and address security vulnerabilities. Its key differentiator is enabling developers to define content metadata directly within their component or data files using standard JavaScript exports, providing a unified location for code and content configuration, distinct from traditional Markdown-based frontmatter solutions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `gatsby-transformer-javascript-frontmatter` in `gatsby-config.js` alongside `gatsby-source-filesystem` and provides an example JavaScript file showing how to export frontmatter for the plugin to process.

module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `pages`,
        path: `${__dirname}/src/pages/`,
      },
    },
    "gatsby-transformer-javascript-frontmatter",
  ],
}

// Example content file: src/pages/my-post.js
import React from "react"

export const frontmatter = {
  title: "Choropleth on d3v4",
  written: "2017-05-04",
  layoutType: "post",
  path: "choropleth-on-d3v4",
  category: "data science",
  description: "Things about the choropleth.",
}

export default function MyComponent() {
  return <div>My Post Content</div>
}

view raw JSON →