Skip to content

Commit

Permalink
fix chinese words search
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoXuan40404 committed Nov 21, 2024
1 parent 519fc27 commit 93392c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions 3.x/zh_CN/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#sys.path.insert(0, os.path.abspath('..'))
import sphinx_rtd_theme
from recommonmark.transform import AutoStructify
# from pathlib import Path


DOC_SOURCES_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -64,6 +65,15 @@
'myst_parser'
]

myst_enable_extensions = [
"linkify", # 自动转换 URL 为链接
"replacements", # 支持文本替换
# "smartquotes", # 美化引号
# "strikethrough", # 支持删除线
# "substitution", # 支持替换变量
# "attrs_block", # 支持 Markdown 块级属性
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['../_templates']

Expand Down Expand Up @@ -233,6 +243,25 @@
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
#html_search_language = 'en'
html_search_language = 'zh'
# current_dir = Path(__file__).parent.resolve()
# package_path = [p for p in sys.path if 'site-packages' in p][0] # 找到 jieba 的安装路径
# dict_path = Path(package_path) / 'jieba/dict.txt' # jieba 默认词典路径

# custom_dict_path = current_dir / "custom_words.txt" # 自定义词典路径
# if custom_dict_path.exists():
# custom_words = custom_dict_path.read_text(encoding="utf-8").splitlines()
# custom_words = [f"{word} 3 n" for word in custom_words if word.strip()]
# dict_texts = dict_path.read_text(encoding="utf-8").splitlines()
# dict_texts.extend(custom_words)
# dict_path.write_text("\n".join(dict_texts), encoding="utf-8")

# html_search_options = {
# 'dict': str(dict_path),
# 'split_all': True, # 开启全分词模式
# 'minchars': 2, # 最小搜索字符数
# 'maxchars': 10, # 最大搜索字符数
# }


# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ git-lfs
Jinja2<3.1
myst-parser == 0.13.0
pyyaml

jieba
linkify-it-py
markdown-it-py

0 comments on commit 93392c7

Please sign in to comment.