llms.txt 1/2
This commit is contained in:
parent
54aef5ec39
commit
e87304508f
@ -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)
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user