Force lang prefix (en) with only one language?

I currently have a website that has only one language (English). I do however want my URLs to be prefixed by /en/. Is this supported? I have tried a few combinations of contentDir (content/en, content/) but none of them seem to work. If I define only one language in config.toml, I get a 404 on any url under root/en/*

My folder looks like this:

content
---- en
------ section 1

Similar question on Github.
TIA

In site configuration:

baseURL = 'https://example.org/en/'

If/when you add more languages, remove the trailing en/ from the baseURL.

2 Likes

Thanks, that partially works as images are now expected to be at /en/image/image.png.

As this is a migration from an older version of Hugo/Docsy, most of the images are in a static/image/image.png folder.

Images are added to docs using Markdown as ![](/image/new-ui.png).

Any hints on solving that? I’m also trying to minimize the work required once we do add another language.

That is unfortunate.

This would not be an issue if images were either page resources or global resources, accessed directly or through an image render hook. However, depending on the size of your project, making these changes may require considerable effort.

How about this instead?

  1. Define two languages in site configuration
  2. Do not create any content for the second language
  3. Override the the built-in sitemapindex.xml template to include only one language (see docs)
  4. Override any other template code that renders alternate language links (language switchers, meta tags, etc.).

When you ultimately add a second language, revert #3 and #4.

1 Like

Thank you. That is indeed the direction I’m pursuing for the moment. I very much appreciate the support. :hand_with_index_finger_and_thumb_crossed:

1 Like

Ended up with
layouts/sitemapindex.xml

{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  {{ range . }}
    {{ if (eq .Language.Lang "en") }}
        <sitemap>
            <loc>{{ .SitemapAbsURL }}</loc>
            {{ if not .LastChange.IsZero }}
            <lastmod>{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
            {{ end }}
        </sitemap>
    {{ end }}
  {{ end }}
</sitemapindex>

assets/scss/_styles_project.scss

.nav-item.dropdown {
    display: none !important;
}

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