Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ exports.createPages = async ({ graphql, actions }) => {
pathname
sourceInstanceName
}
parent {
... on File {
gitRemote {
webLink
}
}
}
}
}
}
}
`);
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`),
Expand All @@ -94,6 +102,7 @@ exports.createPages = async ({ graphql, actions }) => {
// in page queries as GraphQL variables.
pathname: node.fields.pathname,
sourceInstanceName: node.fields.sourceInstanceName,
sourceLink,
},
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/components/table-of-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<>
<h3>
<a href={source.sourceLink} style={{ textDecoration: 'none' }}>
{source.sourceInstanceName} source
</a>
</h3>
<Typography component='label' className={classes.title}>{title}</Typography>
<Box
ref={tocRef}
Expand Down
7 changes: 6 additions & 1 deletion src/templates/docs-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ const useStyles = makeStyles({
},
});

export default function DocsPage({ data }) {
export default function DocsPage({ data, pageContext }) {
const classes = useStyles();

const { markdownRemark: post } = data;
const { sourceInstanceName, sourceLink } = pageContext;
const [tocHtml, setTocHtml] = useState(post.tableOfContents);
const title = post.headings.find(({ depth }) => depth === 1)?.value;
const toc = {
source: {
sourceInstanceName,
sourceLink,
},
title,
__html: tocHtml,
headings: post.headings
Expand Down