Open stekhn opened 11 months ago
@stekhn have you found a workaround for this error?
@enriquedecote Unfortunately, no. I refactored the whole project to use the Gatsby Node API, which gives me the flexibility I need without the bugs.
@stekhn I am having a similar issue are you able to share your refactored code?
@TapiwaCh: Yeah, sure this how I generate my project and blog post pages with the Gatsby Node API:
import { resolve } from 'path';
import { GatsbyNode } from 'gatsby';
import { IMarkdown } from './src/types/markdown';
import { IProject } from './src/types/projects';
export const createPages: GatsbyNode['createPages'] = async ({
graphql,
actions,
reporter,
}) => {
const { createPage } = actions;
// Create project pages
const projectPagesData: {
errors?: any;
data?: IMarkdown<IProject>;
} = await graphql(`
{
allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/projects/" } }
sort: { frontmatter: { date: DESC } }
) {
nodes {
frontmatter {
slug
title
description
date
}
}
}
}
`);
if (projectPagesData.errors) {
reporter.panicOnBuild(projectPagesData.errors);
}
const projects = projectPagesData.data!.allMarkdownRemark.nodes;
const projectPageTemplate = resolve('./src/templates/ProjectPage.tsx');
projects.forEach(({ frontmatter }) => {
createPage({
path: `/projects/${frontmatter.slug}/`,
component: projectPageTemplate,
context: { ...frontmatter },
});
});
reporter.info(`Project pages created: ${projects.length}`);
// Create blog posts pages
const blogPostData: {
errors?: any;
data?: IMarkdown<IProject>;
} = await graphql(`
{
allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/blog/" } }
sort: { frontmatter: { date: DESC } }
) {
nodes {
html
frontmatter {
slug
title
description
date
}
}
}
}
`);
if (blogPostData.errors) {
reporter.panicOnBuild(blogPostData.errors);
}
const blogPosts = blogPostData.data!.allMarkdownRemark.nodes;
const blogPostTemplate = resolve('./src/templates/BlogPost.tsx');
blogPosts.forEach(({ frontmatter, html }) => {
createPage({
path: `/blog/${frontmatter.slug}/`,
component: blogPostTemplate,
context: { ...frontmatter, html },
});
});
reporter.info(`Blog posts created: ${blogPosts.length}`);
};
Preliminary Checks
Description
I'm trying to create multiple pages from Markdown files which fall into two categories: blog posts and project pages. The Markdown files get sourced from two different folders using the gatsby-source-filesystem plugin. The gatsby-config.ts looks like this:
The pages get generated using gatsby-transformer-remark. Im using two page templates, if you can call them that:
Each page template has a slightly different page query that relies on the file path to distinguish between blog posts and project pages:
When running
gatsby develop
, everything is fine. My page overview (index.tsx) works fine and I can navigate to the individual pages and back. But when I rungatsby build
the static page generation fails with this error:To me it seems like the filters on the GraphQL query get ignored resulting in Gatsby trying to build pages that simply do not exist like
/projects/blog-post-1/
or/blog/project-1/
.Reproduction Link
https://github.com/stekhn/gatsby-multiple-md-pages
Steps to Reproduce
git clone https://github.com/stekhn/gatsby-multiple-md-pages
cd gatsby-multiple-md-pages
npm install
npm run build
Expected Result
gatsby build
should pass and the following pages are to be created:This is a logical outcome, since the respective templates
{MarkdownRemark.frontmatter__slug}.tsx
have a GraphQL query that each filters for category based on the filepath:Actual Result
gatsby build
fails as Gatsby tries to create the following pages:This is behaviour seems weird, as if the filters on the GraphQL queries within the
{MarkdownRemark.frontmatter__slug}.tsx
templates get ignored.Environment
Config Flags
No response