-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
feat(docusaurus-theme-common): classify Chinese tag into alphabet #7843
Conversation
Hi @MarkShawn2020! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi—sorry, I don't really want to take this. It's a hassle for the team to maintain (despite me being Chinese), and it bloats the bundle size for everybody. You are free to implement this solution in userland through swizzling. Thank you for taking interest in this!
Once we make theme enhancements more ergonomic (tracked in #4530), you can consider publishing this as a community theme.
I tried sizzling but it only provides the ability to customize UI layer, so I do suggest exposing more functional-hooks, just like what the remark/rehype plugin does. |
|
Yep, just abstracting it into a hook, and indeed we really do not care too much which side the code would be running. |
First, thanks for your real-time work yesterday @Josh-Cena . By the way, could you please provide me a best-practice on how to develop and deploy my own site based on docusaurus, when I had to customize some implementations individually? There seems to be two optional solutions for me:
|
Pre-flight checklist
Motivation
The Chinese tags in blog tag list page would be categoried into the first word, e.g.
测
(from测试
), and开
(from开发
), which leads to the problem of managing tags, since there are too many Chinese characters rather than just 26 in English.Research
There are a few of solutions to force the Chinese tag to be categoried into English alphebet, e.g. rearrange the doms on the frontend. But indeed, the best choice is to enhance the prior function of
getTagLetter
inpackages/docusaurus-theme-common/src/utils/tagsUtils.ts
, since it's just where the job works, i.e. converting the input string to be the first letter.Solution
I got one copy of Chinese map (pinyin -> character) from the project of
simple-pinyin
(if it's illegal please tell me since I do not know licence relative well), and transformed into the reversed shape (character -> pinyin), so that we can do one step furtuer (pinyin -> alphebet).I did think about the extensible problem, since it would be costly if we added the otherwise unnecessary step to check whether a tag is Chinese. Hence, I added one parameter of
lang
in order to compat with other potential languages.Result
Notes
packages/docusaurus-theme-common/src/utils/pinyin/src/index.ts
provides the interface to get leading pinyin from a Chinese word, which is integrated withdocusaurus-theme-common
.packages/docusaurus-theme-common/src/utils/pinyin/src/genMap/*
are for generating the target map, which is individual with the main processs.packages/docusaurus-theme-common/src/utils/pinyin/data/pinyin.json
), which covers the majority of tagging scenarios, and it's quite easy to be extended (e.g. 繁體字).Test Plan
Test links
No test links to be shared, except a sample at: https://markshawn2020.github.io/keeps-learning/blog/tags.
And the unit-test is at:
packages/docusaurus-theme-common/src/utils/__tests__/ChineseWord2Pinyin.ts
.Related issues/PRs
None.