From 05ad17407ea25f1d69baac0aae607681dc06c0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Biro=C5=A1?= Date: Tue, 21 Apr 2026 13:43:16 +0200 Subject: [PATCH] Exclude unlisted pages from llms.txt --- __tests__/content-classifier.test.ts | 54 +++++++++++++++++++ .../src/discovery/content-classifier.ts | 5 ++ 2 files changed, 59 insertions(+) create mode 100644 __tests__/content-classifier.test.ts diff --git a/__tests__/content-classifier.test.ts b/__tests__/content-classifier.test.ts new file mode 100644 index 0000000..f478186 --- /dev/null +++ b/__tests__/content-classifier.test.ts @@ -0,0 +1,54 @@ +/// + +jest.mock('../packages/docusaurus-plugin-llms-txt/src/constants', () => ({ + DOCUSAURUS_BLOG_PLUGIN: 'docusaurus-plugin-content-blog', + DOCUSAURUS_PAGES_PLUGIN: 'docusaurus-plugin-content-pages', + CONTENT_TYPES: { + BLOG: 'blog', + PAGES: 'pages', + DOCS: 'docs', + UNKNOWN: 'unknown', + }, +})); + +import { shouldIncludeRoute } from '../packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier'; +import type { IncludeFilterConfig } from '../packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier'; +import type { PluginRouteConfig } from '@docusaurus/types'; + +const baseConfig: IncludeFilterConfig = { + includeDocs: true, + includeVersionedDocs: true, + includeBlog: true, + includePages: true, + includeGeneratedIndex: true, + excludeRoutes: [], +}; + +function makeRoute(overrides: Record = {}): PluginRouteConfig { + return { + path: '/test', + component: '@theme/DocItem', + ...overrides, + } as unknown as PluginRouteConfig; +} + +describe('shouldIncludeRoute', () => { + it('includes a normal doc route', () => { + expect(shouldIncludeRoute(makeRoute(), baseConfig)).toBe(true); + }); + + it('excludes a route with unlisted: true', () => { + const route = makeRoute({ props: { unlisted: true } }); + expect(shouldIncludeRoute(route, baseConfig)).toBe(false); + }); + + it('includes a route with unlisted: false', () => { + const route = makeRoute({ props: { unlisted: false } }); + expect(shouldIncludeRoute(route, baseConfig)).toBe(true); + }); + + it('includes a route with no unlisted prop', () => { + const route = makeRoute({ props: {} }); + expect(shouldIncludeRoute(route, baseConfig)).toBe(true); + }); +}); diff --git a/packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier.ts b/packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier.ts index b0b9c72..c94955b 100644 --- a/packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier.ts +++ b/packages/docusaurus-plugin-llms-txt/src/discovery/content-classifier.ts @@ -137,6 +137,11 @@ export function shouldIncludeRoute( } } + // Skip pages marked as unlisted in frontmatter + if (route.props?.unlisted) { + return false; + } + return true; }