fix(generate-llms): корректные ссылки в корневом README
- ссылки /docs/... преобразованы в относительные пути docs/docs/*.md - корневые ресурсы (/llms.txt, *.zip и т.п.) переписаны на абсолютный SITE_URL - после описания добавлена строка с URL сайта
This commit is contained in:
@@ -547,6 +547,29 @@ const buildSitemap = (): void => {
|
|||||||
console.log(`${PUBLIC_DIR}/sitemap.xml создан`);
|
console.log(`${PUBLIC_DIR}/sitemap.xml создан`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Преобразовать абсолютные ссылки `index.md` в рабочие при открытии
|
||||||
|
* README в репозитории:
|
||||||
|
* - `/docs/foo` → относительный путь `docs/docs/foo.md`;
|
||||||
|
* - корневые ресурсы (`/llms.txt`, `/llms-full.txt`, `*.zip`, `/manifest.json`,
|
||||||
|
* `/sitemap.xml`, `/robots.txt`) — генерируемые, в репозитории отсутствуют,
|
||||||
|
* поэтому ссылки переписываются на абсолютный `SITE_URL`.
|
||||||
|
*/
|
||||||
|
const transformReadmeLinks = (content: string): string => {
|
||||||
|
const linkRe = /\]\((\/[^)\s]*)\)/g;
|
||||||
|
return content.replace(linkRe, (match, href: string) => {
|
||||||
|
const [pathPart, hash = ''] = href.split('#');
|
||||||
|
const hashPart = hash ? `#${hash}` : '';
|
||||||
|
|
||||||
|
if (pathPart.startsWith(DOC_PREFIX)) {
|
||||||
|
const rel = linkToArchiveRel(pathPart);
|
||||||
|
return `](docs/docs/${rel}${hashPart})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `](${SITE_URL}${pathPart}${hashPart})`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/** Скопировать `index.md` документации в корневой README без frontmatter. */
|
/** Скопировать `index.md` документации в корневой README без frontmatter. */
|
||||||
const buildReadme = (): void => {
|
const buildReadme = (): void => {
|
||||||
const indexPath = 'docs/docs/index.md';
|
const indexPath = 'docs/docs/index.md';
|
||||||
@@ -556,7 +579,15 @@ const buildReadme = (): void => {
|
|||||||
}
|
}
|
||||||
const raw = fs.readFileSync(indexPath, 'utf8');
|
const raw = fs.readFileSync(indexPath, 'utf8');
|
||||||
const { body } = parseFrontmatter(raw);
|
const { body } = parseFrontmatter(raw);
|
||||||
fs.writeFileSync('README.md', body.trimStart(), 'utf8');
|
const transformed = transformReadmeLinks(body.trimStart());
|
||||||
|
|
||||||
|
// Порядок: H1 → описание (первый абзац) → ссылка на сайт.
|
||||||
|
const withSiteLink = transformed.replace(
|
||||||
|
/^(#\s[^\n]*\n\n[^\n]+\n)/,
|
||||||
|
`$1\nСайт: ${SITE_URL}\n`,
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync('README.md', withSiteLink, 'utf8');
|
||||||
console.log(`README.md обновлён из ${indexPath}`);
|
console.log(`README.md обновлён из ${indexPath}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user