question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autogenerated sidebar items: allow more control on output

See original GitHub issue

🚀 Feature

Several things:

  • Add exclude option in category metadata to filter out docs;
  • Add additionalItems option to include more items in autogenerated categories, including link, ref, etc.;
  • Exclude entire subdirectories when declaring autogenerated sidebar items.

Have you read the Contributing Guidelines on issues?

Yes

Has this been requested on Canny?

No, but there are inline comments asking if they should be allowed, and the answer is yes: I’ve been asked about this feature.

Motivation

Sometimes we want a fully autogenerated sidebar, but occasionally want to add a few external links in categories. Sometimes we have a legacy directory structure and we only want to generate the sidebar from part of that directory.

API Design

In _category_.json, add the following options:

type CategoryMetadatasFile = {
  label?: string;
  position?: number;
  collapsed?: boolean;
  collapsible?: boolean;
  className?: string;
+ additionalItems?: WithPosition<SidebarItem>[];
+ exclude?: {
+   paths: string[];
+   docIDs?: string[];
+ };
};

paths accepts folder paths (I don’t know if file paths would work well; from my experience with the autogenerator code, seems it’s not easy since the doc metadata only includes sourceDir?), while docIDs accepts… doc IDs. It’s assumed that the members in these two arrays are otherwise included in the category; if they are never included (non-existent IDs/paths not in the autogen dir…), maybe throw an error, or maybe do nothing.

additionalItems accepts doc, ref, link, and even category, but not autogenerated (at least I think it doesn’t make much sense, and opens up holes to infinite recursion). Because doc items already come with their own sidebarPosition, they will be sorted well with the rest of the items. However, all items can have an additional sidebarPosition attribute (hence WithPosition<SidebarItem>) to override this behavior.

The autogenerated sidebar item will also accept the exclude and additionalItems properties, because the metadata file in the autogen dir root is not read.

Have you tried building it?

No

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
slorbercommented, Jan 20, 2022

@lorenzolewis that looks like a similar case to https://github.com/facebook/docusaurus/pull/5830#issuecomment-1017146250 (except your doc is named index)

You should be able to do something like:

[
  {
    type: "category",
    label: "JS",
    link: {
      type: "doc",
      id: "index"
    },
    items: [
      {
        type: "autogenerated",
        dirName: "js",
        exclude: ["index"]
      }
    ]
  }
];

Eventually, we could figure a way to exclude it automatically, as it looks like a convenient default

We could also allow an include option so that you can generate the sidebar slice one level upper:

[
  {
    type: "autogenerated",
    dirName: ".",
    include: ["js"]
  }
];

Does it make sense?

2reactions
azinitcommented, Sep 24, 2022

Still actual!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autogenerated - Docusaurus
Docusaurus can create a sidebar automatically from your filesystem structure: each folder creates a sidebar category, and each file creates ...
Read more >
Can Docusaurus read all files in a folder? - Stack Overflow
Docusaurus can create a sidebar automatically from your filesystem structure: each folder creates a sidebar category. An autogenerated item is ...
Read more >
Doc-only mode, versioning, sidebar, add new doc ... - YouTube
Introduction on how to edit the documentation section. Create a document, enable documentation-only mode, edit and modify the sidebar, ...
Read more >
VS Code tips — The side panel - YouTube
Want your outline or source control view to always be visible in VS Code? Try moving it to the side panel ! …...
Read more >
Auto-Increment Number Field in a SharePoint List
What you will see when you do this is that it wraps itself in an apply to each control. It does this because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found