This commit is contained in:
Kaparthy Reddy 2025-12-25 06:25:32 +00:00 committed by GitHub
commit 0bd8682022
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -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, PluginOptions>,
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();
});
});

View File

@ -68,7 +68,8 @@ export async function readVersionDocs(
): Promise<DocFile[]> {
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)),