diff --git a/gatsby-node.js b/gatsby-node.js index ab57ad317fe6c..dc7124a7a1ac2 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -15,6 +15,9 @@ const { getExcludedCollections, isFullSiteBuild, } = require("./src/utils/build-collections"); +const createBlogPages = require("./src/node-api/createBlogPages"); +const createKanvasLabPages = require("./src/node-api/createKanvasLabPages"); +const createSistentComponentPages = require("./src/node-api/createSistentComponentPages"); const shouldBuildFullSite = isFullSiteBuild(); const excludedCollections = new Set( @@ -107,23 +110,31 @@ exports.createPages = async ({ actions, graphql, reporter }) => { const HandbookTemplate = path.resolve("src/templates/handbook-template.js"); + await createBlogPages({ + graphql, + createPage: envCreatePage, + reporter, + isCollectionEnabled, + blogPostTemplate, + blogCategoryListTemplate, + blogTagListTemplate, + }); + + await createKanvasLabPages({ + graphql, + createPage: envCreatePage, + reporter, + labTemplate: LabTemplate, + }); + + await createSistentComponentPages({ + graphql, + createPage, + reporter, + }); + const res = await graphql(` { - blogPosts: allMdx( - filter: { - fields: { collection: { eq: "blog" } } - frontmatter: { published: { eq: true } } - } - ) { - nodes { - fields { - slug - } - internal { - contentFilePath - } - } - } resourcePosts: allMdx( filter: { fields: { collection: { eq: "resources" } } @@ -234,32 +245,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { } } } - blogTags: allMdx( - filter: { - fields: { collection: { eq: "blog" } } - frontmatter: { published: { eq: true } } - } - ) { - group(field: { frontmatter: { tags: SELECT } }) { - nodes { - id - } - fieldValue - } - } - blogCategory: allMdx( - filter: { - fields: { collection: { eq: "blog" } } - frontmatter: { published: { eq: true } } - } - ) { - group(field: { frontmatter: { category: SELECT } }) { - nodes { - id - } - fieldValue - } - } ${ shouldBuildFullSite ? `memberPosts: allMdx( @@ -327,19 +312,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { } } } - labs: allMdx( - filter: { fields: { collection: { eq: "kanvas-labs" } } } - ) { - nodes { - fields { - slug - collection - } - internal { - contentFilePath - } - } - } learncontent: allMdx( filter: { fields: { collection: { eq: "content-learn" } } } ) { @@ -358,25 +330,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { } } } - sistentComponents: allMdx( - filter: { - fields: { collection: { eq: "sistent" } } - } - ) { - group(field: { fields: { componentName: SELECT } }) { - fieldValue - nodes { - fields { - slug - componentName - pageType - } - internal { - contentFilePath - } - } - } - } } `); @@ -386,7 +339,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { return; } - const blogs = res.data.blogPosts.nodes; const resources = res.data.resourcePosts.nodes; const news = res.data.newsPosts.nodes; @@ -415,7 +367,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { const handbook = res.data.handbookPages.nodes; const singleWorkshop = res.data.singleWorkshop.nodes; - const labs = res.data.labs.nodes; if (isCollectionEnabled("events") && events.length > 0) { paginate({ @@ -427,44 +378,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { }); } - if (isCollectionEnabled("blog")) { - blogs.forEach((blog) => { - envCreatePage({ - path: blog.fields.slug, - component: `${blogPostTemplate}?__contentFilePath=${blog.internal.contentFilePath}`, - context: { - slug: blog.fields.slug, - }, - }); - }); - } - - const blogCategory = res.data.blogCategory.group; - if (isCollectionEnabled("blog")) { - blogCategory.forEach((category) => { - envCreatePage({ - path: `/blog/category/${slugify(category.fieldValue)}`, - component: blogCategoryListTemplate, - context: { - category: category.fieldValue, - }, - }); - }); - } - - const BlogTags = res.data.blogTags.group; - if (isCollectionEnabled("blog")) { - BlogTags.forEach((tag) => { - envCreatePage({ - path: `/blog/tag/${slugify(tag.fieldValue)}`, - component: blogTagListTemplate, - context: { - tag: tag.fieldValue, - }, - }); - }); - } - if (isCollectionEnabled("resources")) { resources.forEach((resource) => { envCreatePage({ @@ -567,16 +480,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { }); }); - labs.forEach((lab) => { - envCreatePage({ - path: lab.fields.slug, - component: `${LabTemplate}?__contentFilePath=${lab.internal.contentFilePath}`, - context: { - slug: lab.fields.slug, - }, - }); - }); - if (shouldBuildFullSite) { integrations.forEach((integration) => { envCreatePage({ @@ -761,29 +664,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { } }); - // Create Sistent component pages dynamically from MDX - // Use grouping to identify which sub-pages (Tabs) exist for each component - const sistentGroups = res.data.sistentComponents.group; - const sistentTemplate = path.resolve("src/templates/sistent-component.js"); - - sistentGroups.forEach((group) => { - const componentName = group.fieldValue; - // content-learn uses different fields, sistent uses componentName. - - const availablePages = group.nodes.map((node) => node.fields.pageType); - - group.nodes.forEach((node) => { - createPage({ - path: node.fields.slug, - component: `${sistentTemplate}?__contentFilePath=${node.internal.contentFilePath}`, - context: { - slug: node.fields.slug, - componentName: componentName, - availablePages: availablePages, - }, - }); - }); - }); }; // slug starts and ends with '/' so parts[0] and parts[-1] will be empty diff --git a/src/node-api/createBlogPages.js b/src/node-api/createBlogPages.js new file mode 100644 index 0000000000000..34fd521192505 --- /dev/null +++ b/src/node-api/createBlogPages.js @@ -0,0 +1,96 @@ +const slugify = require("../utils/slugify"); + +const createBlogPages = async ({ + graphql, + createPage, + reporter, + isCollectionEnabled, + blogPostTemplate, + blogCategoryListTemplate, + blogTagListTemplate, +}) => { + const result = await graphql(` + { + blogPosts: allMdx( + filter: { + fields: { collection: { eq: "blog" } } + frontmatter: { published: { eq: true } } + } + ) { + nodes { + fields { + slug + } + internal { + contentFilePath + } + } + } + blogTags: allMdx( + filter: { + fields: { collection: { eq: "blog" } } + frontmatter: { published: { eq: true } } + } + ) { + group(field: { frontmatter: { tags: SELECT } }) { + fieldValue + } + } + blogCategory: allMdx( + filter: { + fields: { collection: { eq: "blog" } } + frontmatter: { published: { eq: true } } + } + ) { + group(field: { frontmatter: { category: SELECT } }) { + fieldValue + } + } + } + `); + + if (result.errors) { + reporter.panicOnBuild("Error while running GraphQL query for blog pages."); + return; + } + + if (!isCollectionEnabled("blog")) { + return; + } + + const blogs = result.data.blogPosts.nodes; + const blogCategory = result.data.blogCategory.group; + const blogTags = result.data.blogTags.group; + + blogs.forEach((blog) => { + createPage({ + path: blog.fields.slug, + component: `${blogPostTemplate}?__contentFilePath=${blog.internal.contentFilePath}`, + context: { + slug: blog.fields.slug, + }, + }); + }); + + blogCategory.forEach((category) => { + createPage({ + path: `/blog/category/${slugify(category.fieldValue)}`, + component: blogCategoryListTemplate, + context: { + category: category.fieldValue, + }, + }); + }); + + blogTags.forEach((tag) => { + createPage({ + path: `/blog/tag/${slugify(tag.fieldValue)}`, + component: blogTagListTemplate, + context: { + tag: tag.fieldValue, + }, + }); + }); +}; + +module.exports = createBlogPages; diff --git a/src/node-api/createKanvasLabPages.js b/src/node-api/createKanvasLabPages.js new file mode 100644 index 0000000000000..69e66696969a0 --- /dev/null +++ b/src/node-api/createKanvasLabPages.js @@ -0,0 +1,37 @@ +const createKanvasLabPages = async ({ graphql, createPage, reporter, labTemplate }) => { + const result = await graphql(` + { + labs: allMdx( + filter: { fields: { collection: { eq: "kanvas-labs" } } } + ) { + nodes { + fields { + slug + } + internal { + contentFilePath + } + } + } + } + `); + + if (result.errors) { + reporter.panicOnBuild("Error while running GraphQL query for Kanvas labs pages."); + return; + } + + const labs = result.data.labs.nodes; + + labs.forEach((lab) => { + createPage({ + path: lab.fields.slug, + component: `${labTemplate}?__contentFilePath=${lab.internal.contentFilePath}`, + context: { + slug: lab.fields.slug, + }, + }); + }); +}; + +module.exports = createKanvasLabPages; diff --git a/src/node-api/createSistentComponentPages.js b/src/node-api/createSistentComponentPages.js new file mode 100644 index 0000000000000..189aa09e5bff5 --- /dev/null +++ b/src/node-api/createSistentComponentPages.js @@ -0,0 +1,56 @@ +const path = require("path"); + +const createSistentComponentPages = async ({ graphql, createPage, reporter }) => { + const result = await graphql(` + { + sistentComponents: allMdx( + filter: { + fields: { collection: { eq: "sistent" } } + } + ) { + group(field: { fields: { componentName: SELECT } }) { + fieldValue + nodes { + fields { + slug + componentName + pageType + } + internal { + contentFilePath + } + } + } + } + } + `); + + if (result.errors) { + reporter.panicOnBuild( + "Error while running GraphQL query for Sistent component pages.", + ); + return; + } + + const sistentTemplate = path.resolve("src/templates/sistent-component.js"); + const sistentGroups = result.data.sistentComponents.group; + + sistentGroups.forEach((group) => { + const componentName = group.fieldValue; + const availablePages = group.nodes.map((node) => node.fields.pageType); + + group.nodes.forEach((node) => { + createPage({ + path: node.fields.slug, + component: `${sistentTemplate}?__contentFilePath=${node.internal.contentFilePath}`, + context: { + slug: node.fields.slug, + componentName, + availablePages, + }, + }); + }); + }); +}; + +module.exports = createSistentComponentPages;