question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gatsby-plugin-sitemap generates NaN-NaN-NaN on <lastmod>

See original GitHub issue

Description

When using gatsby-plugin-sitemap to generate sitemap.xml, <lastmod> was not available by default.

Manually adding this would output <lastmod> tags in the final sitemap.xml, but the date were written as NaN-NaN-NaN

Note: Even if we manually uses lastmod: '2020-08-03T01:54:49.000Z' during the serialize below still outputs as NaN

Steps to reproduce

{
      resolve: `gatsby-plugin-sitemap`,
      options: {
        createLinkInHead: true,
        query: `{
          site {
            siteMetadata {
              siteUrl
            }
          }

          allSitePage {
            nodes {
              path
              context {
                updated
              }
            }
          }
        }`,
        resolveSiteUrl: ({ site }) => {
          return site.siteMetadata.siteUrl;
        },
        serialize: ({ site, allSitePage }) =>
          allSitePage.nodes.map((node) => {
            return {
              url: `${site.siteMetadata.siteUrl}${node.path}`,
              changefreq: `daily`,
              priority: 0.7,
              lastmod: `${node.context.updated}`,
            };
          }),
      },
    },

Expected result

Expecting the sitemap to output entries with correct last-modified tags, ie:<lastmod>2020-08-03T01:54:49.000Z</lastmod>

Actual result

<lastmod>NaN-NaN-NaN</lastmod>

Environment

System: OS: macOS 10.15.6 CPU: (8) x64 Intel® Core™ i7-6820HQ CPU @ 2.70GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node npm: 6.14.7 - ~/.nvm/versions/node/v12.17.0/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 84.0.4147.105 Safari: 13.1.2 npmPackages: gatsby: ^2.24.4 => 2.24.4 gatsby-image: ^2.4.13 => 2.4.13 gatsby-plugin-catch-links: ^2.3.11 => 2.3.11 gatsby-plugin-feed-mdx: ^1.0.1 => 1.0.1 gatsby-plugin-google-analytics: ^2.3.11 => 2.3.11 gatsby-plugin-manifest: ^2.4.18 => 2.4.21 gatsby-plugin-mdx: ^1.2.27 => 1.2.27 gatsby-plugin-offline: ^3.2.18 => 3.2.18 gatsby-plugin-preact: ^4.0.9 => 4.0.9 gatsby-plugin-react-helmet: ^3.3.10 => 3.3.10 gatsby-plugin-robots-txt: ^1.5.1 => 1.5.1 gatsby-plugin-s3: ^0.3.3 => 0.3.4 gatsby-plugin-sharp: ^2.6.19 => 2.6.22 gatsby-plugin-sitemap: ^2.4.11 => 2.4.11 gatsby-plugin-styled-components: ^3.3.10 => 3.3.10 gatsby-remark-attr: ^0.1.0 => 0.1.0 gatsby-remark-external-links: 0.0.4 => 0.0.4 gatsby-remark-images: ^3.3.19 => 3.3.19 gatsby-remark-unwrap-images: ^1.0.2 => 1.0.2 gatsby-source-filesystem: ^2.3.20 => 2.3.23 gatsby-transformer-sharp: ^2.5.11 => 2.5.11 npmGlobalPackages: gatsby-cli: 2.12.66

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
flikteohcommented, Aug 4, 2020

@fgambarino Thank you so much. That fixes my problem.

Was wondering why isn’t there any documentation regarding to this on the plugin page itself. Whether is it lastmod or lastmodISO, I felt that it’s somewhat important for users.

Also,

https://support.google.com/webmasters/answer/183668?hl=en Google ignores <priority> and <changefreq> values, so don’t bother adding them. Google reads the <lastmod> value, but if you misrepresent this value, we will stop reading it.

and sorry @vladar I’m unable to create a minimal reproduction for this issue.

In case anyone that came across similar problem, this solved my problem:

via the lastmodISO

    {
      resolve: `gatsby-plugin-sitemap`,
      options: {
        query: `{
          site {
            siteMetadata {
              siteUrl
            }
          }

          allSitePage {
            nodes {
              path
              context {
                updated
              }
            }
          }
        }`,
        resolveSiteUrl: ({ site }) => site.siteMetadata.siteUrl,
        serialize: ({ site, allSitePage }) =>
          allSitePage.nodes.map((node) => {
            const { siteUrl } = site.siteMetadata;
            return {
              url: `${siteUrl}${node.path}`,
              lastmodISO: node.context.updated,
            };
          }),
        createLinkInHead: true,
      },
    },
0reactions
github-actions[bot]commented, Aug 24, 2020

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label “not stale” to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add a Sitemap and Robots.txt to a Gatsby Project
In this video, I demonstrate adding and configuring an XML Sitemap and a robots.txt file for a Gatsby site.We're going to be bringing...
Read more >
gatsby-plugin-sitemap
Create a sitemap for your Gatsby site. Please note: This plugin only generates output when run in production mode! To test your sitemap,...
Read more >
How to get updated / lastmod value for static files for sitemap ...
1. Use gatsby-source-filesystem to add the static page files to your filesystem so you can query them. In gatsby-config.js add the following ...
Read more >
youtube.comou' Code Example
... Syntax Error: Error: PostCSS plugin tailwindcss requires PostCSS 8. ... join tmux windows into a pane · NaN Check for Data Numbers...
Read more >
Generate an SEO-Friendly Sitemap for your Gatsby Site
Whenever we build our site, this plugin will generate a sitemap.xml file, alongside all the other files that Gatsby builds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found