How to display blog posts in on a Hugo site with two languages?

Hello!

I want to build a site with two sections – English and German. In the German section I want to have following types of pages:

  1. Normal pages
  2. Blog posts
  3. One page that shows all blog posts

For now there will be only content in the German part of the page. The English part will only have “This site is under construction” page.

In hugo.toml I wrote the following:

baseURL = 'http://example.org/'
title = 'Sample Page'
theme = 'hugo-texify2'
defaultContentLanguage = 'de'
defaultContentLanguageInSubdir = true


[languages]
  [languages.en]
  contentDir = 'content/en'
  languageCode = 'en-us'
    [languages.en.params]
      title = 'Sample Page'
  [languages.de]
    contentDir = 'content/de'
    languageCode = 'de-de'
    [languages.de.params]
      title = 'Beispielseite'

This is supposed to mean that

  1. the content in English goes into content/en directory and that in German into content/de (defaultContentLanguageInSubdir) and
  2. German (de) is the main language (defaultContentLanguage).

In content/de/posts there are two pages – hf-1.org (post) and index.org.

hf-1.org looks like shown below.

---
title: "Hf 1"
date: 2024-04-04T10:05:44+02:00
draft: false
---

Huggingface.

Erstes Experiment mit Huggingface.

index.org contains the following text:

---
title: "Beiträge"
date: 2024-04-04T10:02:36+02:00
headless: true
draft: false
---

When I

  1. launch the site using hugo serve,
  2. open the URL http://localhost:1313/de/posts/hf-1/ in my browser or
  3. URL http://localhost:1313/de/posts/hf-1/,

I get “Page not found” errors.

What do I need to change in my project in order for

  1. the individual blog posts and
  2. the page with links to blog posts

to be displayed properly?

I am using Hugo v0.115 (hugo version returns hugo v0.115.3+extended darwin/amd64 BuildDate=unknown).

Thanks in advance

Pravles

Update 1: Changing hf-1.org leads to a weird behavior: Sometimes the page is displayed properly and sometimes I get “Page not found” error.

#+title: "Hf 1"
#+date: 2024-04-04T10:05:44+02:00
#+author: Pravles Redneckoff
#+draft: false
#+hugo_section: post

Huggingface.

Erstes Experiment mit Huggingface.

Rename index.org to _index.org.

See documentation about page bundles.

2 Likes

Thanks. I updated the GitHub repository accordingly.

Now the individual post (http://localhost:1313/de/posts/hf-1/) is displayed, but the page with the list of posts (http://localhost:1313/de/posts/) only shows three dots (see below).

How can I fix this, i. e. make sure that there is a preview of the hf-1 post on the posts page?

???

image

It can be a branch bundle, or a leaf bundle, but not both.

1 Like

Deleted index.org in the content/de/posts directory.

But the page with the list of posts still shows only three dots.

The theme expects the section to be named “post” (singular) not “posts”.

1 Like

Many thanks.

Now the list of posts is rendered under http://localhost:1313/de/.

Is there a way to make sure that

  • http://localhost:1313/de/ shows the content of content/de/_index.org and
  • http://localhost:1313/de/post/ the list of posts?

The second is already implemented.

I noticed you modified themes/hugo-texify2/hugo.toml. Why?

If you need to override something in a theme, make a copy of the file using the same path but relative to the project root.

I noticed you modified themes/hugo-texify2/hugo.toml. Why?

To adapt the menu. I didn’t know one can do it without changing the theme.

Override the home page template:

mkdir layouts
cp themes/hugo-texify2/layouts/index.html layouts/

Then edit layouts/index.html, inserting .Content somewhere within the main element. For example:

<main id="main" class="index">
  
  {{ .Content }}

  {{ $paginator := .Paginate (where .Site.RegularPages "Type" "==" "post") }}
1 Like

Never change any of the theme files. If you update the theme in the future (e.g., after the theme author fixes bugs or adds features) you will lose your changes!

1 Like

I have a multilingual site with German, French, and other languages. There are a few subtleties, but I’ve been able to get it to do anything I want:

Here’s my config file: A multilingual Hugo configuration · GitHub

1 Like

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