【问题标题】:`next-sitemap` duplicated language in alternate ref path (href)`next-sitemap` 在备用参考路径(href)中重复的语言
【发布时间】:2022-10-25 17:37:35
【问题描述】:

..我有一个支持多语言的 Next.js 应用程序(英语作为默认语言,德语作为次要语言 - 英语在 https://mywebsite.com 上,德语在 https://mywebsite.com/de 上)。

我正在使用next-sitemap 为页面生成站点地图,并使用备用参考链接来链接页面的英语和德语版本。以下是我的下一个站点地图配置:

/** @type {import('next-sitemap').IConfig} */
module.exports = {
  siteUrl: `https://mywebsite.com`,
  generateRobotsTxt: true,
  exclude: ['/app/*', '/social-redirect'],
  robotsTxtOptions: {
    policies: [
      {
        userAgent: '*',
        [process.env.VERCEL_ENV !== 'preview' && process.env.VERCEL_ENV !== 'development'
          ? 'allow'
          : 'disallow']: '/',
      },
    ],
  },
  alternateRefs: [
    {
      href: 'https://mywebsite.com',
      hreflang: 'en',
    },
    {
      href: 'https://mywebsite.com/de',
      hreflang: 'de',
    },
  ],
};

在生成的站点地图中,站点地图的英文条目看起来不错。他们有正确的备用裁判。但是在站点地图的德语条目中,备用参考在路径中具有两次语言,例如:https://mywebsite.com/de/de/blog。这是next-sitemap 的问题还是我做错了什么?如果有人可以帮助我,我会很高兴!

【问题讨论】:

  • 尝试从备用参考的href 中删除/de
  • 嗨@juliomalves,谢谢你的评论——我已经试过了。结果是,在站点地图的英文条目中,德语的备用参考不正确——它们也只是指向英文版本。

标签: next.js sitemap.xml


【解决方案1】:

这也发生在我身上。我认为这是下一个站点地图的问题

就我而言,我有语言zh英文生成的网址是:

  • <xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/en-gb/blog/"/>
  • <xhtml:link rel="alternate" hreflang="en-gb" href="http://localhost:3000/en-gb/en-gb/blog/"/>

您可以使用 transform 属性来配置替换 transform: async (config, path) => { return { ...config, loc: path.replace('/en-gb/en-gb', '/en-gb') } }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2022-08-12
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多