gatsby-theme-wordpress-mdx
Version:
<p align="center"> <img width='200px' alt="Gatsby Theme" src="https://raw.githubusercontent.com/artezan/gatsby-theme-wordpress-mdx/master/%40artezan/gatsby-theme-wordpress-mdx/dn.png" />
76 lines (73 loc) • 1.66 kB
JavaScript
const path = require('path')
module.exports = async function CreatePagesMdx(
actions,
graphql,
reporter,
sourceMdxPosts
) {
const { createPage } = actions
const result = await graphql(`
query {
allMdx {
edges {
node {
id
fields {
slug
sourceName
}
frontmatter {
section
layout
}
}
}
}
allMdxWpPosts(filter: { type: { eq: "MDX" } }) {
edges {
node {
id
mdxData {
fields {
slug
}
}
}
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query')
}
result.data.allMdx.edges.forEach(({ node }) => {
const {
frontmatter: { section, layout },
id
} = node
if (layout) {
let layoutPath
if (layout === 'landing') {
layoutPath = `../src/templates/Landing.js`
} else if (layout === 'page') {
layoutPath = `../src/templates/page.js`
}
createPage({
path: node.fields.slug,
component: path.join(__dirname, layoutPath),
context: { id: node.id }
})
}
})
const { edges: mdxPosts } = result.data.allMdxWpPosts
if (sourceMdxPosts && mdxPosts.length) {
const postTemplate = path.join(__dirname, `../src/templates/mdxPost.js`)
mdxPosts.forEach(({ node }) => {
createPage({
path: node.mdxData.fields.slug,
component: postTemplate,
context: { id: node.id }
})
})
}
}