3

At work we have a basic Docusaurus v2 page for user documentation, and I can't share it for privacy reasons. Suffice it to say it has a sidebar which is autogenerated, where the top level contains a number of folders as categories and each category only contains .md files.

At the top level (the level of the categories) there is an empty index.md file that only exists so that the page will load. The autogenerated sidebar includes an index entry that points to a blank page. I would like to hide/get rid of this entry.

I have looked at this github discussion on something similar, but I haven't been able to make the solutions work. The sidebar.js file has the following simple contents:

module.exports = {
  docs: [
    {
      type: 'autogenerated',
      dirName: '.'
    },
  ],
};

I have tried adding an exclude: ['path\to\index\file'] line, but this results in the error "exclude" is not allowed.

What is the proper way of hiding this index entry from the sidebar? Alternatively, is there a way to set up the site so that the index.md file is not needed at all?

William
  • 296
  • 4
  • 14
  • did you manage to find a solution for this? I am facing the same and it kinda drives me nuts :) – ovi Oct 06 '22 at 09:57
  • 1
    @Ovi I'm not sure if it's a "solution" as it doesn't accomplish what I intended, but we ended up just giving the file the title "Introduction" and adding an introductory blurb to it, so that now at least it seems less out-of-place. – William Oct 12 '22 at 20:26
  • hahaha, thank you! I did the same thing as well :) it's a hack but I could not find a better solution – ovi Oct 14 '22 at 11:10
  • From what I can see it looks like this is a planned feature - https://docusaurus.canny.io/feature-requests/p/hiding-parts-of-docs-in-autogenerated-sidebar – Rahul Gupta-Iwasaki Dec 01 '22 at 01:03

1 Answers1

1

I have the same setup:

/folder1
  /file
/folder2
  /file
index

And I wand to autogenerate the sidebar with two categories only:

  • folder1
  • folder2

Moreover, I wanted to click on the navbar and see index.

I was able to do so by:

Create a custom sidebar

function skipIndex(items) {
  return items.filter(({ type, id }) => {
    return type !== 'doc' || id !== 'index';
  });
}

module.exports = async function sidebarItemsGenerator({ defaultSidebarItemsGenerator, ...args }) {
  const sidebarItems = await defaultSidebarItemsGenerator(args);
  return skipIndex(sidebarItems);
}

Then in the docusaurus.config.js

  presets: [
    [
      'classic',
      ({
        // https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#configuration
        docs: {
          sidebarItemsGenerator: require('./sidebar.js'),
        },

And finally in the index.md file I must add this metadata, otherwise when I reach the index page, the sidebar disappears because the page is not included:

---
displayed_sidebar: docsSidebar
---
Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73