Skip to content
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

configure locals > themeConfig.search , it can't work #3141

Closed
4 tasks done
vanchKong opened this issue Oct 26, 2023 · 7 comments
Closed
4 tasks done

configure locals > themeConfig.search , it can't work #3141

vanchKong opened this issue Oct 26, 2023 · 7 comments
Labels

Comments

@vanchKong
Copy link
Contributor

vanchKong commented Oct 26, 2023

Describe the bug

https://github.com/vanchKong/vitepress/tree/doc-zh

temporary modify docs/locals/en.ts & docs/locals/zh.ts > themeConfig.search to

search: {
  provider: 'local'
},

run vitepress dev docs, search can't work successfully

Reproduction

https://github.com/vanchKong/vitepress/tree/doc-zh

Expected behavior

  • configure locals > themeConfig.search , and it could work
  • In addition, markdown.container should be supported in multi-language configurations

System Info

System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 485.97 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.1.0 - /usr/local/bin/npm
    pnpm: 8.2.0 - /usr/local/bin/pnpm
  Browsers:
    Safari: 16.6
  vitepress: 1.0.0-rc.24

Additional context

No response

Validations

@vanchKong vanchKong added the bug: pending triage Maybe a bug, waiting for confirmation label Oct 26, 2023
@zonemeen
Copy link
Collaborator

你好,现有版本关于搜索的配置你应该在 themeConfig 里边设置,别设在 locales 里,不然搜索框整体都会被隐藏的

@zonemeen zonemeen removed the bug: pending triage Maybe a bug, waiting for confirmation label Oct 28, 2023
@vanchKong
Copy link
Contributor Author

你好,现有版本关于搜索的配置你应该在 themeConfig 里边设置,别设在 locales 里,不然搜索框整体都会被隐藏的

了解了。所以是这样:配置了多语言的情况下,使用 themeConfig.search.options._render 来做到区分语言搜索吗?未来会有进一步的分别配置的支持吗?
另外,markdown.container 在多语言的配置中应该得到支持

@zonemeen
Copy link
Collaborator

了解了。所以是这样:配置了多语言的情况下,使用 themeConfig.search.options._render 来做到区分语言搜索吗?未来会有进一步的分别配置的支持吗? 另外,markdown.container 在多语言的配置中应该得到支持

local 搜索是在这里进行区分的:

(await searchIndexData.value[localeIndex.value]?.())?.default,

然后 algolia 是在这里:

...props.algolia.locales?.[localeIndex.value]

进一步的分别配置在正式版1.0出来之前应该都不太会支持,当然可以期待一下另外一个 issue 提到的i18n解决方案

你指的 markdown.container 是指的这个吗?

@vanchKong
Copy link
Contributor Author

你指的 markdown.container 是指的这个吗?

是的,就是这个

@awxiaoxian2020
Copy link
Collaborator

@vanchKong I think we should post it in English to engage with others.

@vanchKong vanchKong changed the title 在多语言配置 locals 下,配置 themeConfig.search,无法正常工作 configure locals > themeConfig.search, it can't work Oct 29, 2023
@vanchKong vanchKong changed the title configure locals > themeConfig.search, it can't work configure locals > themeConfig.search , it can't work Oct 29, 2023
@brc-dd
Copy link
Member

brc-dd commented Oct 29, 2023

markdown.container support can be a bit tricky as we'll have to somehow get the current locale in the markdown renderer. I'll see what we can do.

Regarding search I believe the recommended approach is https://vitepress.dev/reference/default-theme-search#local-search-i18n (it should be in top-level config, same for algolia too). Regarding _render function, we probably can pass the locale as env.locale (this logic would probably be shared between that container titles thing and this _render function).

In the meantime you can do something like:

_render(src, env, md) {
  if (env.relativePath.startsWith('/zh/') {
    ...
  }
}

@brc-dd
Copy link
Member

brc-dd commented May 3, 2024

_render thing is not needed actually. Local search appear to handle filtering based on current language automatically 👀 One just would need to do https://vitepress.dev/reference/default-theme-search#local-search-i18n to customize labels, etc. rest of the things work out of the box. I'll split out container thing into separate issue.

@brc-dd brc-dd closed this as completed May 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants