Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Proof of concept - Make the docs part of the Gatsby website #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 9 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ module.exports = {
"gatsby-plugin-image",
"gatsby-plugin-sharp",
"gatsby-transformer-remark",
{
resolve: "gatsby-source-filesystem",
options: {
name: "reference",
path: `${__dirname}/src/markdown/Reference/`,
},
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "markdown",
path: `${__dirname}/src/markdown/`,
},
},
}
],
}
}
53 changes: 53 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);
/*
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode, basePath: `reference` });
createNodeField({
node,
name: `slug`,
value: slug,
});
}
};
*/
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return new Promise((resolve, reject) => {
graphql(`
query ReferencePagesQuery {
allMarkdownRemark(
filter: {fileAbsolutePath: {glob: "**/Reference/**"}}
sort: {frontmatter: {title: ASC}}
) {
nodes {
id
frontmatter {
title
slug
}
url: gatsbyPath(filePath: "/reference/{markdownRemark.frontmatter__slug}")
}
}
}
`).then(result => {
console.log(result);
result.data.allMarkdownRemark.nodes.forEach((node) => {
console.log(node);
const slug = node.frontmatter.slug;
createPage({
path: node.url,
component: path.resolve(`./src/templates/reference-page.js`),
context: {
slug: slug,
title: node.frontmatter.title,
id: node.id
},
});
});
resolve();
});
});
};
4 changes: 2 additions & 2 deletions src/layout/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Header = () => {
/>
<Button
children="Reference"
url="https://ml5js.github.io/ml5-website-v02-docsify/#/reference/overview"
url="/reference"
txtColor="var(--color-text-dark)"
bgColor="var(--color-transparent)"
fontSize="0.9rem"
Expand Down Expand Up @@ -92,4 +92,4 @@ const Header = () => {
)
}

export default Header;
export default Header;
Loading