如何在多语言Hugo网站中自定义默认语言站点图URL

发布于 2025-01-22 12:03:19 字数 693 浏览 2 评论 0 原文

我在雨果(Hugo)上有一个多语言网站,现在自动生成的站点地图是以下内容:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
   <loc>https://domain/en/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
  <sitemap>
   <loc>https://domain/it/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
</sitemapindex>

问题是,英语中的所有内容(默认语言)中不包含 /en en url中的所有内容,而只是简单/产品 /博客。意大利内容中包含URL中的语言指示,例如 /it /prodotti, /it /blog。

在站点地图方面,似乎不建议在 /en /entemap中使用英语站点地图。它应该在 /domain/sitemap_en.xml中。

关于如何自定义站点地点本地化URL的任何线索?

谢谢。

I have a multilanguage website in Hugo and right now the sitemap generated automatically is the following:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
   <loc>https://domain/en/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
  <sitemap>
   <loc>https://domain/it/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
</sitemapindex>

The issue is that all the content in English, which is the default language, does not contain /en in the url but simply the slug itself, such as /products /blog. The italian content contains the language indication in the url instead, such as /it/prodotti, /it/blog.

Sitemap-wise, it doesn't seem to be advisable to have the english sitemap in /en/sitemap. It should be in /domain/sitemap_en.xml instead.

Any clue on how to customise the localised url of the sitemap?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2025-01-29 12:03:19

这是SiteMapIndex的Hugo内置模板:

他们使用 .sitemapabsurl varible,但我没有从文档中找到的文档中找到。 。但是,您可以使用 .permalik 重写SiteMapIndex。

要覆盖内置的SiteMapIndex.xml模板,请在这两个位置创建一个新文件:

  • 布局/sitemapindex.xml
  • 布局/_default/stitemapindex.xml

Here is the hugo Built-in Template for sitemapindex:
https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/sitemapindex.xml

They use .SitemapAbsURL variable, but I didn't find in documentation from where it came. However, you could rewrite sitemapindex for example with .Permalik

To override the built-in sitemapindex.xml template, create a new file in either of these locations:

  • layouts/sitemapindex.xml
  • layouts/_default/sitemapindex.xml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文