Multilingual site and relative content image links

Hi, everyone!

I’m thinking of moving my site from custom gulp-based solution to Hugo, and have one problem: my posts have this structure:

some-post
├── index.en.md
├── index.ru.md
└── illustration.png

Then, I have one default language: ru, and one extra — en.

In both my .md files I call my image as usual: ![…](illustration.png)

The problem: this image generated from markdown has src="illustration.png", so it works for the unprefixed default language, but not for the one that has a language prefix.

In my custom solution, I handled this in a most straightforward way: just by copying the image for every language generated. Is there a way to do the same in Hugo?

Another solution could be to replace the links at the template level, maybe there is something like that as well? Is it possible to get the behaviour I’m expecting?

The important part is that in the source .md files I totally want to have just a source-relative link, as this way it would be shown by any other markdown viewer/editor (like github).

While I can imagine situations not covered, yours is not one of them.

Have you tested this with the latest Hugo?

1 Like

Hmm, yep, I think I could have an older version of Hugo (from September?), I’ll update it and would reply if that would help, thanks!

Yep, works, and by copying the illustration to both paths, that is awesome!

(sorry, not used to binary tools that you need to update manually, used to having always latest stuff from npm for the new projects)

So far I’m amazed at how Hugo does all the stuff in ways I’m already used to: especially this naming convention for multilang sites, really nice work there!

1 Like

You should also have a look at the image processing feature in Hugo 0.32 – which is going to be improved in Hugo 0.33 with front matter meta data:

http://hugotest.bep.is/section3/2017/11/my-cool-article-1b/

And this is Hugo next:

http://hugotest.bep.is/resourcemeta/bundle-with-resource-meta-yaml/

This also works seamlessly in multilingual mode.

Also a tip: The language naming convention also extends to other resources, images etc.

Hmm, interesting!

Although, I have a question re: how I do my structure with the index files: if I have something like that:

2018-01-04-counters-and-stones
└── index.en.md

Then inside .md I have metadata with slug equal to counters-and-stones.

I have two questions/problems:

  1. The url generated for this article is not that I expect: en/posts/2018-01-04-counters-and-stones/counters-and-stones/, I don’t want to have the initial part with the date and want to have only the slug I have given in metadata. Is there a way to override this?
  2. I have another default language, and there is no translation for it at this directory. But I still get generated posts/2018-01-04-counters-and-stones/counters-and-stones/ url for this article (while articles that are present only for default language are not copied for non-default without translations). While I find it to be a feature rather than a bug, I would probably want to control it: is it an intended behaviour and if yes, then if there is a way to control it using some config or metadata options?

Aha, for the first question I found my own answer: [permalinks] with posts = "/:section/:slug/" seems to do what I want!

Oh! But I’ve noticed another thing that is connected to the second point: while a page is created for my default language, the image is not copied to it, so it is only available for the original version under the en/

And another thing: when I use this method with mmark, the include don’t seem to work: {{lol.html}} when it is placed in the same folder as index.en.md would give an error:

mmark: failed: `lol.html': open lol.html: no such file or directory

From the mmark’s docs:

the filename is taken relative to working directory of the Mmark process

It seems that the working directory for mmark is not the one each document has, but the root of the whole project. I wonder: if there a way to make the working directory to be the source folder of each document in that case?

I don’t know MMark, but I suggest that you post that in another thread, you are drifting from the original topic.