Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does permalink:"{{ title | slugify }}" support multi-byte languages like Japanese? #2537

Closed
bissy opened this issue Aug 18, 2022 · 7 comments
Labels
education feature: 🪨 permalink Related to the `permalink` feature to control where the file’s output is written

Comments

@bissy
Copy link

bissy commented Aug 18, 2022

I set post like below.

こんにちは.md

title: こんにちは
permalink: "/article/{{ title | slugify }}"
---

hello.md

title: hello
permalink: "/article/{{ title | slugify }}"
---

And then, hello.md compiled /article/hello/index.html
but こんにちは.md is compiled /article/index.html.

Is this issue of slugify? or other issue?

@pdehaan
Copy link
Contributor

pdehaan commented Aug 18, 2022

I believe that is Japanese, correct?
Looking at https://www.11ty.dev/docs/filters/slugify/ (which points me to @sindresorhus/slugify), which then points me towards https://github.com/sindresorhus/transliterate#supported-languages as a list of supported languages. And then sindresorhus/transliterate#1 says that there is currently no support for languages like Chinese, Japanese, Thai, etc.

One workaround might be using the page's filename instead of slugifying the title, if that works.

---
title: こんにちは
permalink: "/article/{{ page.fileSlug }}/"
---

<h1>{{ title }}</h1>

UPDATE: Here's my build log:

npm run build

> [email protected] build
> eleventy

[11ty] Writing www/article/こんにちは/index.html from ./src/こんにちは.md (liquid)
[11ty] Wrote 1 file in 0.06 seconds (v1.0.2)

@pdehaan
Copy link
Contributor

pdehaan commented Aug 18, 2022

I also found https://github.com/lovell/limax which seems to support Japanese; if you were looking for translated slugified strings.

// Overwrite the built-in `slugify` filter.
eleventyConfig.addFilter("slugify", require("limax"));

src/こんにちは.md

---
title: こんにちは
permalink: "/article/{{ title | slugify }}/"
---

<h1>{{ title }}</h1>

OUTPUT

> eleventy

[11ty] Writing www/article/konnichiha/index.html from ./src/こんにちは.md (liquid)
[11ty] Wrote 1 file in 0.06 seconds (v1.0.2)

I'm not sure if that's transliterating correctly, but… maybe?

@bissy
Copy link
Author

bissy commented Aug 18, 2022

@pdehaan Thank you sooo much!!

One workaround might be using the page's filename instead of slugifying the title

permalink: "/article/{{ page.fileSlug }}/"

I tried this, and works fine!
Thank you!

@bissy
Copy link
Author

bissy commented Aug 18, 2022

@pdehaan
Now, still I confusing..
I can not use Japanese language tag.
e.g.
tags: ["cat","dog"] => compiled!
tags: ["ねこ","犬"] => failed!

How should I do?

@pdehaan
Copy link
Contributor

pdehaan commented Aug 18, 2022

This seems to work for me in [email protected].

src/こんにちは.md

---
title: こんにちは
permalink: "/article/{{ title | slugify }}/"
tags: ["ねこ","犬"]
---

<h1>{{ title }}</h1>

src/index.md

---
title: multibyte 犬 test
---

<h1>collections['犬']</h1>

{% for p in collections['犬'] %}
title={{ p.data.title }}
{% endfor %}

OUTPUT

<h1>collections['犬']</h1>
<p>title=こんにちは</p>

@bissy
Copy link
Author

bissy commented Aug 19, 2022

@pdehaan

Thank you for your help!

I'm using eleventy-base-blog,
and I found this.
 
In tags.njk, I change code below.
permalink: /tags/{{ tag | slugify }}/

permalink: /tags/{{ tag }}/

And now, "猫" tag is working fine.

@zachleat
Copy link
Member

Pushed some warnings and guidance for this to https://www.11ty.dev/docs/filters/slugify/

Thanks y’all!

@zachleat zachleat added education feature: 🪨 permalink Related to the `permalink` feature to control where the file’s output is written and removed needs-triage labels Aug 22, 2022
zachleat added a commit that referenced this issue Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
education feature: 🪨 permalink Related to the `permalink` feature to control where the file’s output is written
Projects
None yet
Development

No branches or pull requests

3 participants