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

Error reported when tag is in Chinese #169

Closed
xiyuvi opened this issue Jan 12, 2024 · 5 comments
Closed

Error reported when tag is in Chinese #169

xiyuvi opened this issue Jan 12, 2024 · 5 comments

Comments

@xiyuvi
Copy link

xiyuvi commented Jan 12, 2024

md

---
title: test
description: test
date: 2023-12-03
tags:
  - 测试
---
测试

Error content

[11ty] File changed: content\blog\33.md
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] Output conflict: multiple input files are writing to `_site/tags/index.html`. Use distinct `permalink` values to resolve this conflict.
[11ty]   1. ./content/tags.njk
[11ty]   2. ./content/tags-list.njk (via DuplicatePermalinkOutputError)
[11ty]
[11ty] Original error stack trace: (Repeated output has been truncated…)
[11ty]     at TemplateMap.checkForDuplicatePermalinks (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\TemplateMap.js:803:13)
[11ty]     at TemplateMap.cache (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\TemplateMap.js:488:10)
[11ty]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[11ty]     at async TemplateWriter._createTemplateMap (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\TemplateWriter.js:330:5)
[11ty]     at async TemplateWriter.generateTemplates (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\TemplateWriter.js:360:5)
[11ty]     at async TemplateWriter.write (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\TemplateWriter.js:407:23)
[11ty]     at async Eleventy.executeBuild (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\Eleventy.js:1191:13)
[11ty]     at async Eleventy._watch (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\Eleventy.js:822:24)
[11ty]     at async watchRun (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\Eleventy.js:1047:9)
[11ty]     at async FSWatcher.<anonymous> (E:\nextblog\node_modules\_@[email protected]@@11ty\eleventy\src\Eleventy.js:1065:7)
[11ty] Benchmark     30ms  15%    20× (Configuration) "slugify" Nunjucks Filter
[11ty] Benchmark     22ms  11%    12× (Configuration) "transformWithHtmlBase" Nunjucks Async Filter
[11ty] Wrote 0 files in 0.20 seconds (v2.0.1)
@Aankhen
Copy link

Aankhen commented Jan 12, 2024

My guess is that you’re using slugify on the permalink for the tag’s individual page, which drops the Chinese characters (sindresorhus/slugify#63), and what’s left is just /tags/. I’m not sure what the solution is here, because the tag name doesn’t have anything in it that slugify knows how to handle. What would you ideally like its URL to look like?

@xiyuvi
Copy link
Author

xiyuvi commented Jan 12, 2024

I used Chinese TGA in the article.
The URL I expect is like this https://xiyu.pro/tags/%E6%94%BB%E5%87%BB/
It is displayed in Chinese in my address bar. If your system does not have a Chinese font library, it may be displayed as the default content https://xiyu.pro/tags/攻击/
image
Thank you for your reply. God bless you

My guess is that you’re using slugify on the permalink for the tag’s individual page, which drops the Chinese characters (sindresorhus/slugify#63), and what’s left is just /tags/. I’m not sure what the solution is here, because the tag name doesn’t have anything in it that slugify knows how to handle. What would you ideally like its URL to look like?

@xiyuvi
Copy link
Author

xiyuvi commented Jan 12, 2024

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeuricomponent
I have solved this problem, and the URL does not need to be formatted at all because the URL already supports Chinese, Japanese, Thai, spaces, and so on. It is an element based log that uses slugify to beautify the URL. However, slugify does not support Chinese, which leads to this problem.

I deleted slugify and successfully resolved this issue.
original

permalink: /tags/{{ tag | encode }}/

now

permalink: /tags/{{ tag }}/

And the official example's tga "second tag" containing spaces did not report an error, and the URL changed to http://localhost:8080/tags/second%20tag/

I personally think that slugify should not be used by default, as this way the webpage can be displayed normally

@Aankhen
Copy link

Aankhen commented Jan 12, 2024

I’m glad you found a solution! I don’t think Eleventy uses slugify on its own. There’s in fact a warning on the appropriate docs page:

slugify currently ignores characters for Japanese, Chinese, and others. If you need to slugify these characters, add your own universal filter with an alternative library like limax or transliteration. (More context at Issue #2537)

In case you still want to create friendlier versions of your URLs, you could look at those libraries. The aforementioned 11ty/eleventy#2537 seems to have concluded with the same approach you’ve switched to, though.

@zachleat
Copy link
Member

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants