Remove competely accents from URL

Hello guys. I has been struggling with this problem all morning. The problem is. , in Vietnamese, we have also accent for d is “đ”. I’m trying to make my category taxonomy completely slug and without accents

Example : I have an tag call “Đông”. Url expected is “/the/dong”. But some how, when i add tag to my posts. It show /the/đong in url.

removePathAccents = true is not solve the problem. It only remove other accent, but with “đ” is not. So how can i fix this?

It similiar with this bug report

You can’t trust Hugo and its upstream dependencies with these things. It’s probably better to set these parts of the URL by yourself. There are frontmatter options available for that:

Either do it in each post with url or use the slug frontmatter for the folder (if the special character is in the foldername).

What is a character?

…characters can span multiple runes. For example, an e and ◌́ (acute \u0301) can combine to form é (e\u0301 in NFD). Together these two runes are one character.

See https://go.dev/blog/normalization#what-is-a-character-h2

The ◌́ (acute \u0301) rune is a member of the Nonspacing Mark (Mn) unicode category.

Hugo’s removePathAccents setting removes all runes in the Mn category. For example, José becomes Jose.

The character đ is not a combination of the letter d with a non-spacing mark. It is a lower case letter, and will not be affected by the removePathAccents settings.

The same is true with characters such as ł, ƚ, ŧ, and ħ. They may look like a combination of a letter and non-spacing mark, but they are not.

If we wanted to do something like this:

đéłƚŧħß --> dellthss

We would need to incorporate something like iconv.

iconv -c -f utf8 -t ascii//TRANSLIT <<< "đéłƚŧħß"
2 Likes

Yes i tried to change url/slug in tag
Example with tag “Đông”, i change in content/tags/đong/_index.md

title: "Đông"
slug: "/the/dong"

In my post example.md, I’m using front-matter:

title: "Hello world"
the : 
     - Đông

But when i check it again. in mywebsite/the/dong, it give me empty list, not show my “Hello world” post.
What wrong with me

Interesting idea. But how can i use it in Hugo ?

You should use url instead of slug if you use the full path from your website root for the value. in slug it should only be dong without the folder it’s in.

Okay thanks for your help . It working. Now one small slight problem is. The taxonomy of Hugo is generated a link whenever i input a tag into front matter . But with accent like i said above.
So can i use replace in url?. Tried below method but it still not working
Like this:

<div class="tag-container">
    {{ range .Params.tag }}
// replace everytag tag start with "đ" word with "d"
    {{$tag := replace . "đ" "d"}}
    <a href="/tag/{{$tag |urlize }}" class="tag-item--article">#{{.}}</a>
    {{end}}
 
</div>

You can add content files with frontmatter for all your tags (or just some), see " Add custom metadata to a Taxonomy or Term":

You might miss here.
If you look above, i’m trying replace any tag start have an name start with “đ”. Then replace to “d” only.
The metadata part is done. Just added it. Now i’m doing the replace part

Pretty sure I don’t but we have some language issues here :wink:

Let’s assume this is lowercase “dong”:

Đông

You create a file content/tags/dong/_index.md with the following content:

---
title: Đông
slug: dong
---

Then you refer to the tag in your contents frontmatter with:

tags: ["dong", "other", "tags"]

and it will display Đông and link to dong

3 Likes

Thanks you so much. Finally figure how to make it work xD

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