reuixiy / hugo-theme-meme

😝 You can’t spell awesome without MemE!
https://io-oi.me/hugo-theme-meme
MIT License
1.01k stars 279 forks source link

Hope the Chinese search support #222

Open TenTu0121 opened 4 years ago

TenTu0121 commented 4 years ago

希望能有中文搜索支持。

reuixiy commented 4 years ago

暂不支持的原因见 #165

sosiristseng commented 3 years ago

FYI, fuse.js supports Chinese. An example could be found in this Hugo partial theme.

TenTu0121 commented 3 years ago

Thinks.

swang-harbin commented 2 years ago

lunr-languages 现在支持中文了,使用的是 nodejieba,我在 blog/layouts/partials/third-party/lunr-search.html 文件中将 lunr-language 的版本进行了更新:

{{- $scripts := slice "https://cdn.jsdelivr.net/npm/lunr@2.3.9/lunr.min.js" -}}
{{- if ne .Site.Language.Lang "en" -}}
    {{- $supported := slice "ar" "da" "de" "du" "es" "fi" "fr" "hu" "it" "ja" "nl" "no" "pt" "ro" "ru" "sv" "tr" "vi" "zh"  -}}
    {{- if in $supported .Site.Language.Lang -}}
        {{- if eq .Site.Language.Lang "ja" -}}
            {{- $scripts = union $scripts (slice "https://cdn.jsdelivr.net/npm/lunr-languages@1.9.0/tinyseg.js") -}}
        {{- end -}}
        {{- $scripts = union $scripts (slice "https://cdn.jsdelivr.net/npm/lunr-languages@1.9.0/min/lunr.stemmer.support.min.js") -}}
        {{- $scripts = union $scripts (slice (printf "https://cdn.jsdelivr.net/npm/lunr-languages@1.9.0/min/lunr.%s.min.js" .Site.Language.Lang)) -}}
    {{- else -}}
        {{- warnf "The site language %q isn't supported by lunr, the search results might be suboptimal. Supported languages are: %q" .Site.Language.Lang $supported -}}
    {{- end -}}
{{- end -}}

{{- $scripts = union $scripts (slice "js/lunr-search.js") -}}
{{- return $scripts -}}

但是搜索时报错:

Uncaught TypeError: Cannot read property 'cut' of undefined
    at e.Builder.r.zh.tokenizer (lunr.zh.min.js:1)
    at e.Builder.add (lunr.min.js:6)
    at e.Builder.<anonymous> (meme.min.111eed27d8910a11822d3084ae2d0a86388b9ccd9024cd2fd6216233c4eb8818.js:1)
    at e (lunr.min.js:6)
    at XMLHttpRequest.<anonymous> (meme.min.111eed27d8910a11822d3084ae2d0a86388b9ccd9024cd2fd6216233c4eb8818.js:1)

找不到 nodejieba 的 cut 方法,请问有什么解决办法吗?

StudentWeis commented 1 year ago

同求,现在有很多解决方案啦。