Skip to content

Commit c622456

Browse files
refactor: improve dynamic page creation logic for sistent components
Signed-off-by: Vidit Kushwaha <[email protected]>
1 parent 2f3e0ee commit c622456

File tree

1 file changed

+122
-70
lines changed

1 file changed

+122
-70
lines changed

gatsby-node.js

Lines changed: 122 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -389,84 +389,99 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
389389
const resourcePostTemplate = path.resolve("src/templates/resource-single.js");
390390
const integrationTemplate = path.resolve("src/templates/integrations.js");
391391

392-
const res = await graphql(`{
393-
allPosts: allMdx(filter: {frontmatter: {published: {eq: true}}}) {
394-
nodes {
395-
frontmatter {
396-
program
397-
programSlug
398-
}
399-
fields {
400-
collection
401-
slug
402-
}
403-
}
404-
}
405-
blogTags: allMdx(
406-
filter: {fields: {collection: {eq: "blog"}}, frontmatter: {published: {eq: true}}}
407-
) {
408-
group(field: {frontmatter: {tags: SELECT}}) {
409-
nodes {
410-
id
392+
const res = await graphql(`
393+
{
394+
allPosts: allMdx(filter: { frontmatter: { published: { eq: true } } }) {
395+
nodes {
396+
frontmatter {
397+
program
398+
programSlug
399+
}
400+
fields {
401+
collection
402+
slug
403+
}
404+
}
411405
}
412-
fieldValue
413-
}
414-
}
415-
blogCategory: allMdx(
416-
filter: {fields: {collection: {eq: "blog"}}, frontmatter: {published: {eq: true}}}
417-
) {
418-
group(field: {frontmatter: {category: SELECT}}) {
419-
nodes {
420-
id
406+
blogTags: allMdx(
407+
filter: {
408+
fields: { collection: { eq: "blog" } }
409+
frontmatter: { published: { eq: true } }
410+
}
411+
) {
412+
group(field: { frontmatter: { tags: SELECT } }) {
413+
nodes {
414+
id
415+
}
416+
fieldValue
417+
}
421418
}
422-
fieldValue
423-
}
424-
}
425-
memberBio: allMdx(
426-
filter: {fields: {collection: {eq: "members"}}, frontmatter: {published: {eq: true}, executive_bio: {eq: true}}}
427-
) {
428-
nodes {
429-
frontmatter {
430-
name
419+
blogCategory: allMdx(
420+
filter: {
421+
fields: { collection: { eq: "blog" } }
422+
frontmatter: { published: { eq: true } }
423+
}
424+
) {
425+
group(field: { frontmatter: { category: SELECT } }) {
426+
nodes {
427+
id
428+
}
429+
fieldValue
430+
}
431431
}
432-
fields {
433-
slug
434-
collection
432+
memberBio: allMdx(
433+
filter: {
434+
fields: { collection: { eq: "members" } }
435+
frontmatter: { published: { eq: true }, executive_bio: { eq: true } }
436+
}
437+
) {
438+
nodes {
439+
frontmatter {
440+
name
441+
}
442+
fields {
443+
slug
444+
collection
445+
}
446+
}
435447
}
436-
}
437-
}
438-
singleWorkshop: allMdx(
439-
filter: {fields: {collection: {eq: "service-mesh-workshops"}}}
440-
) {
441-
nodes {
442-
fields {
443-
slug
444-
collection
448+
singleWorkshop: allMdx(
449+
filter: { fields: { collection: { eq: "service-mesh-workshops" } } }
450+
) {
451+
nodes {
452+
fields {
453+
slug
454+
collection
455+
}
456+
}
445457
}
446-
}
447-
}
448-
labs: allMdx(filter: {fields: {collection: {eq: "service-mesh-labs"}}}) {
449-
nodes {
450-
fields {
451-
slug
452-
collection
458+
labs: allMdx(
459+
filter: { fields: { collection: { eq: "service-mesh-labs" } } }
460+
) {
461+
nodes {
462+
fields {
463+
slug
464+
collection
465+
}
466+
}
453467
}
454-
}
455-
}
456-
learncontent: allMdx(filter: {fields: {collection: {eq: "content-learn"}}}) {
457-
nodes {
458-
fields {
459-
learnpath
460-
slug
461-
course
462-
section
463-
chapter
464-
pageType
465-
collection
468+
learncontent: allMdx(
469+
filter: { fields: { collection: { eq: "content-learn" } } }
470+
) {
471+
nodes {
472+
fields {
473+
learnpath
474+
slug
475+
course
476+
section
477+
chapter
478+
pageType
479+
collection
480+
}
481+
}
466482
}
467483
}
468-
}
469-
}`);
484+
`);
470485

471486
// handle errors
472487
if (res.errors) {
@@ -707,6 +722,43 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
707722
}
708723
}
709724
});
725+
726+
const components = [
727+
"button",
728+
"text-input",
729+
"model",
730+
"paper",
731+
"popper",
732+
"text-field",
733+
"link",
734+
"container",
735+
"button-group",
736+
];
737+
738+
const createComponentPages = (createPage, components) => {
739+
const pageTypes = [
740+
{ suffix: "", file: "index.js" },
741+
{ suffix: "/guidance", file: "guidance.js" },
742+
{ suffix: "/code", file: "code.js" },
743+
];
744+
745+
components.forEach((name) => {
746+
pageTypes.forEach(({ suffix, file }) => {
747+
const path = `/projects/sistent/components/${name}${suffix}`;
748+
const componentPath = `./src/sections/Projects/Sistent/components/${name}/${file}`;
749+
try {
750+
createPage({
751+
path,
752+
component: require.resolve(componentPath),
753+
});
754+
} catch (error) {
755+
console.error(`Error creating page for ${path}:`, error);
756+
}
757+
});
758+
});
759+
};
760+
761+
createComponentPages(createPage, components);
710762
};
711763

712764
// slug starts and ends with '/' so parts[0] and parts[-1] will be empty

0 commit comments

Comments
 (0)