gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.52k stars 7.38k forks source link

multihost: Console displays wrong language key when running hugo server #12564

Open jmooring opened 4 weeks ago

jmooring commented 4 weeks ago

This isn't anything recent... the problem has been present since v0.119.0.

Background

In a multihost configuration, when you run hugo server, the console displays something like:

Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) en
Web Server is available at http://localhost:1314/ (bind address 127.0.0.1) de

We added the language key to the end of each line in v0.119.0 via #11442.

Problem

If the default content language does not correspond to the first site by weight (or language key fallback), the wrong language key is displayed at the end of each line.

Example

defaultContentLanguage = 'en'

[languages.de]
baseURL = 'https://de.example.org/'
weight = 1

[languages.en]
baseURL = 'https://en.example.org/'
weight = 2

When I run hugo server I see this in the console:

Web Server is available at http://localhost:1314/ (bind address 127.0.0.1) en
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) de

But http://localhost:1314/ is serving the DE site, while http://localhost:1313/ is serving the EN site.


Commentary

It seems like this, and similar areas of the code base, would be a lot simpler if the default content language were hardcoded to the the lightest weighted/sorted language. I guess I've never understood the use case for the configuration above.

bep commented 3 weeks ago

would be a lot simpler if the default content language were hardcoded to the the lightest weighted/sorted language.

I think this mostly comes from a time where we needed the value of defaultContentLanguage before we had bult the languages/sites slice.

But the above slice also defines the default sort order of languages (as seen in .AllTranslations) used in language selectors, so it's not a strange requirement to be able to control. that order independently from defaultContentLanguage.