Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require("path");
- //Create dynamically blog pages
- exports.createPages = async ({ graphql, actions, reporter }) => {
- const { createPage } = actions;
- const markdownFiles = await graphql(`
- {
- allMarkdownRemark {
- nodes {
- html
- frontmatter {
- author
- date
- title
- slug
- }
- }
- }
- }
- `);
- if (markdownFiles.errors) {
- reporter.panicOnBuild("Error while creating blog pages!");
- return;
- }
- const blogPostTemplate = path.resolve("src/templates/blog-post.js");
- markdownFiles.data.allMarkdownRemark.nodes.forEach(markdownFile => {
- createPage({
- path: `blog/${markdownFile.frontmatter.slug}`,
- component: blogPostTemplate,
- context: {
- slug: markdownFile.frontmatter.slug
- }
- });
- });
- reporter.info(JSON.stringify(markdownFiles, null, 2));
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement