How to avoid duplicating multilingual content in the index.json of the main language?

My layouts/_default/index.json is:

{{- $index := slice -}}
{{- range .Site.RegularPages -}}
    {{- $index = $index | append (dict "title" .Title "tags" .Params.tags "categories" .Params.categories "contents" .Plain "permalink" .Permalink) -}}
{{- end -}}
{{- $index | jsonify -}}

I added another language and now the English index.json duplicates the content. How can I avoid this?

The site source is infra/libreofficeorg - Gitiles (not multilingual at the moment).

I don’t understand the question. With a multilingual site you would typically generate an index.json file for each language. For example, this…

site configuration
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true

[languages.en]
languageCode = 'en-US'
languageDirection = 'ltr'
languageName = 'English'
weight = 1

[languages.de]
languageCode = 'de-DE'
languageDirection = 'ltr'
languageName = 'Deutsch'
weight = 2

[outputs]
home = ['html','json']

layouts/_default/index.json
{{- $s := slice }}
{{- range site.RegularPages }}
  {{- $s = $s | append (dict "title" .Title "relpermalink" .Permalink) }}
{{- end }}
{{- jsonify $s }}

content structure
content/
├── posts/
│   ├── post-1.de.md
│   ├── post-1.md
│   ├── post-2.de.md
│   └── post-2.md
├── _index.de.md
└── _index.md

Produces this…

public/
├── de/
│   ├── posts/
│   │   ├── post-1/
│   │   │   └── index.html
│   │   ├── post-2/
│   │   │   └── index.html
│   │   └── index.html
│   ├── index.html
│   └── index.json   <-- JSON data for the de site
├── en/
│   ├── posts/
│   │   ├── post-1/
│   │   │   └── index.html
│   │   ├── post-2/
│   │   │   └── index.html
│   │   └── index.html
│   ├── index.html
│   └── index.json   <-- JSON data for the en site
└── index.html

Thanks for the reply. I now tried with defaultContentLanguageInSubdir = true, but I am still getting a 291 KB index.json for English while the index.json for the other language is 145 KB. The index.json generated for en includes the content from the other language. I don’t want this. Could this be a bug? If so, I can report it.

Can you provide an example site that demonstrates the problem?

I don’t have anything online that would show it, but the source is infra/libreofficeorg - Gitiles so you could clone it, add a language to config.toml, copy the English content to the respective subdir and build.

Your config should look like:

[languages.en]
  languageName = 'English'
  contentDir = 'content/en'
  weight = 1
[languages.de]
  languageName = 'Deutsch'
  contentDir = 'content/de'
  weight = 2

And your content structure should look like:

content/
├── de/
│   ├── headerfooter/
│   ├── _index.md
│   ├── donate.md
│   ├──  ...
│   └── who-are-we.md
└── en/
    ├── headerfooter/
    ├── _index.md
    ├── donate.md
    ├── ...
    └── who-are-we.md

Thanks a lot, I was missing that I needed to put English content source files into content/en!

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