Skip to content

Commit

Permalink
Add farmOS/farmOS as a source.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Mar 16, 2021
1 parent 0d1e2ca commit da73a64
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 1 deletion.
24 changes: 23 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ module.exports = {
icon: "src/images/icon.png",
},
},
"gatsby-transformer-remark",
{
resolve: "gatsby-transformer-remark",
options: {
plugins: [
{
resolve: "gatsby-remark-prefix-relative-links",
options: {
sourceName: "farmOS",
prefix: "/farmos/docs",
},
},
],
},
},
"gatsby-plugin-sharp",
"gatsby-transformer-sharp",
{
Expand All @@ -36,5 +49,14 @@ module.exports = {
},
__key: "pages",
},
{
resolve: "gatsby-source-git",
options: {
name: "farmOS",
remote: "https://github.com/farmOS/farmOS.git",
branch: "2.x",
patterns: "docs/**",
},
},
],
};
52 changes: 52 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const path = require('path');
const { createFilePath } = require('gatsby-source-filesystem');

exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
// Ensures we are processing only markdown files
if (node.internal.type === "MarkdownRemark") {
// Use `createFilePath` to turn markdown files in our `data/faqs` directory into `/faqs/slug`
const relativeFilePath = createFilePath({
node,
getNode,
basePath: ".cache/gatsby-source-git",
});
const { sourceInstanceName } = getNode(node.parent);

// Creates new query'able field with name of 'slug'
createNodeField({
node,
name: "slug",
value: `/${sourceInstanceName.toLowerCase()}${relativeFilePath}`,
});
}
};

exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allMarkdownRemark {
edges {
node {
fields {
slug
sourceName
}
}
}
}
}
`);
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/docs-page.js`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.fields.slug,
},
});
});
};
Loading

0 comments on commit da73a64

Please sign in to comment.