Skip to content

Instantly share code, notes, and snippets.

@openscript
Created June 4, 2022 09:55
Show Gist options
  • Save openscript/d56a810c1fe9b2639ba0b112e217f8ce to your computer and use it in GitHub Desktop.
Save openscript/d56a810c1fe9b2639ba0b112e217f8ce to your computer and use it in GitHub Desktop.
import { GatsbyNode } from 'gatsby';
import { resolve } from 'path';
export const createPages: GatsbyNode['createPages'] = async args => {
const { actions, graphql } = args;
const { createPage } = actions;
const allPages = await graphql<Queries.AllGenericPagesQuery>(`
query AllGenericPages {
allMdx(filter: { fields: { kind: { eq: "pages" } } }) {
edges {
node {
id
fields {
path
translations {
locale
path
}
}
}
}
}
}
`);
allPages.data?.allMdx.edges.forEach(p => {
if (p.node.fields && p.node.fields.path) {
createPage({
component: resolve('./src/templates/GenericPage.tsx'),
context: { id: p.node.id, translations: p.node.fields.translations },
path: p.node.fields.path,
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment