Skip to content

[gatsby-plugin-sitemap] Documentation and DX improvements #29810

@jevenson

Description

@jevenson

Summary

I implemented gatsby-plugin-sitemap onto my site just now, and I ran into a few problems that I think could've been prevented by improving documentation and adding some error handling with logging in the plugin.

First, I was unclear that it is required to query allSitePage with a path property. The docs do state this, however as devs do, we typically skim documentation. Would be good to add error handling/logging when the allSitePage option is missing.

Second, I forgot to return from the serialize function, which led to this error. I think this could be improved with some error handling. If urls is undefined, throw an error with a message "gatsby-plugin-sitemap did not recieve sitemap entries. Did you forget to return from your serialize function". Or something of that nature.

 ERROR #11321  PLUGIN

"gatsby-plugin-sitemap" threw an error while running the onPostBuild lifecycle:

Cannot read property 'forEach' of undefined

  79 | 
  80 |             map = _sitemap.default.createSitemap(rest);
> 81 |             urls.forEach(function (u) {
     |                  ^
  82 |               return map.add(u);
  83 |             });
  84 |             return _context.abrupt("return", (0, _internals.writeFile)(saved,
map.toString()));

File: node_modules\gatsby-plugin-sitemap\gatsby-node.js:81:18

Motivation

To improve DX when implementing the sitemap plugin

Steps to resolve this issue

I will be cooking up a pull request for your consideration to resolve these issues 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: documentationAn issue or pull request for improving or updating Gatsby's documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions