From 934310a32c29faa032468792bc3edd4a06136fd7 Mon Sep 17 00:00:00 2001 From: estorozhenko Date: Sat, 14 Nov 2026 14:19:23 +0000 Subject: [PATCH] =?UTF-8?q?fix(covers):=20slugify=20=D0=B2=20gen-covers=20?= =?UTF-8?q?(31=20=D0=BE=D0=B1=D0=BB=D0=BE=D0=B6=D0=BA=D0=B0=20=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=8C=20=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2=D0=BE)=20+=20?= =?UTF-8?q?=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20PNG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/gen-covers.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; } }