npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-plugin-json-remark

v1.1.5

Published

A GatsbyJs plugin that transforms markdown content from JSON files. The new MarkdownRemark nodes are placed inside the original `gatsby-transformer-json` node tree. Transformed HTML is also populated in new fields with "Html" appended to field names.

Downloads

269

Readme

Commitizen friendly semantic-release codecov

gatsby-plugin-json-remark is a GatsbyJs plugin that transforms markdown content from JSON files. The new MarkdownRemark nodes are placed inside the original gatsby-transformer-json node tree. Transformed HTML is also populated in new node properties as the original JSON key names appended with "Html".

This plugin piggybacks off of the existing gatsby-transformer-remark plugin configuration in gatsby-config.json and honors all additional parsing provided by its sub-plugins (e.g. gatsby-remark-prismjs). This is accomplished on the *Html fields by retrieving the HTML from the MarkdownRemark nodes' own html resolvers.

The ability to place markdown in structured JSON files comes in handy for CMS software that stores its content inside JSON files. In TinaCMS for example, gatsby-plugin-json-remark can be used to embed markdown in the structured page content using TinaCMS' markdown blocks feature.

Please create an issue for question, bug, idea, etc. If this plugin doesn't fit your particular use case but you feel that it should, please open an issue to request the new feature. PRs welcome 👍.

Note: It is recommended to use gatsby-remark-remove-root-p-tag in tandem with this plugin. gatsby-transformer-remark will often automatically wrap a paragraph node around markdown snippets, resulting in an unintended <p> tag wrapping the transformed HTML. gatsby-remark-remove-root-p-tag will remove the paragraph parent from the markdown AST.

Install

Add gatsby-plugin-json-remark package to your gatsby project:

npm

npm i gatsby-plugin-json-remark

yarn

yarn add gatsby-plugin-json-remark

Configure

Add plugin to the gatsby-plugin-json-remark plugins array in your gatsby-config.js:

module.exports = {
  plugins: [
    // ...
    {
      resolve: `gatsby-plugin-json-remark`,
      options: {
        paths: [
          `${__dirname}/content/pages`,
          `${__dirname}/content/json-markdown`,
        ], // Process all JSON files in these directories.
        pathsExclude: [`${__dirname}/content/pages/contact.json`], // Process all files in the directories above, except `pages/contact.json`.
        fieldNameBlacklist: [
          "id",
          "children",
          "parent",
          "fields",
          "internal",
          "path",
          "template",
        ],
      },
    },
    // ...
  ],
};

Optional: add gatsby-remark-remove-root-p-tag as a sub-plugin to `gatsby-transformer-remark' to remove unwanted HTML paragraph tags from the generaged HTML.

module.exports = {
  plugins: [
    // ...
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-remove-root-p-tag`,
            options: {
              parents: ["gatsby-plugin-json-remark", "default-site-plugin"], // Required: will process only the MarkdownRemark nodes created by these plugins
            },
          },
        ],
      },
    },
    // ...
  ],
};

Options

paths (required)

Values can be JSON file paths or directory paths. The plugin will only process these files and directories. Note: see requirements below.

pathsExclude (optional)

Values can be JSON file paths or directory paths which serve as exceptions to the paths option. The plugin will ignore the files and directories provided here, even if they are configured with the paths option. This option is handy when a directory is configured with the paths option but certain files in that directory should be ignored.

fieldNameBlacklist (optional / recommended)

A list of JSON keys that will be ignored in the source JSON files. This is useful for preventing conflicts with the reserved property names of the Gatsby node data structure.

Requirements

gatsby-config.js Dependencies

  • gatsby-transformer-remark
  • gatsby-source-filesystem Configured with at least one directory containing JSON files. The paths option of gatsby-plugin-json-remark must contain at least a directory or a file that is also configured with gatsby-source-filesystem. Otherwise, there will be no JSON nodes to process.

Environment

  • Node >=12.16.1
  • Gatsby v2