From 533480005d44f2c5d20903cf93e6e80a562cd180 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Sun, 12 Dec 2021 22:54:25 -0800 Subject: [PATCH 1/3] Add gitRemote webLink to page as sourceLink. --- gatsby-node.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gatsby-node.js b/gatsby-node.js index 04c8089..6b0b945 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -80,6 +80,13 @@ exports.createPages = async ({ graphql, actions }) => { pathname sourceInstanceName } + parent { + ... on File { + gitRemote { + webLink + } + } + } } } } @@ -94,6 +101,7 @@ exports.createPages = async ({ graphql, actions }) => { // in page queries as GraphQL variables. pathname: node.fields.pathname, sourceInstanceName: node.fields.sourceInstanceName, + sourceLink: node?.parent?.gitRemote?.webLink }, }); }); From e5bf9a18006218d1d9090ef74496da05ea54484c Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Sun, 12 Dec 2021 22:54:48 -0800 Subject: [PATCH 2/3] Render a source link above the toc. --- src/components/table-of-contents.js | 7 ++++++- src/templates/docs-page.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/table-of-contents.js b/src/components/table-of-contents.js index 79364d5..3cd91b5 100644 --- a/src/components/table-of-contents.js +++ b/src/components/table-of-contents.js @@ -36,11 +36,16 @@ const useStyles = makeStyles(theme => ({ export default function TableOfContents(props) { const classes = useStyles(); - const { __html, headings, title = 'Table of contents' } = props; + const { __html, headings, source, title = 'Table of contents' } = props; const [tocRef, setActiveHeading] = useActiveHeading(headings, classes.active); return (<> +

+ + {source.sourceInstanceName} source + +

{title} depth === 1)?.value; const toc = { + source: { + sourceInstanceName, + sourceLink, + }, title, __html: tocHtml, headings: post.headings From 68425469e0f681cc6c0e194264d30714ee4667b3 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Sun, 12 Dec 2021 23:11:59 -0800 Subject: [PATCH 3/3] Remove optional chaining. --- gatsby-node.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gatsby-node.js b/gatsby-node.js index 6b0b945..5dfdbc9 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -93,6 +93,7 @@ exports.createPages = async ({ graphql, actions }) => { } `); result.data.allMarkdownRemark.edges.forEach(({ node }) => { + const sourceLink = node.parent.gitRemote ? node.parent.gitRemote.webLink : null; createPage({ path: node.fields.pathname, component: path.resolve(`./src/templates/docs-page.js`), @@ -101,7 +102,7 @@ exports.createPages = async ({ graphql, actions }) => { // in page queries as GraphQL variables. pathname: node.fields.pathname, sourceInstanceName: node.fields.sourceInstanceName, - sourceLink: node?.parent?.gitRemote?.webLink + sourceLink, }, }); });