fix: устранить проблемы доступности llms.txt для AI-агентов
All checks were successful
CI/CD Pipeline / docker (push) Successful in 51s
CI/CD Pipeline / deploy (push) Successful in 8s

- Caddyfile: text/plain применяется только к существующим .txt/.md
- Caddyfile: несуществующие .txt/.md отдают 404 вместо HTML-фолбэка
- Caddyfile: добавлены редиректы /docs/llms*.txt → /llms*.txt
- Caddyfile: добавлен HTTP-заголовок Link с rel="llms" (RFC 8288)
- лендинг: относительные ссылки на llms.txt заменены на абсолютные
- лендинг: добавлено явное упоминание путей в тексте карточки
- config: добавлены <link rel="alternate"> на llms.txt в <head>
- generate-llms: добавлена генерация robots.txt и sitemap.xml
This commit is contained in:
2026-04-27 09:37:23 +03:00
parent 781efc52f1
commit e265799c26
4 changed files with 103 additions and 7 deletions

View File

@@ -14,6 +14,9 @@ const PUBLIC_DIR = 'docs/public';
/** Префикс URL документации. Соответствует структуре `docs/docs/...`. */
const DOC_PREFIX = '/docs/';
/** Канонический хост сайта (для sitemap/robots). Можно переопределить через ENV. */
const SITE_URL = (process.env.SITE_URL || 'https://nextjs-style-guide.gromlab.ru').replace(/\/$/, '');
interface SidebarItem {
text: string;
link?: string;
@@ -488,6 +491,63 @@ const writeManifest = (): void => {
console.log(`${PUBLIC_DIR}/manifest.json создан`);
};
/**
* Сгенерировать `robots.txt` с указанием sitemap и явными ссылками
* на llms.txt/llms-full.txt — стандартные файлы, которые читают агенты.
*/
const buildRobots = (): void => {
const lines = [
'User-agent: *',
'Allow: /',
'',
`Sitemap: ${SITE_URL}/sitemap.xml`,
'',
'# Карта документации для AI-агентов:',
`# ${SITE_URL}/llms.txt`,
`# ${SITE_URL}/llms-full.txt`,
'',
];
fs.mkdirSync(PUBLIC_DIR, { recursive: true });
fs.writeFileSync(path.join(PUBLIC_DIR, 'robots.txt'), lines.join('\n'), 'utf8');
console.log(`${PUBLIC_DIR}/robots.txt создан`);
};
/**
* Сгенерировать `sitemap.xml` из sidebar + корневые ресурсы для LLM
* (llms.txt, llms-full.txt) — чтобы агенты, читающие sitemap, видели их.
*/
const buildSitemap = (): void => {
const sidebar = cfg.themeConfig.sidebar;
const entries = flattenSidebar(sidebar);
const urls = new Set<string>();
urls.add(`${SITE_URL}/`);
urls.add(`${SITE_URL}/llms.txt`);
urls.add(`${SITE_URL}/llms-full.txt`);
for (const entry of entries) {
const link = entry.link;
// VitePress отдаёт страницы как HTML; для index — каталог со слешем.
const url = link.endsWith('/') ? `${SITE_URL}${link}` : `${SITE_URL}${link}.html`;
urls.add(url);
}
const today = BUILD_DATE.slice(0, 10);
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...[...urls].map(
(loc) => ` <url><loc>${loc}</loc><lastmod>${today}</lastmod></url>`,
),
'</urlset>',
'',
].join('\n');
fs.mkdirSync(PUBLIC_DIR, { recursive: true });
fs.writeFileSync(path.join(PUBLIC_DIR, 'sitemap.xml'), xml, 'utf8');
console.log(`${PUBLIC_DIR}/sitemap.xml создан`);
};
/** Скопировать `index.md` документации в корневой README без frontmatter. */
const buildReadme = (): void => {
const indexPath = 'docs/docs/index.md';
@@ -506,4 +566,6 @@ buildLlmsFull();
copyMdFiles();
buildZip();
writeManifest();
buildRobots();
buildSitemap();
buildReadme();