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

@mkitio/gatsby-theme-blog

v1.0.1

Published

A Gatsby blog theme with rich MDX support by MK IT https://mkit.io

Downloads

7

Readme

@mkit/gatsby-theme-blog

A Gatsby blog theme with rich MDX support by MK IT https://mkit.io

Feel free to submit improvements, bug reports and PRs.

Any planned changes or improvements will be listed in the theme's ROADMAP.md.

Description

A Gatsby blog theme supporting local filesystem content, MDX, image processing, and content mapping.

The theme provides several built-in features to set the bare-minimum for building a blog including:

What you'll get:

  • Content sourced from the local filesystem, e.g. content/ folder within your repository
  • Blog post pages created automatically given your content/posts/ contents
  • Auto blog post slug field generation based on folder naming, e.g. content/posts/mypost results in /mypost slug
  • Reading time field based on the content length of the MDX file, e.g. { text: '1 min read', minutes: 1, time: 60000, words: 200 }
  • MDX support out of the box
  • Optimized images out of the box
  • Ability to define relations between frontmatter fields and your own mappings, e.g. multiple authors, tags, etc.
  • Blank canvas for you to built on top of, i.e. pages and components are for you to implement.

Heavily inspired by gatsby-theme-blog and gatsby-theme-blog-core.

Install

Manually add to your site

# with npm
npm install --save mkit@gatsby-theme-blog

# or with yarn (recommended)
yarn add mkit@gatsby-theme-blog

Usage

Theme options

| Key | Default value | Description | | ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | contentPath | content/ | The location where your content and mappings live. Should be on the root level of your project. | | mapping | { 'Mdx.frontmatter.author': 'AuthorsYaml' } | Optional mapping between node types, i.e. frontmatter to YAML relations. Read more. |

Example usage

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: '@mkit/gatsby-theme-blog',
      options: {
        // defaults to `/content`
        contentPath: '/my-content'
        // defaults to author mapping only
        mapping: {
          'Mdx.frontmatter.author': 'AuthorsYaml',
          'Mdx.frontmatter.tags': 'TagsYaml'
        }
      }
    }
  ]
}

How to Content

Content lives under the contentPath/posts location on the root level of your project. Typically that's content/posts/ by default.

The plugin will automatically detect any .mdx files and create pages on the root URL of your site, e.g. localhost:8000/__EXAMPLE__. See content/posts/__EXAMPLE__ for more details.

If you don't have such folder structure already, this theme will automatically create it for you and include useful examples.

# content/
.
├── mappings
└── posts                       # blog posts
    └── __EXAMPLE__               # example post folder used for auto slug generation
        ├── images                # blog post images or assets
        │   ├── 150.png
        │   ├── 1500x500.png
        │   ├── 3000x1000.png
        │   ├── 300x600.png
        │   └── 500.png
        └── index.mdx             # blog post .mdx

How to Mapping

You may want to reuse or define multiple complex objects in your blog post's frontmatter. For instance you may want to add an author to your post's frontmatter but the author itself should have its own properties such as name, bio, avatar, etc. That's where mapping kicks in.

It is possible to define whatever relations you need between your .mdx's frontmatter and YAML definitions. See content/mappings/authors for more details.

Mapping between node types is possible thanks to Mapping node types in Gatsby.

# content/
.
├── mappings                    # [optional, enabled by default] all available mappings
│   └── authors
│       ├── authors.yaml          # authors definition
│       └── images                # [optional] author avatar images
│           └── john-doe.png
└── posts

How to GraphQL

Nodes of Interest

The theme and its configuration adds several node types available to query via GraphQL. You can see the details at localhost:8000/__graphql's Explorer.

  • allFile and file
  • allMdx and mdx
  • allAuthorsYaml and authorsYaml

All blog posts

Typically you'd want to get get all blog posts so you can build your "posts" page. The page where all posts are displayed in some way.

# GraphQL query to get all blog posts
query allPosts {
  allMdx {
    edges {
      node {
        frontmatter {
          title
        }
      }
    }
  }
}

Results in:

// Data returned by the query
{
  "data": {
    "allMdx": {
      "edges": [
        {
          "node": {
            "frontmatter": {
              "title": "Welcome To Your Blog"
            }
          }
        }
      ]
    }
  }
}

Frontmatter

Frontmatter fields defined in your .mdx files can act as meta data for your posts. By default the blog post has title and author.

# GraphQL query to get all blog posts with frontmatter and author mapping
query allPosts {
  allMdx {
    edges {
      node {
        frontmatter {
          title
          author {
            id
            slug
            image {
              relativePath
            }
          }
        }
      }
    }
  }
}

Results in:

// Data returned by the query
{
  "data": {
    "allMdx": {
      "edges": [
        {
          "node": {
            "frontmatter": {
              "title": "Welcome To Your Blog",
              "author": {
                "id": "John Doe",
                "slug": "john-doe",
                "description": "Consectetur aliqua mollit commodo cillum eiusmod ullamco nisi in.",
                "image": {
                  "relativePath": "mappings/authors/images/john-doe.png"
                }
              }
            }
          }
        }
      ]
    }
  }
}

Fields

# GraphQL query to get all blog posts with auto-generated fields by the theme
query allPosts {
  allMdx {
    edges {
      node {
        fields {
          slug
          readingTime {
            minutes
            text
            time
            words
          }
        }
      }
    }
  }
}

Results in:

// Data returned by the query
{
  "data": {
    "allMdx": {
      "edges": [
        {
          "node": {
            "fields": {
              "slug": "/__EXAMPLE__",
              "readingTime": {
                "minutes": 3.315,
                "text": "4 min read",
                "time": 198900,
                "words": 663
              }
            }
          }
        }
      ]
    }
  }
}