【问题标题】:How do I fix sitemap errors?如何修复站点地图错误?
【发布时间】:2021-03-28 17:54:29
【问题描述】:

站点地图不起作用 我无法获取站点地图 URL,也无法使用 /sitemap.xml URL 我该如何解决??

  siteMetadata: {
    siteUrl: siteAddress.href, // which is "https://www.example.com/"
  },
 {
  resolve: `gatsby-plugin-sitemap`,
  options: {
    head: true,
    output: `/sitemap.xml`,
  }

【问题讨论】:

  • 你能用比“不起作用”更专业的术语来解释吗?
  • 我无法获取站点地图的 URL,我不知道为什么
  • 我们对“不起作用”无能为力。我们可以帮助您解决具体错误或您尝试解决的技术问题。

标签: graphql gatsby xml-sitemap gatsby-plugin


【解决方案1】:

您是否尝试过构建您的项目? From the docs:

注意:此插件仅在生产模式下运行时才会生成输出!要测试您的站点地图,请运行:gatsby build && gatsby serve

此外,您的插件选项无效:head 应为 createLinkInHead。带有查询的完整示例应如下所示:

 {
    resolve: `gatsby-plugin-sitemap`,
    options: {
      output: `/some-other-sitemap.xml`,
      createLinkInHead: true,
      exclude: [`/category/*`, `/path/to/page`],
      query: `
        {
          wp {
            generalSettings {
              siteUrl
            }
          }

          allSitePage {
            nodes {
              path
            }
          }
      }`,
      resolveSiteUrl: ({site, allSitePage}) => {
        return site.wp.generalSettings.siteUrl
      },
      serialize: ({ site, allSitePage }) =>
        allSitePage.nodes.map(node => {
          return {
            url: `${site.wp.generalSettings.siteUrl}${node.path}`,
            changefreq: `daily`,
            priority: 0.7,
          }
        })
    }
  }

或者,您可以使用gatsby-plugin-advanced-sitemap,它具有更多可自定义的选项。

【讨论】:

    猜你喜欢
    • 2019-06-10
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    相关资源
    最近更新 更多