Sitemap in single language website with /en prefix

Follow-up of: Force lang prefix (en) with only one language?

I have recently being able to force the /en path for a single language website, with the below configuration (this is probably some recent hugo enhancement, either intentional, or unintentional):

defaultContentLanguageInSubdir = true
defaultContentLanguage = "en"

[languages]
[languages.en]
languageName = "English"
staticDir = "static"
contentDir = "content/en"

Everything works, aside from the sitemap which keeps generating the wrong sitemap.

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>//localhost:1313/sitemap.xml</loc>
<lastmod>2024-03-15T13:15:11-04:00</lastmod>
</sitemap>
</sitemapindex>

It should be //localhost:1313/en/sitemap.xml instead of //localhost:1313/sitemap.xml

This is due to this line I believe: hugo/hugolib/site.go at d4d49e0f0ec53ef7e105c51b5c6fd198c86acb7e · gohugoio/hugo · GitHub

func (s *Site) HomeAbsURL() string {
	base := ""
	if len(s.conf.Languages) > 1 {
		base = s.Language().Lang
	}
	return s.AbsURL(base, false)
}

Is there anything that I can do that do not involve redefining sitemapindex.xml?

Is this considered a bug I should report? (I think I may be using Docsy/Hugo) in non recommended ways as per @jmooring comment in Force lang prefix (en) with only one language?

Yes, this is a bug. This simple configuration:

baseURL = 'https://example.org/'
title = 'Hugo Forum Topic #48861'
disableKinds = ['rss','taxonomy','term']
defaultContentLanguageInSubdir = true

With this content:

content/
└── _index.md

Is published to:

public/
├── en/
│   ├── index.html
│   └── sitemap.xml
├── index.html
└── sitemap.xml  <-- this is a sitemapindex, but it points to itself

I’m not sure what the fix is though. Should the sitemapindex point to https://example.org/en/sitemap.xml, or should the actual sitemap be moved to the root (replacing sitemap index)?. It seems like the former would be the right thing to do.

I think the correct behaviour should be what I see in the docsy example site → https://example.docsy.dev/sitemap.xml

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>/en/sitemap.xml</loc>
    <lastmod>2023-11-10T12:40:56+01:00</lastmod>
  </sitemap>
  <sitemap>
    <loc>/fa/sitemap.xml</loc>
    <lastmod>2023-11-10T12:40:56+01:00</lastmod>
  </sitemap>
  <sitemap>
    <loc>/no/sitemap.xml</loc>
    <lastmod>2023-11-10T07:28:51-05:00</lastmod>
  </sitemap>
</sitemapindex>

So in your dummy example:

One language neutral sitemap.xml (index) at root, that points to a language specific sitemap under /en/sitemap.xml

Something like

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>/en/sitemap.xml</loc>
    <lastmod>2023-11-10T12:40:56+01:00</lastmod>
  </sitemap>
</sitemapindex>

The embedded template generates absolute URLs, so even if we fix this, you’ll need to override the sitemapindex template to get relative URLs.

I’ll log an issue on this… it isn’t anything new.

See https://github.com/gohugoio/hugo/pull/12267, merged and available in the next release.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.