Skip to content

Instantly share code, notes, and snippets.

@1049451037
Forked from chen206/mkdocs-chinese-search.md
Created June 25, 2018 16:00
Show Gist options
  • Save 1049451037/99f08ee256396abd6770b70a594c8086 to your computer and use it in GitHub Desktop.
Save 1049451037/99f08ee256396abd6770b70a594c8086 to your computer and use it in GitHub Desktop.
mkdocs支持中文搜索
  1. 替换支持中文的lunr.min.js文件
  2. 下载 https://github.com/codepiano/lunr.js/blob/37680a339bfec3785e507bb3c07e362cae66ac26/lunr.min.js
  3. 复制到 /usr/local/Cellar/mkdocs/0.16.1_1/libexec/lib/python2.7/site-packages/mkdocs/assets/search/mkdocs/js/
  4. 修改生成索引文件的函数
  5. 找到文件 /usr/local/Cellar/mkdocs/0.16.1_1/libexec/lib/python2.7/site-packages/mkdocs/search.py
  6. 修改函数generate_search_index,在json.dumps中添加一个参数:ensure_ascii=False
    def generate_search_index(self):
        """python to json conversion"""
        page_dicts = {
            'docs': self._entries,
        }
        return json.dumps(page_dicts, sort_keys=True, ensure_ascii=False, indent=4)
@1049451037
Copy link
Author

在Windows下的Python3.5:

  • 第3步中的路径是C:\Users\song\AppData\Local\Programs\Python\Python35\Lib\site-packages\mkdocs\contrib\legacy_search\templates\search
  • 第5步的路径是C:\Users\song\AppData\Local\Programs\Python\Python35\Lib\site-packages\mkdocs\contrib\legacy_search\search_index.py

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