feat(content-docs): expose isCategoryIndex matcher to customize conventions (#6451)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2022-01-27 00:58:52 +08:00 committed by GitHub
parent 76a8d5f38a
commit 24a895fbc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 408 additions and 93 deletions

View file

@ -77,6 +77,12 @@ type PrefixParser = (filename: string) => {
numberPrefix?: number;
};
type CategoryIndexMatcher = (doc: {
fileName: string;
directories: string[];
extension: string;
}) => boolean;
type SidebarGenerator = (generatorArgs: {
item: {type: 'autogenerated'; dirName: string}; // the sidebar item with type "autogenerated"
version: {contentPath: string; versionName: string}; // the current version
@ -88,6 +94,7 @@ type SidebarGenerator = (generatorArgs: {
sidebarPosition?: number | undefined;
}>; // all the docs of that version (unfiltered)
numberPrefixParser: PrefixParser; // numberPrefixParser configured for this plugin
isCategoryIndex: CategoryIndexMatcher; // the default category index matcher, that you can override
defaultSidebarItemsGenerator: SidebarGenerator; // useful to re-use/enhance default sidebar generation logic from Docusaurus
}) => Promise<SidebarItem[]>;
@ -141,6 +148,7 @@ const config = {
item,
version,
docs,
isCategoryIndex,
}) {
// Use the provided data to generate a custom sidebar slice
return [
@ -274,15 +282,15 @@ website/i18n/[locale]/docusaurus-plugin-content-docs
│ # translations for website/docs
├── current
   ├── api
   │   └── config.md
   └── getting-started.md
├── api
└── config.md
└── getting-started.md
├── current.json
│ # translations for website/versioned_docs/version-1.0.0
├── version-1.0.0
   ├── api
   │   └── config.md
   └── getting-started.md
├── api
└── config.md
└── getting-started.md
└── version-1.0.0.json
```