diff --git a/examples/sitemap/gatsby-config.js b/examples/sitemap/gatsby-config.js index 39cd906d29328..8b2187e566568 100644 --- a/examples/sitemap/gatsby-config.js +++ b/examples/sitemap/gatsby-config.js @@ -15,6 +15,9 @@ module.exports = { `gatsby-transformer-remark`, { resolve: `gatsby-plugin-sitemap`, + options: { + exclude: [`/secret`], + }, }, ], } diff --git a/examples/sitemap/gatsby-node.js b/examples/sitemap/gatsby-node.js index edab7e1ee4a4d..7c3b752d9679b 100644 --- a/examples/sitemap/gatsby-node.js +++ b/examples/sitemap/gatsby-node.js @@ -1,4 +1,49 @@ const path = require(`path`) +const slash = require(`slash`) + +exports.createPages = ({ graphql, boundActionCreators }) => { + const { createPage } = boundActionCreators + + return new Promise((resolve, reject) => { + const blogPostTemplate = path.resolve(`src/templates/template-blog-post.js`) + graphql( + ` + { + allMarkdownRemark( + limit: 1000 + filter: { frontmatter: { draft: { ne: true } } } + ) { + edges { + node { + fields { + slug + } + } + } + } + } + ` + ).then(result => { + if (result.errors) { + console.log(result.errors) + reject(result.errors) + } + + // Create blog posts pages. + result.data.allMarkdownRemark.edges.forEach(edge => { + createPage({ + path: edge.node.fields.slug, // required + component: slash(blogPostTemplate), + context: { + slug: edge.node.fields.slug, + }, + }) + }) + + resolve() + }) + }) +} exports.onCreateNode = ({ node, boundActionCreators, getNode }) => { const { createNodeField } = boundActionCreators diff --git a/examples/sitemap/package.json b/examples/sitemap/package.json index 87965d9ba2730..57620aa08af4c 100644 --- a/examples/sitemap/package.json +++ b/examples/sitemap/package.json @@ -10,7 +10,9 @@ "gatsby-transformer-remark": "latest", "gatsby-plugin-sitemap": "latest" }, - "keywords": ["gatsby"], + "keywords": [ + "gatsby" + ], "license": "MIT", "main": "index.js", "scripts": { diff --git a/examples/sitemap/src/html.js b/examples/sitemap/src/html.js deleted file mode 100644 index ecd3580eea08d..0000000000000 --- a/examples/sitemap/src/html.js +++ /dev/null @@ -1,44 +0,0 @@ -import React, { Component } from "react" -import * as PropTypes from "prop-types" - -const propTypes = { - headComponents: PropTypes.node.isRequired, - body: PropTypes.node.isRequired, - postBodyComponents: PropTypes.node.isRequired, -} - -class Html extends Component { - render() { - return ( - -
- {this.props.headComponents} - - - - - - -Welcome to the GatsbyJS Sitemap Demo. Visit{` `} - + to see the generated sitemap.
+
+ Note: gatsby-plugin-sitemap uses siteMetadata.siteUrl
{` `}
+ defined in gatsby-config.js to construct absolute URLs!
+
This page should be included in sitemap.xml
+This page should be excluded from sitemap.xml
+