跳到主要内容
版本:0.17.0+

feat(theme-common): added interface for locale char mapping

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests .
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

In order to solve the problem of classifying non-eng blog tags mentioned in #7843 , considering about the efficiency and extensibility, I finally managed to add an interface naming charMap in I18nLocaleConfig which is integrated with the current API nicely.

The work of updating documentation is also acceptable if this PR could be accepted.

Demo

In order to use this new API, we need to provide the initial charMap in our app level manually. Here is a demo for someone need:

// docusaurus.config.js

// the charMap you can easily find at e.g. https://github.com/guoyunhe/pinyin-json/blob/master/hanzi-pinyin-table.json
// attention to our interface is `one char --> one string` (so you need to convert `string[]` to `string` manually if you use the above data)
/** @type {import("@docusaurus/types/src/i18n").CharMap} */
const charMap = {
: 'ce',
: 'shi',
};

/** @type {import('@docusaurus/types').Config} */
module.exports = {
i18n: {
defaultLocale: 'zh-Hans',
locales: ['zh-Hans'],
localeConfigs: {
'zh-Hans': {
charMap,
},
},
},
};

Then you can got the ideal effect when you open your blog tags page at: http://localhost:3000/blog/tags

image
  • #7843