jooy2/vitepress-sidebar

Enhancement: convertSameNameSubFileToGroupIndexPage but for index.md files

Closed this issue · 5 comments

It would be great to have the option to get links to folders when there is an index.md (.html) file, not just a file of the same name as the folder!

jooy2 commented

Hello, Thanks for the great feedback. I think this is an important feature for vitepress-sidebar.

The following two options were recently added in version 1.10.0:

  • includeFolderIndexFile: If an index.md file exists in each folder, include it in the sidebar menu.
  • useFolderLinkAsIndexPage: A link to the index.md file will be added to each folder.

However, the useFolderLinkAsIndexPage option adds the file as a link even if it doesn't exist, so if you want to use this option, you'll need to check each folder for an index.md file, otherwise it may return a 404.

Thanks!

Excellent, thank you! I haven't had a chance to try it yet, but I will soon!

Hi, I'm not sure I understand how this works. I've added index.md files to all my folders. This is my config:

		sidebar: generateSidebar({
				collapseDepth: 2,
				capitalizeFirst: true,
				useTitleFromFrontmatter: true,
				includeFolderIndexFile: true,				
				useFolderLinkAsIndexPage: true,
				excludeFolders: ['node_modules', 'publications']
			}),

But I'm not seeing links to the folders, and the index.md files show up in the list with the other files. See here the output for part of my tree:

          {
            text: '2023',
            items: [
              {
                text: 'Course on Data Vis Fundamentals and Best Practices',
                link: '/blog/2023/course-on-data-vis-fundamentals-and-best-practices'
              },
              { text: 'Index', link: '/blog/2023/index' },
              {
                text: 'New video: Exploring the connections between companies with They Rule',
                link: '/blog/2023/new-video-exploring-the-connections-between-companies-with-they-rule'
              },
              {
                text: 'Paper: Notebooks for Data Analysis and Visualization',
                link: '/blog/2023/paper-notebooks-for-data-analysis-and-visualization'
              },
              {
                text: 'Rainbow Colormaps Are Not All Bad (Paper)',
                link: '/blog/2023/rainbow-colormaps-are-not-all-bad-paper'
              }
            ],

Is there something else I need to do to get this working?

jooy2 commented

The includeFolderIndexFile option is responsible for including the index.md file in the sidebar menu if it exists in the folder, and has nothing to do with linking to the folder, so use it only if necessary.
(This influenced the following parts of your answer: { text: 'Index', link: '/blog/2023/index' },)

The useFolderLinkAsIndexPage option creates a link for all groups (except the root group) to go directly to their page, even if the index.md file doesn't actually exist.

From the output in your answer, it appears that this option did not work. If this is normal behavior, you should see text: '2023', and at the bottom of the line, link: '/blog/2023/index'.

Could you please double check that the current version of vitepress-sidebar is 1.10.0 and that the link does not appear in the 2023 folder even when run without the includeFolderIndexFile option?

Regards,

Hi, sorry I should have responded here sooner! This works as expected. I think I confused myself by upgrading the package but not re-starting my dev server (so it was still running the old code).

Thanks again! Closing this now.