Skip to content

Commit

Permalink
fix: fixes rendering of development site without GITHUB_TOKEN env var…
Browse files Browse the repository at this point in the history
…iable
  • Loading branch information
claymcleod committed Feb 11, 2021
1 parent e7966ae commit d8f6535
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
49 changes: 44 additions & 5 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ exports.onCreateNode = async ({ node, getNode, actions }) => {
if (process.env.GITHUB_TOKEN) {
await registerGithubFields(relativeFilepath, node, createNodeField)
} else {
console.log(
"No GITHUB_TOKEN was passed in, so any information pulled from \n" +
"a GitHub API request (e.g. contributors and commits) will not \n" +
"be included in this build!"
)
createNodeField({
node,
name: `commits`,
Expand Down Expand Up @@ -133,3 +128,47 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
})
})
}

exports.createSchemaCustomization = ({ actions, reporter }) => {
const { createTypes } = actions

if (!process.env?.GITHUB_TOKEN) {
reporter.warn(
"No GITHUB_TOKEN was passed in, so any information pulled from \n" +
"a GitHub API request (e.g. contributors and commits) will not \n" +
"be included in this build! If you're developing locally, you can ignore \n" +
"this. If you see this in a production build, however, the lack \n" +
"of the GITHUB_TOKEN env variable means contributors and commit history \n" +
"embedded within each doc page will be missing."
)
}

const typeDefs = `
type MarkdownRemark implements Node {
fields: Fields
}
type Fields {
relativeFilepath: String!
slug: String!
commits: [Commit!]
contributors: [Contributor!]
}
type Contributor {
login: String!
avatar_url: String!
url: String!
commits: Int
}
type Commit {
url: String!
message: String!
date: String!
author: Contributor!
committer: Contributor!
}
`
createTypes(typeDefs)
}
1 change: 0 additions & 1 deletion src/components/docs/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class BaseLayout extends Component {
fileAbsolutePath,
timeToRead,
} = markdownRemark
contributors.forEach(e => console.log(e.login))
let currentModule = null

let longestMatchingPathPrefix = -1
Expand Down
17 changes: 10 additions & 7 deletions src/components/docs/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import PropTypes from "prop-types"
const DocsHeader = ({ title, timeToRead, contributors, commits }) => {
let latestCommit = null
let latestCommitDate = null
for (let i = 0; i < commits.length; i++) {
const commit = commits[i]
if (!commit.date) continue
const currentCommitDate = moment(commit.date)
if (!latestCommit || latestCommitDate < currentCommitDate) {
latestCommit = commit
latestCommitDate = currentCommitDate

if (commits) {
for (let i = 0; i < commits.length; i++) {
const commit = commits[i]
if (!commit.date) continue
const currentCommitDate = moment(commit.date)
if (!latestCommit || latestCommitDate < currentCommitDate) {
latestCommit = commit
latestCommitDate = currentCommitDate
}
}
}

Expand Down

0 comments on commit d8f6535

Please sign in to comment.