Skip to content
Open
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
172 changes: 26 additions & 146 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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" } }
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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" } } }
) {
Expand All @@ -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
}
}
}
}
}
`);

Expand All @@ -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;

Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
96 changes: 96 additions & 0 deletions src/node-api/createBlogPages.js
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions src/node-api/createKanvasLabPages.js
Original file line number Diff line number Diff line change
@@ -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;
Loading
Loading