jooy2 / vitepress-sidebar

🔌 VitePress Sidebar is a plugin for VitePress that automatically configures and manages the sidebar of your page with simple settings.
https://vitepress-sidebar.cdget.com
MIT License
144 stars 7 forks source link

How to includeRootIndexFile but rename index file to another name? #158

Closed Jackiexiao closed 3 months ago

Jackiexiao commented 3 months ago

Hello! Appreciation is extended for the creation of this excellent plugin!

I am curious as to how to incorporate the includeRootIndexFile while rechristening the index file to an alternative name?

The 'useTitleFromFileHeading' appears to have an impact on all other files, and it also conflicts with the'removePrefixAfterOrdering' setting.

jooy2 commented 3 months ago

Hello! Thank you for using vitepress-sidebar and for supporting the project!

You can utilize the Frontmatter syntax and the useTitleFromFrontmatter option to set the index file to any name you want.

The advantage of this option is that it can be applied only to the specific file you want, unlike the useTitleFromFileHeading option, which is done for the entire file.

For example, in the index.md file, fill in Frontmatter's title field like this:

---
title: The title that appears in the menu
---

# The title that displayed in article content (but not in the menu)

The parts of the vitepress-sidebar that need to be set up are:

export default defineConfig({
  themeConfig: {
    sidebar: generateSidebar({
      includeRootIndexFile: true, // If you don't want to display the index file, clear this option or leave it `false`.
      useTitleFromFrontmatter: true
    }),
  }
});

Result:

image

If this doesn't solve your problem, or doesn't meet your needs, please leave a reply.

Regards,

Jackiexiao commented 3 months ago

thx!!!!! It works!

Jackiexiao commented 3 months ago

This is my final configuration for reference.

collapsed: true,
collapseDepth: 2,
includeRootIndexFile: true,
useTitleFromFrontmatter: true,
sortMenusOrderNumericallyFromTitle: true,
prefixSeparator: '.',
removePrefixAfterOrdering: true,

In index.md

--- 
title: 1.xxx
---

and docs/ looks like

index.md
2.xxx.md
3.xxx.md

It can ensure that index.md is in the first position. And it ensures that all other files are sorted according to the number at the beginning, and the number prefix is removed when finally displayed.

jooy2 commented 3 months ago

Thanks for sharing your workaround, i'm glad to hear it worked for you!