diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 26594bc95d..edffdf4e4a 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -976,3 +976,35 @@ describe('site with custom sidebar items generator', () => { expect(version.sidebars).toMatchSnapshot(); }); }); +describe('nested directory exclusion (issue #11607)', () => { + it('excludes nested directories and their contents correctly', async () => { + const siteDir = path.join( + __dirname, + '__fixtures__/site-with-autogenerated-sidebar', + ); + + const context = await loadContext({siteDir}); + + const options = validateOptions({ + validate: normalizePluginOptions as Validate, + options: { + path: 'docs', + // We use the actual folder name '3-API' found in the fixture + exclude: ['3-API'], + }, + }); + + const plugin = await pluginContentDocs(context, options); + const content = await plugin.loadContent!(); + const currentVersion = content.loadedVersions[0]!; + + // This ensures we actually loaded the other docs (Getting Started, etc.) + expect(currentVersion.docs.length).toBeGreaterThan(0); + + // If the bug exists, this will find "API/api-overview" + // and the test will FAIL (because we expect it to be undefined) + const apiDoc = currentVersion.docs.find((doc) => doc.id.includes('API')); + + expect(apiDoc).toBeUndefined(); + }); +}); diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index b8f02ba5b0..0cfd2a93b7 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -68,7 +68,8 @@ export async function readVersionDocs( ): Promise { const sources = await Globby(options.include, { cwd: versionMetadata.contentPath, - ignore: options.exclude, + // THE FIX: Transform simple folder names into recursive glob patterns + ignore: options.exclude.flatMap((pattern) => [pattern, `${pattern}/**`]), }); return Promise.all( sources.map((source) => readDocFile(versionMetadata, source)),