llms.txt 1/2

This commit is contained in:
babayaga 2025-12-29 10:47:45 +01:00
parent 54aef5ec39
commit e87304508f
2 changed files with 71 additions and 0 deletions

View File

@ -245,6 +245,18 @@ export function loader(branch: string): Loader {
generateDigest
} as any)
// Emit to LLM Registry
try {
const { LLMRegistry } = await import('../registry.js')
LLMRegistry.add("Products and Components", {
title: data.title,
url: `/products/${data.slug}`,
description: storeItem.data.description || ""
})
} catch (e) {
// console.error("Failed to emit to LLM Registry", e)
}
storeItem.data['config'] = JSON.stringify({
...storeItem.data
}, null, 2)

View File

@ -152,3 +152,62 @@ class PolymechRegistry {
export const PolymechInstance = PolymechRegistry.getInstance();
export type { PolymechConfig };
import * as fs from 'node:fs';
import * as path from 'node:path';
// LLM Registry for aggregating content
export interface LLMItem {
title: string;
url: string;
description: string;
}
const getCachePath = () => {
const cacheDir = path.join(process.cwd(), 'node_modules', '.cache');
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir, { recursive: true });
}
return path.join(cacheDir, 'llms_registry.json');
}
export class LLMRegistry {
static add(section: string, item: LLMItem) {
const file = getCachePath();
let data: Record<string, LLMItem[]> = {};
try {
if (fs.existsSync(file)) {
data = JSON.parse(fs.readFileSync(file, 'utf-8'));
}
} catch (e) {
// ignore errors
}
if (!data[section]) {
data[section] = [];
}
if (!data[section].some(i => i.url === item.url)) {
data[section].push(item);
fs.writeFileSync(file, JSON.stringify(data, null, 2));
}
}
static getAll(): Map<string, LLMItem[]> {
const file = getCachePath();
const map = new Map<string, LLMItem[]>();
try {
if (fs.existsSync(file)) {
const data = JSON.parse(fs.readFileSync(file, 'utf-8'));
for (const [key, value] of Object.entries(data)) {
map.set(key, value as LLMItem[]);
}
}
} catch (e) {
// ignore
}
return map;
}
}