Skip to content

Commit c5f40ca

Browse files
zackkatzclaude
andcommitted
fix: create llms.txt if it doesn't exist during CI/CD
The script only updated llms.txt if it existed, but since the file is gitignored, it didn't exist during GitHub Actions runs. Now the script creates the file from a template if it doesn't exist. This fixes the 404 error at https://www.gravitykit.dev/llms.txt 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b11bf5f commit c5f40ca

File tree

1 file changed

+92
-9
lines changed

1 file changed

+92
-9
lines changed

scripts/enhance-for-llms.mjs

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,15 @@ async function main() {
436436
fs.writeFileSync(compactJsonPath, JSON.stringify(compactHooks));
437437
log(` Created: static/api/hooks-compact.json`, colors.green);
438438

439-
// Step 4: Update llms.txt with stats
440-
log('\n▶ Updating llms.txt...', colors.cyan);
439+
// Step 4: Create or update llms.txt with stats
440+
log('\n▶ Creating/Updating llms.txt...', colors.cyan);
441441
const llmsPath = path.join(PROJECT_ROOT, 'static', 'llms.txt');
442-
if (fs.existsSync(llmsPath)) {
443-
let llmsContent = fs.readFileSync(llmsPath, 'utf8');
444442

445-
// Add/update stats section
446-
const statsSection = `
447-
## Statistics (Auto-Updated)
443+
// Generate the product IDs list
444+
const productIds = Object.keys(hooksData.products).join(', ');
445+
446+
// Stats section that gets updated each time
447+
const statsSection = `## Statistics (Auto-Updated)
448448
449449
- **Total Hooks:** ${hooksData.stats.totalHooks}
450450
- **Actions:** ${hooksData.stats.totalActions}
@@ -453,6 +453,85 @@ async function main() {
453453
- **Last Updated:** ${new Date().toISOString().split('T')[0]}
454454
`;
455455

456+
// Full template for llms.txt - used when file doesn't exist
457+
const llmsTemplate = `# GravityKit Developer Documentation
458+
459+
> GravityKit builds WordPress plugins that extend Gravity Forms. This documentation covers all hooks (actions and filters) available for developers.
460+
461+
## About This Documentation
462+
463+
This site documents WordPress hooks (actions and filters) for GravityKit products. Use this documentation to:
464+
- Customize GravityKit plugin behavior
465+
- Integrate with GravityKit products
466+
- Build extensions and add-ons
467+
- Modify default functionality
468+
469+
## Products Documented
470+
471+
- **GravityView** - Display Gravity Forms entries in customizable Views (tables, lists, maps, DataTables)
472+
- **GravityCalendar** - Display entries as calendar events
473+
- **GravityCharts** - Visualize form data with charts
474+
- **GravityImport** - Import CSV/Excel data into Gravity Forms
475+
- **GravityExport** - Export entries to CSV, Excel, PDF
476+
- **GravityEdit** - Frontend entry editing
477+
- **GravityMath** - Calculations and math operations
478+
- **GravityActions** - Bulk actions and workflows
479+
- **GravityRevisions** - Entry revision history
480+
481+
Plus 20+ additional products and extensions.
482+
483+
## URL Structure
484+
485+
Documentation follows this pattern:
486+
- \`/docs/{product}/\` - Product overview
487+
- \`/docs/{product}/actions/\` - All actions for product
488+
- \`/docs/{product}/filters/\` - All filters for product
489+
- \`/docs/{product}/actions/{hook-name}/\` - Individual action documentation
490+
- \`/docs/{product}/filters/{hook-name}/\` - Individual filter documentation
491+
492+
## Machine-Readable Data
493+
494+
For programmatic access to hook information:
495+
496+
### Recommended: Per-Product APIs (Smaller Files)
497+
- \`/api/hooks/index.json\` - Product directory with stats (~6KB)
498+
- \`/api/hooks/{product-id}.json\` - Individual product hooks (1KB-408KB each)
499+
500+
Example workflow:
501+
1. Fetch \`/api/hooks/index.json\` to discover available products
502+
2. Fetch \`/api/hooks/gravityview.json\` for GravityView hooks only (408KB)
503+
3. Fetch \`/api/hooks/gravityedit.json\` for GravityEdit hooks only (21KB)
504+
505+
### Full Database (Large - 728KB)
506+
- \`/api/hooks.json\` - All ${hooksData.stats.totalHooks} hooks in one file
507+
- \`/api/hooks-compact.json\` - Minimal format for quick searches
508+
509+
### Product IDs
510+
${productIds}
511+
512+
## Related Resources
513+
514+
- Main documentation: https://docs.gravitykit.com
515+
- Support: https://www.gravitykit.com/support/
516+
- GitHub: https://github.com/GravityKit
517+
518+
## For AI Assistants
519+
520+
When helping developers with GravityKit:
521+
1. Check the specific product's hooks section
522+
2. Look for filters to modify data, actions for side effects
523+
3. Note the hook's parameters and their types
524+
4. Include the full hook name with any dynamic portions (e.g., \`{field_type}\`)
525+
5. Check related hooks for comprehensive solutions
526+
527+
${statsSection}`;
528+
529+
let llmsContent;
530+
531+
if (fs.existsSync(llmsPath)) {
532+
// File exists - update the stats section
533+
llmsContent = fs.readFileSync(llmsPath, 'utf8');
534+
456535
// Replace or append stats
457536
if (llmsContent.includes('## Statistics (Auto-Updated)')) {
458537
llmsContent = llmsContent.replace(
@@ -462,11 +541,15 @@ async function main() {
462541
} else {
463542
llmsContent += '\n' + statsSection;
464543
}
465-
466-
fs.writeFileSync(llmsPath, llmsContent);
467544
log(` Updated: static/llms.txt`, colors.green);
545+
} else {
546+
// File doesn't exist - create it from template
547+
llmsContent = llmsTemplate;
548+
log(` Created: static/llms.txt`, colors.green);
468549
}
469550

551+
fs.writeFileSync(llmsPath, llmsContent);
552+
470553
// Summary
471554
log('\n✅ LLM Enhancement Complete!\n', colors.bright + colors.green);
472555
log('Files created/updated:', colors.yellow);

0 commit comments

Comments
 (0)