A Gatsby source plugin for sourcing data into your Gatsby application from your local git repository.
This source plugin enables gatsby sites to include meta data about their own git repository at build time. Possible features are:
- Printing the hash of the latest git commit on an about page
- Including the name of the current git branch (might be useful for canary builds or split deployments)
- Creating a list of all git authors / contributors
Missing a feature? Please create an issue (or even a pull request).
npm install --save gatsby-source-local-git
// In your gatsby-config.js
module.exports = {
plugins: [`gatsby-source-local-git`],
}
You can find a running example here: https://using-gatsby-source-local-git.netlify.app/
Sources of the example are available examples/using-gatsby-source-local-git/
You can query commit nodes like the following:
{
allGitCommit(limit: 25, sort: { fields: date, order: DESC }) {
edges {
node {
hash
message
body
date(fromNow: true)
refs
author {
name
email
}
}
}
totalCount
}
}
Query hash of latest commit:
{
gitCommit(latest: { eq: true }) {
hash
}
}
You can query tags like this:
{
allGitTag {
edges {
node {
name
}
}
}
}
Query the latest tag:
{
gitTag(latest: { eq: true }) {
name
}
}
Tags will simply be sorted by semantic version number to find the latest tag (including every tag containing a dot like v1.2.3
or 1.2
but not newest-feature
).
You can query branches like this:
{
allGitBranch {
edges {
node {
commit
id
name
current
}
}
}
}
Query the current branch:
{
gitBranch(current: { eq: true }) {
name
}
}
You can query author nodes like the following:
{
allGitAuthor(sort: { fields: name }) {
nodes {
name
email
}
totalCount
}
}
git clone https://github.com/gatsbyjs/gatsby-starter-default.git && cd gatsby-starter-default
git submodule add https://github.com/PMudra/gatsby-source-local-git.git plugins/gatsby-source-local-git
See top of readme for an example.
Just be sure to switch to the right directory depending on the task. Working on plugin:
cd plugins/gatsby-source-local-git
npm install
npm start
See if the plugin is working as expected (in root directory i.e. gatsby-starter-default
):
npm install
npm start