66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
|
|
import fs from 'node:fs';
|
|||
|
|
import path from 'node:path';
|
|||
|
|
|
|||
|
|
import { docs } from '../../src/config/docs.config';
|
|||
|
|
|
|||
|
|
const siteTitle = 'Документация';
|
|||
|
|
const siteDescription = 'Единое пространство для идей, черновиков и первых версий документаций, которые ещё формируются и постепенно становятся самостоятельными материалами.';
|
|||
|
|
|
|||
|
|
const rootDir = process.cwd();
|
|||
|
|
const publicDir = path.join(rootDir, 'public');
|
|||
|
|
const llmsPath = path.join(publicDir, 'llms.txt');
|
|||
|
|
|
|||
|
|
function formatMarkdownLink(label: string, href: string, description: string) {
|
|||
|
|
return `- [${label}](${href}): ${description}`;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function findDocLink(doc: (typeof docs)[number], label: string) {
|
|||
|
|
return doc.links.find((link) => link.label === label);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function formatLlmsLinks() {
|
|||
|
|
return docs
|
|||
|
|
.map((doc) => {
|
|||
|
|
const link = findDocLink(doc, 'llms.txt');
|
|||
|
|
|
|||
|
|
if (!link) return undefined;
|
|||
|
|
|
|||
|
|
return formatMarkdownLink(doc.title, link.href, doc.description);
|
|||
|
|
})
|
|||
|
|
.filter(Boolean);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function formatFullLinks() {
|
|||
|
|
return docs
|
|||
|
|
.map((doc) => {
|
|||
|
|
const link = findDocLink(doc, 'llms-full.txt');
|
|||
|
|
|
|||
|
|
if (!link) return undefined;
|
|||
|
|
|
|||
|
|
return formatMarkdownLink(`${doc.title} full`, link.href, `Полный bundle документации: ${doc.label.toLowerCase()}.`);
|
|||
|
|
})
|
|||
|
|
.filter(Boolean);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const content = [
|
|||
|
|
`# ${siteTitle}`,
|
|||
|
|
'',
|
|||
|
|
`> ${siteDescription}`,
|
|||
|
|
'',
|
|||
|
|
'Этот файл является корневой картой документаций. Для работы с конкретным направлением используйте его собственный `llms.txt`.',
|
|||
|
|
'',
|
|||
|
|
'## Documentation',
|
|||
|
|
'',
|
|||
|
|
...formatLlmsLinks(),
|
|||
|
|
'',
|
|||
|
|
'## Optional',
|
|||
|
|
'',
|
|||
|
|
...formatFullLinks(),
|
|||
|
|
'',
|
|||
|
|
].join('\n');
|
|||
|
|
|
|||
|
|
fs.mkdirSync(publicDir, { recursive: true });
|
|||
|
|
fs.writeFileSync(llmsPath, content, 'utf8');
|
|||
|
|
|
|||
|
|
console.log(`Сгенерирован ${path.relative(rootDir, llmsPath)}`);
|