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-source-gh-readme

v1.0.10

Published

This GatsbyJS plugin queries GitHub's GraphQL API for a given user account. It fetches the README.md file contents on the master branch of each repository and creates nodes in GatsbyJS which can be queried using GraphQL. Because the mime type for the cont

Downloads

16

Readme

gatsby-source-gh-readme

A Gatsby source plugin for sourcing the README.md files at the root of the master branches of each of your Github repositories into your Gatsby application.

The plugin creates markdown File nodes from the readme file content. If gatsby-tranformer-remark is installed it will transform these markdown file nodes into MarkdownRemark nodes from which you can query an HTML representation of the markdown.

Nota Bene: Currently this plugin only fetches readme files named with all caps "README.md" not "readme.md". I am looking into how to fetch both upper and lower case named readme files.

Install

yarn add gatsby-source-gh-readme

or

npm install --save gatsby-source-gh-readme

Usage

Provide Github Credentials

@ github.com > account > developer settings > personal access token, create a token and give access to read data from your repositories. Choose to restrict access to only public repos if that's what you want.

Amend your .gitignore file to exclude .env files

# dotenv environment variables file
.env
.env.*
.env.development
.env.production

Create .env files to hold you secret token

touch .env.development

and for production...

touch .env.production

Edit these file to hold your github token

# Github GraphQL API (Public and Private)
GITHUB_API_TOKEN="YOUR-SECRET-TOKEN-GOES-HERE"

Make the environment variables listed in these files available to GatsbyJS

@ gatsby-config.js, at the top of the file

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`
});

Note: dotenv is part of GatsbyJS so you can require it without installing it.

Make GatsbyJS aware of the plugin

@ gatsby-config.js, add the plugin

  plugins: [
    {
      resolve: "gatsby-source-gh-readme",
      options: {
        gitHubToken: `${process.env.GITHUB_API_TOKEN}`
      }
    },...

Query for nodes

Once you have this plugin installed on your GatsbyJS site a GraphQL query to Github will pull in the readme file content and create nodes on your Gatsby data graph at GatsbyJS build time.

You will find a list of all the readme contents under allGithubReadme

So you can query for all readme nodes like this

query MyQuery {
  allGithubReadme(sort: {order: ASC, fields: title}) {
    totalCount
    nodes {
      id
      title
      description
    }
  }
}

If the totalCound doesn't match the number of repos on your account it may be for one of the following reasons:

  • some of your repos don't have a readme file on the master branch
  • the readme file may be named "readme" instead of "README"
  • you may have some private repos that will only be available if you have issued yourself a key with private permissions.

Individual nodes are found on githubReadme. To query for the readme of a particular repo you can try:

query githubProjectByTitle($name: String!) {
  githubReadme(title: {eq: $name}) {
    title
    description
    readme
  }
}

with these query variables

{
  "name":"REPO-NAME-GOES-HERE"
}

In these queries the readme content is a blob of markdown text in the field readme

Create pages on your site

Note that MarkdownRemark must be installed on the site for the readme nodes to be processed into usable html.

Because a MarkdownRemark node is created for each githubReadme node that is added to the GatsbyJS data graph, you can get access the content you want through childMarkdownRemark.

Contribute

Any ideas to make this more useful or stable are welome. See the github project page gatsby-source-gh-readme for more information.