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

@suin/gatsby-source-esa

v1.2.0

Published

Source plugin for pulling posts into Gatsby from esa.io spaces.

Downloads

6

Readme

@suin/gatsby-source-esa

Gatsby に esa.io のデータを提供するソースプラグイン。esa API v1 を使用してデータを取り込みます。

現在は、投稿の取得のみ対応しています。

特徴

  • esa のデータソースに対応
    • 記事
  • TypeScript サポート
  • 複数の esa チームをデータソースに指定できる
  • 下記の gatsby プラグインとの統合をサポート
    • gatsby-transformer-remark
    • gatsby-transformer-rehype

インストール

yarn add @suin/gatsby-source-esa
# or
npm install @suin/gatsby-source-esa

使い方

設定の仕方

gatsby-config.js のプラグイン設定に@suin/gatsby-source-esa を追加してください:

// gatsby-config.js
module.exports = {
  // ...
  plugins: [
    {
      resolve: `@suin/gatsby-source-esa`,
      options: {
        team: `foo`,
        token: process.env.ESA_TOKEN,
        posts: {
          q: `wip:false in:Public`,
          include: [`comments`, `stargazers`],
          sort: `number`,
          order: `asc`,
        },
      },
    },
    // ...
  ],
}

オプション

  • team: https://{チーム名}.esa.io の {チーム名} の部分を指定する。
  • token: ユーザの管理画面(https://[team].esa.io/user/tokens)で発行したアクセストークンを指定する。
  • posts: エンドポイント GET /v1/team/:team_name/posts の URI クエリ文字列 に指定できるパラメータが利用可能。
    • posts.q: 記事を絞り込むための条件。ここに検索オプション(wip:false や in:Public など)を駆使して、公開すべき記事をうまく絞り込むことをおすすめをします。help/記事の検索方法 - docs.esa.io参照。

クエリー

GraphQL でのクエリーは以下のように行なえます:

query MyQuery {
  allEsaPost {
    edges {
      node {
        number
        name
        body_md
        body_html
        category
        tags
        created_at
        updated_at
      }
    }
  }
}

提供される GraphQL インターフェイス

  • allEsaPost: すべての投稿
  • allEsaPostBodyHtml: すべての投稿の本文の HTML 部分
  • allEsaPostBodyMarkdown: すべての投稿の本文の Markdown 部分
  • esaPost
  • esaPostBodyHtml
  • esaPostBodyMarkdown

注意事項

  • esa API には「ユーザ毎に 15 分間に 75 リクエストまで」という利用制限があります。このプラグインはできるだけリクエスト数が少なくなるように設計してありますが、この利用制限に達した場合の挙動は未定義です。

Tips

gatsby-transformer-remark との統合

Markdown ファイルをパースする Gatsby プラグインの gatsby-transformer-remark とは自動的に統合されます。下記のように、当プラグインと gatsby-transformer-remark を併用するだけです:

// gatsby-config.js
module.exports = {
  // ...
  plugins: [
    {
      resolve: `@suin/gatsby-source-esa`,
      options: {
        team: `foo`,
        token: process.env.ESA_TOKEN,
        posts: {
          /*...*/
        },
      },
    },
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        /*...*/
      },
    },
    // ...
  ],
}

gatsby-transformer-rehype との統合

HTML ファイル(mediaType が text/html)のノードを変形する Gatsby プラグインの gatsby-transformer-rehype とは自動的に統合されます。下記のように、当プラグインと gatsby-transformer-rehype を併用するだけです。

gatsby-transformer-rehype には記事ノードのbody_htmlが渡ります。

// gatsby-config.js
module.exports = {
  // ...
  plugins: [
    {
      resolve: `@suin/gatsby-source-esa`,
      options: {
        team: `foo`,
        token: process.env.ESA_TOKEN,
        posts: {
          /*...*/
        },
      },
    },
    {
      resolve: `gatsby-transformer-rehype`,
      options: {
        /*...*/
      },
    },
    // ...
  ],
}

gatsby-transformer-rehype で処理された HTML を取り出すには、次のようなクエリーを発行します:

query MyQuery {
  allEsaPost {
    edges {
      node {
        number
        name
        childrenEsaPostBodyHtml {
          childHtmlRehype {
            html
          }
        }
      }
    }
  }
}

結果の例:

{
  "data": {
    "allEsaPost": {
      "edges": [
        {
          "node": {
            "number": 123,
            "name": "...",
            "childrenEsaPostBodyHtml": [
              {
                "childHtmlRehype": {
                  "html": "<p>..."
                }
              }
            ]
          }
        }
      ]
    }
  }
}

複数のチームをデータソースにする場合

このプラグインは複数の esa チームをデータソースにしても、それぞれのチームの投稿が Gatsby 上で衝突しないように設計されています。

複数のチームからデータを取り込む場合は、下記のように@suin/gatsby-source-esaを複数記述してください。

// gatsby-config.js
module.exports = {
  // ...
  plugins: [
    {
      resolve: `@suin/gatsby-source-esa`,
      options: {
        team: `foo`,
        token: process.env.ESA_FOO_TOKEN,
      },
    },
    {
      resolve: `@suin/gatsby-source-esa`,
      options: {
        team: `bar`,
        token: process.env.ESA_BAR_TOKEN,
      },
    },
    // ...
  ],
}

GraphQL でチーム名を参照するには、teamをクエリに含めてください:

query MyQuery {
  allEsaPost {
    edges {
      node {
        team # ここ
        name
        body_md
        # ....
      }
    }
  }
}