diff --git a/scripts/gen-covers.mjs b/scripts/gen-covers.mjs index f01c188..fcd1c75 100644 --- a/scripts/gen-covers.mjs +++ b/scripts/gen-covers.mjs @@ -63,6 +63,14 @@ function frontMatter(text) { return fm; } +function slugify(value) { + return String(value) + .toLowerCase() + .replace(/[^\p{L}\p{N}]+/gu, '-') + .replace(/^-+|-+$/g, '') + .slice(0, 80) || 'cover'; +} + function collect() { const entries = []; for (const dir of fs.readdirSync(POSTS, { withFileTypes: true })) { @@ -71,7 +79,7 @@ function collect() { if (!fs.existsSync(index)) continue; const fm = frontMatter(fs.readFileSync(index, 'utf8')); if (fm.draft === true && !FORCE) continue; - const slug = String(fm.slug || dir.name).trim(); + const slug = slugify(String(fm.slug || dir.name).trim()); if (!slug || !fm.title) continue; const date = String(fm.date || '').slice(0, 10); const tags = Array.isArray(fm.tags) ? fm.tags.map(String) : String(fm.tags || '').split(',').filter(Boolean); @@ -93,9 +101,11 @@ function toPng(svgPath) { ['rsvg-convert', ['-o', pngPath, svgPath]], ['resvg', ['--use-fonts-dir', '/usr/share/fonts', svgPath, pngPath]], ]; + const errors = []; for (const [bin, args] of tries) { const res = spawnSync(bin, args, { encoding: 'utf8' }); if (res.status === 0 && fs.existsSync(pngPath)) return pngPath; + errors.push(`${bin}: status=${res.status} ${(res.error && res.error.code) || ''} ${(res.stderr || '').trim().slice(-200)}`); } // snap-chromium под AppArmor не читает /opt и /tmp — копируем SVG в НАСТОЯЩИЙ домашний // каталог пользователя (os.homedir() отдаёт $HOME агента, а он у нас в /opt) @@ -110,8 +120,10 @@ function toPng(svgPath) { '--window-size=1200,630', `--screenshot=${tmpPng}`, `file://${tmpSvg}`, ], { encoding: 'utf8', timeout: 120000 }); let ok = chrome.status === 0 && fs.existsSync(tmpPng); + if (!ok) errors.push(`chromium: status=${chrome.status} ${(chrome.error && chrome.error.code) || ''}`); if (ok) fs.copyFileSync(tmpPng, pngPath); fs.rmSync(tmpDir, { recursive: true, force: true }); + if (!ok) console.error(` подробности: ${errors.join(' | ')}`); return ok ? pngPath : null; } @@ -154,7 +166,7 @@ function main() { } if (toPng(svgPath)) made += 1; else { - console.error(`PNG не создан: ${file} — нет rsvg-convert/resvg, chromium недоступен`); + console.error(`PNG не создан: ${file} — ни rsvg-convert, ни resvg, ни chromium не сработали`); break; } }