Skip to content

feat(customization): sidenav components / skip title update #4630

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Tynopia
Copy link

@Tynopia Tynopia commented Mar 18, 2025

Description

Hi, we've added the following features to VitePress:

  • Custom side navigation components, allowing for greater flexibility in modifying passed content. This is achieved by overriding the component within enhanceApp.

  • A boolean flag in themeConfig, enabling users to bypass the original title update logic. This provides more control over how titles are handled within the theme.

@Tynopia
Copy link
Author

Tynopia commented Mar 19, 2025

Ready for review

@brc-dd
Copy link
Member

brc-dd commented Mar 21, 2025

A boolean flag in themeConfig, enabling users to bypass the original title update logic. This provides more control over how titles are handled within the theme.

It should be outside themeConfig. DefaultTheme.Config is only for default-theme stuff. This option will impact people using other themes too.

  • How will you use this flag? I see that you want to render dynamic things in document.title. How exactly though?
  • The kind of usage in Page title is not interpolated inside <title> element #4640, is not exactly recommended because it will generate weird heading ids.
  • Might be better to split this into different PRs.
  • Not sure if we should go down this road of global components for patching internal stuff. It feels bit hacky. And if we merge this then there will be demand for adding more global components. Making every span in the theme customizable and ensuring they don't change between minor releases is very hard to maintain.

@Tynopia
Copy link
Author

Tynopia commented Mar 21, 2025

Hi,

  1. I've created a new branch with the approach that would be perfect for us: Tynopia@49850c3

    The reason I didn’t want to suggest using the compile function directly here is that, in our case, for example, we need to use the useI18n function for translations, e.g.:

    h(compile(...), { $t: i18n.t })

    This can have custom needs, so a generic approach might be difficult. Additionally, the render(...) function, specifically createVNode does not have access to the current instance (this), unlike the other two components. Since this is empty, it doesn't have direct access to $t, so I have to manually define $t like i did before.

    I also realized that we don’t need the skipTitleUpdate flag because using the watchEffect function automatically overrides the title from the old logic. So this can be removed as well.

  2. What exactly do you mean?

  3. Sure, I can do that. Please also provide feedback on whether we should adopt a generic way of using the compile function. If so, I would appreciate any help regarding the this instance issue I mentioned earlier.

  4. I understand this, but currently, it’s impossible to use such features. In some cases, it is really difficult or maybe even impossible to migrate from MkDocs to VitePress because using variables in the title, sidebar, etc., was a common practice in MkDocs.

    So we need to find a solution that is flexible enough to allow custom functions, like the $t function from vue-i18n.

@Tynopia
Copy link
Author

Tynopia commented Mar 21, 2025

So in the sidenav and local search components, we can use compile with the current this instance without any issues. However, to get it running, I had to use compile from vue/dist/vue.esm-bundler.js, which may not be possible for other runtimes.

That’s also why developers should have the opportunity to use it based on their specific needs.

@Tynopia
Copy link
Author

Tynopia commented Mar 26, 2025

@brc-dd Any new infos here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants