Skip to content

Commit

Permalink
fix: use the right layout for rendering .mdx pages in www/src/pages/
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-smith-tcril authored and bradenmacdonald committed Dec 17, 2024
1 parent 1942f03 commit e0a3539
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion www/gatsby-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const plugins = [
},
},
'gatsby-plugin-react-helmet',
'gatsby-plugin-mdx-source-name',
{
resolve: 'gatsby-plugin-manifest',
options: {
Expand Down Expand Up @@ -108,7 +109,7 @@ const plugins = [
resolve: 'gatsby-plugin-page-creator',
options: {
path: `${__dirname}/src/pages`,
ignore: ['insights.tsx'],
ignore: ['insights.tsx', '**/*.(md|mdx)'],
},
},
];
Expand Down
1 change: 1 addition & 0 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"gatsby": "^5.14",
"gatsby-plugin-manifest": "^5.14",
"gatsby-plugin-mdx": "^5.14",
"gatsby-plugin-mdx-source-name": "^1.0.1",
"gatsby-plugin-react-axe": "^0.5.0",
"gatsby-plugin-react-helmet": "^6.14",
"gatsby-plugin-sass": "^6.14",
Expand Down
55 changes: 37 additions & 18 deletions www/utils/createPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { getThemesSCSSVariables, processComponentSCSSVariables } = require('../th
const componentsUsage = require('../src/utils/componentsUsage');

const componentPageTemplate = path.resolve(__dirname, '../src/templates/component-page-template.tsx');
const defaultMdxPageTemplate = path.resolve(__dirname, '../src/templates/default-mdx-page-template.tsx');

async function createPages(graphql, actions, reporter) {
// Destructure the createPage function from the actions object
Expand All @@ -26,6 +27,7 @@ async function createPages(graphql, actions, reporter) {
id
fields {
slug
source
}
frontmatter {
components
Expand All @@ -42,12 +44,12 @@ async function createPages(graphql, actions, reporter) {
reporter.panicOnBuild('🚨 ERROR: Loading createPages query');
}
// Create component detail pages.
const components = result.data.allMdx.edges;
const pages = result.data.allMdx.edges;

const themesSCSSVariables = await getThemesSCSSVariables();

// you'll call `createPage` for each result
for (const { node } of components) {
for (const { node } of pages) {
const componentDir = node.fields.slug.split('/')[0];
const variablesPath = path.resolve(__dirname, `../../src/${componentDir}/_variables.scss`);
const githubEditPath = `https://github.com/openedx/paragon/edit/master/src${node.internal.contentFilePath.split('src')[1]}`;
Expand All @@ -58,22 +60,39 @@ async function createPages(graphql, actions, reporter) {
scssVariablesData = await processComponentSCSSVariables(variablesPath, themesSCSSVariables);
}

createPage({
// This is the slug you created before
// (or `node.frontmatter.slug`)
path: node.fields.slug,
// This layout will wrap our MDX content
component: `${componentPageTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
// You can use the values in this context in
// our page layout component
context: {
id: node.id,
components: node.frontmatter.components || [],
scssVariablesData,
componentsUsageInsights: Object.keys(componentsUsage),
githubEditPath,
},
});
if (node.fields.source === 'components') {
createPage({
// This is the slug you created before
// (or `node.frontmatter.slug`)
path: node.fields.slug,
// This layout will wrap our MDX content
component: `${componentPageTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
// You can use the values in this context in
// our page layout component
context: {
id: node.id,
components: node.frontmatter.components || [],
scssVariablesData,
componentsUsageInsights: Object.keys(componentsUsage),
githubEditPath,
},
});
}

if (node.fields.source === 'pages') {
createPage({
path: node.fields.slug,
component: `${defaultMdxPageTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
id: node.id,
githubEditPath,
scssVariablesData,
frontmatter: {
title: node.frontmatter.title,
},
},
});
}
}

INSIGHTS_PAGES.forEach(({ path: pagePath, tab }) => {
Expand Down

0 comments on commit e0a3539

Please sign in to comment.