Skip to content

Commit

Permalink
DEVEP-2099 - Implement Contributor API (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron authored Aug 10, 2020
1 parent 5a4a8b8 commit 06f52fa
Show file tree
Hide file tree
Showing 6 changed files with 2,167 additions and 2,152 deletions.
15 changes: 15 additions & 0 deletions packages/gatsby-theme-parliament/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ module.exports = {
rehypePlugins: [require(`rehype-slug`)],
remarkPlugins: [require(`remark-external-links`), require(`remark-docz`)]
}
},
{
resolve: `@adobe/gatsby-source-github-file-contributors`,
options: {
pages: {
paths: ['src/pages'],
extensions: ['md']
},
repo: {
token: process.env.GITHUB_TOKEN,
owner: process.env.GITHUB_REPO_OWNER,
name: process.env.GITHUB_REPO_NAME,
branch: process.env.GITHUB_REPO_BRANCH
}
}
}
]
};
1 change: 1 addition & 0 deletions packages/gatsby-theme-parliament/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"gatsby-plugin-mdx": "^1.2.19",
"gatsby-plugin-react-helmet-async": "^1.0.17-0",
"gatsby-source-filesystem": "^2.3.14",
"@adobe/gatsby-source-github-file-contributors": "*",
"prop-types": "^15.7.2",
"react-helmet-async": "^1.0.6",
"rehype-slug": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const Contributors = ({ href = '#', contributors = [], date }) => (
background: var(--spectrum-global-color-gray-50);
`}>
<img
alt={contributor}
src={contributor.startsWith('https://github.com/') ? `${contributor}.png` : contributor}
alt={contributor.name}
src={`https://github.com/${contributor.login}.png`}
css={css`
width: var(--spectrum-global-dimension-static-size-400);
height: var(--spectrum-global-dimension-static-size-400);
Expand Down
14 changes: 13 additions & 1 deletion packages/gatsby-theme-parliament/src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export default ({ children, pageContext, location }) => {
const data = useStaticQuery(
graphql`
query {
allGithubContributors {
nodes {
contributors {
date
login
name
}
path,
href
}
}
allMdx {
nodes {
tableOfContents
Expand Down Expand Up @@ -91,6 +102,7 @@ export default ({ children, pageContext, location }) => {
const allMdx = data.allMdx;
const allSitePage = data.allSitePage;
const siteMetadata = data.site.siteMetadata;
const allGithubContributors = data.allGithubContributors;

const globalNav = siteMetadata.globalNav;
const pages = siteMetadata.pages;
Expand All @@ -101,7 +113,7 @@ export default ({ children, pageContext, location }) => {
const hasSideNav = selectedSubPages.length > 0;

return (
<Provider value={{ location, pageContext, hasSideNav, siteMetadata, allSitePage, allMdx }}>
<Provider value={{ location, pageContext, hasSideNav, siteMetadata, allSitePage, allMdx, allGithubContributors }}>
<SEO title={pageContext?.frontmatter?.title} description={pageContext?.frontmatter?.description} />
<div className="spectrum spectrum--medium spectrum--large spectrum--light" lang="en" dir="ltr">
<Grid
Expand Down
11 changes: 7 additions & 4 deletions packages/gatsby-theme-parliament/src/components/MDXFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const filterChildren = (children, tableOfContents) => {
};

export default ({ children, pageContext }) => {
const { hasSideNav, siteMetadata, location, allSitePage, allMdx } = useContext(Context);
const { hasSideNav, siteMetadata, location, allSitePage, allMdx, allGithubContributors } = useContext(Context);

// PrevNext
const selectedPage = findSelectedPage(location.pathname, siteMetadata.subPages);
Expand All @@ -147,6 +147,9 @@ export default ({ children, pageContext }) => {
// OnThisPage
const { componentPath } = allSitePage.nodes.find(({ path }) => withPrefix(path) === location.pathname);
const { tableOfContents } = allMdx.nodes.find(({ fileAbsolutePath }) => fileAbsolutePath === componentPath);
const { contributors, href: pageHref } = allGithubContributors.nodes.find(({ path }) => {
return withPrefix(path) === componentPath
})

// Breadcrumbs
const selectedTopPage = findSelectedTopPage(location.pathname, siteMetadata.pages);
Expand Down Expand Up @@ -203,9 +206,9 @@ export default ({ children, pageContext }) => {
<View>
{pageContext.frontmatter.contributors && (
<Contributors
href="#"
contributors={pageContext.frontmatter.contributors}
date={new Date().toLocaleDateString()}
href={pageHref}
contributors={contributors}
date={new Date(contributors[0].date).toLocaleDateString()}
/>
)}
</View>
Expand Down
Loading

0 comments on commit 06f52fa

Please sign in to comment.