11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://eleventy-base-blog.netlify.app/
MIT License
1.19k stars 609 forks source link

Error reported when tag is in Chinese #169

Open xiyuvi opened 6 months ago

xiyuvi commented 6 months ago

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\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\TemplateMap.js:803:13)
[11ty]     at TemplateMap.cache (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@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\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\TemplateWriter.js:330:5)
[11ty]     at async TemplateWriter.generateTemplates (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\TemplateWriter.js:360:5)
[11ty]     at async TemplateWriter.write (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\TemplateWriter.js:407:23)
[11ty]     at async Eleventy.executeBuild (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\Eleventy.js:1191:13)
[11ty]     at async Eleventy._watch (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\Eleventy.js:822:24)
[11ty]     at async watchRun (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@11ty\eleventy\src\Eleventy.js:1047:9)
[11ty]     at async FSWatcher.<anonymous> (E:\nextblog\node_modules\_@11ty_eleventy@2.0.1@@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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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.