Skip to content

Commit 365d954

Browse files
committed
feat: Add relations JSON to llms.txt and per-product sitemaps
- Add Class Relationship Graphs section to main llms.txt explaining the relations JSON format and what data it contains - Add relations JSON, hooks JSON, and llms.txt URLs to each product's sitemap for better discoverability by crawlers and AI agents
1 parent f6551d2 commit 365d954

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

scripts/enhance-for-llms.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,21 @@ ${urlStructureSection}
546546
547547
## Machine-Readable Data
548548
549-
For programmatic access to hook information:
549+
For programmatic access to hook information and code structure:
550550
551-
### Recommended: Per-Product APIs (Smaller Files)
551+
### Class Relationship Graphs (For Code Understanding)
552+
- \`/relations/{product-id}.json\` - Class inheritance, traits, dependencies, and call graphs
553+
554+
These relationship files enable AI assistants to understand codebase architecture without direct code access. Each file contains:
555+
- **extends** - Parent class inheritance
556+
- **implements** - Interface implementations
557+
- **uses** - Trait usage
558+
- **dependencies** - Constructor/method type-hinted dependencies
559+
- **instantiates** - Classes created via \`new\`
560+
- **staticCalls** - Static method calls to other classes
561+
- **usedBy** - Reverse lookup (what uses this class)
562+
563+
### Hooks APIs (For WordPress Integration)
552564
- \`/api/hooks/index.json\` - Product directory with stats (~6KB)
553565
- \`/api/hooks/{product-id}.json\` - Individual product hooks (1KB-408KB each)
554566

src/plugins/product-sitemaps.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,31 @@ export default function productSitemapsPlugin(context, options) {
129129
};
130130
});
131131

132+
// Add machine-readable API files to sitemap
133+
// Relations JSON (class relationships for code understanding)
134+
sitemapItems.push({
135+
url: normalizeUrl([baseUrl, 'relations', `${productId}.json`]),
136+
lastmod: new Date().toISOString().split('T')[0],
137+
changefreq: 'weekly',
138+
priority: 0.8,
139+
});
140+
141+
// Hooks JSON (WordPress hooks API)
142+
sitemapItems.push({
143+
url: normalizeUrl([baseUrl, 'api', 'hooks', `${productId}.json`]),
144+
lastmod: new Date().toISOString().split('T')[0],
145+
changefreq: 'weekly',
146+
priority: 0.8,
147+
});
148+
149+
// Product-specific llms.txt
150+
sitemapItems.push({
151+
url: normalizeUrl([baseUrl, 'docs', productId, 'llms.txt']),
152+
lastmod: new Date().toISOString().split('T')[0],
153+
changefreq: 'weekly',
154+
priority: 0.8,
155+
});
156+
132157
// Generate sitemap XML
133158
const sitemapXML = generateSitemapXML(sitemapItems, productLabel);
134159

0 commit comments

Comments
 (0)