4cb6323e4c
- tools/covergen из ветки covergen-tooling + флаг --palette auto|dedinit-dark (цвета theme-vars/hero.svg) - scripts/gen-covers.mjs: SVG в static/covers (в git), PNG — артефакт сборки (gitignore), --png/--force/--only - rss.xml: <enclosure> с covers/<slug>.png при fileExists, <language>ru</language>, описание канала по-русски - hugo.toml: limit 5 → 20, enableRobotsTXT - deploy.yml: nodejs + librsvg2-bin, шаг генерации обложек перед hugo - docs: DZEN_RSS (итог), covergen (палитра, SVG/PNG, питфолл snap-chromium), вики reference-covers/reference-rss-dzen - openspec change dzen-rss-compliance
130 lines
8.2 KiB
JavaScript
130 lines
8.2 KiB
JavaScript
'use strict';
|
|
|
|
const { esc, fit } = require('../typeset');
|
|
|
|
const SERIF = 'Georgia, "Times New Roman", "DejaVu Serif", serif';
|
|
const SANS = 'Inter, "Helvetica Neue", Helvetica, Arial, "DejaVu Sans", sans-serif';
|
|
const MONO = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace';
|
|
|
|
function tagsLine(ctx) {
|
|
return (ctx.tags ?? []).slice(0, 3).map((tag) => `#${tag}`).join(' ');
|
|
}
|
|
|
|
/** Крупный плакатный заголовок по центру, тонкая рамка, подпись снизу. */
|
|
function poster(ctx) {
|
|
const { width: w, height: h, palette: p, uid } = ctx;
|
|
const pad = Math.round(w * 0.1);
|
|
const title = fit(ctx.title, { maxWidth: w - pad * 2, maxLines: 4, size: Math.round(h * 0.13), min: 22 });
|
|
const blockH = title.lines.length * title.lineHeight;
|
|
const top = Math.round((h - blockH) / 2 - h * 0.02);
|
|
const lines = title.lines
|
|
.map((line, i) => `<text x="${w / 2}" y="${top + title.fontSize + i * title.lineHeight}" text-anchor="middle" font-family="${SANS}" font-size="${title.fontSize}" font-weight="700" fill="${p.ink}" letter-spacing="-0.5">${esc(line)}</text>`)
|
|
.join('');
|
|
return `
|
|
<defs>
|
|
<linearGradient id="bg${uid}" x1="0" y1="0" x2="0.6" y2="1">
|
|
<stop offset="0" stop-color="${p.bg}"/><stop offset="1" stop-color="${p.bg2}"/>
|
|
</linearGradient>
|
|
</defs>
|
|
<rect width="${w}" height="${h}" fill="url(#bg${uid})"/>
|
|
<rect x="${pad * 0.55}" y="${pad * 0.55}" width="${w - pad * 1.1}" height="${h - pad * 1.1}" fill="none" stroke="${p.accent}" stroke-opacity="0.55" stroke-width="2"/>
|
|
<rect x="${pad * 0.55}" y="${top - Math.round(h * 0.06)}" width="${Math.round(w * 0.12)}" height="5" fill="${p.accent}"/>
|
|
${lines}
|
|
<text x="${w / 2}" y="${h - pad * 0.85}" text-anchor="middle" font-family="${MONO}" font-size="${Math.round(h * 0.032)}" fill="${p.muted}" letter-spacing="3">${esc((ctx.subtitle ?? '').toUpperCase())}</text>`;
|
|
}
|
|
|
|
/** Геометрия баухауса: круг, прямоугольник, диагональ; заголовок слева снизу. */
|
|
function bauhaus(ctx) {
|
|
const { width: w, height: h, palette: p, uid } = ctx;
|
|
const title = fit(ctx.title, { maxWidth: w * 0.72, maxLines: 3, size: Math.round(h * 0.11), min: 20 });
|
|
const baseline = h - Math.round(h * 0.14);
|
|
const lines = title.lines
|
|
.map((line, i) => `<text x="${Math.round(w * 0.08)}" y="${baseline - (title.lines.length - 1 - i) * title.lineHeight}" font-family="${SANS}" font-size="${title.fontSize}" font-weight="800" fill="${p.ink}">${esc(line)}</text>`)
|
|
.join('');
|
|
return `
|
|
<defs>
|
|
<clipPath id="clip${uid}"><rect width="${w}" height="${h}"/></clipPath>
|
|
</defs>
|
|
<g clip-path="url(#clip${uid})">
|
|
<rect width="${w}" height="${h}" fill="${p.bg}"/>
|
|
<circle cx="${Math.round(w * 0.82)}" cy="${Math.round(h * 0.26)}" r="${Math.round(h * 0.3)}" fill="${p.accent}" opacity="0.92"/>
|
|
<rect x="0" y="${Math.round(h * 0.44)}" width="${Math.round(w * 0.46)}" height="${Math.round(h * 0.1)}" fill="${p.accent2}" opacity="0.85"/>
|
|
<polygon points="${Math.round(w * 0.06)},0 ${Math.round(w * 0.24)},0 ${Math.round(w * 0.06)},${Math.round(h * 0.22)}" fill="${p.muted}" opacity="0.5"/>
|
|
<rect x="${Math.round(w * 0.08)}" y="${Math.round(h * 0.6)}" width="${Math.round(w * 0.1)}" height="4" fill="${p.accent}"/>
|
|
</g>
|
|
${lines}
|
|
<text x="${Math.round(w * 0.08)}" y="${Math.round(h * 0.92)}" font-family="${MONO}" font-size="${Math.round(h * 0.03)}" fill="${p.muted}" letter-spacing="2">${esc(tagsLine(ctx) || (ctx.subtitle ?? ''))}</text>`;
|
|
}
|
|
|
|
/** Конструктивизм: диагональная плашка и наклонный заголовок. */
|
|
function constructivist(ctx) {
|
|
const { width: w, height: h, palette: p, uid } = ctx;
|
|
const title = fit(ctx.title, { maxWidth: w * 0.68, maxLines: 3, size: Math.round(h * 0.105), min: 20 });
|
|
const originX = Math.round(w * 0.08);
|
|
// Первая строка садится так, чтобы весь блок из 3 строк оставался в кадре даже с наклоном.
|
|
const originY = Math.round(h * 0.34) + Math.round(title.lineHeight * 0.6);
|
|
const lines = title.lines
|
|
.map((line, i) => {
|
|
const y = originY + i * title.lineHeight;
|
|
return `<text x="${originX}" y="${y}" transform="rotate(-4 ${originX} ${y})" font-family="${SANS}" font-size="${title.fontSize}" font-weight="800" fill="${p.ink}">${esc(line.toUpperCase())}</text>`;
|
|
})
|
|
.join('');
|
|
return `
|
|
<rect width="${w}" height="${h}" fill="${p.bg}"/>
|
|
<polygon points="0,${Math.round(h * 0.62)} ${w},${Math.round(h * 0.28)} ${w},${Math.round(h * 0.46)} 0,${Math.round(h * 0.8)}" fill="${p.accent}" opacity="0.9"/>
|
|
<polygon points="0,${Math.round(h * 0.86)} ${w},${Math.round(h * 0.56)} ${w},${Math.round(h * 0.6)} 0,${Math.round(h * 0.9)}" fill="${p.accent2}" opacity="0.75"/>
|
|
<circle cx="${Math.round(w * 0.86)}" cy="${Math.round(h * 0.18)}" r="${Math.round(h * 0.11)}" fill="${p.muted}" opacity="0.35"/>
|
|
${lines}
|
|
<text x="${originX}" y="${Math.round(h * 0.94)}" font-family="${MONO}" font-size="${Math.round(h * 0.028)}" fill="${p.muted}" letter-spacing="4">${esc((ctx.subtitle ?? '').toUpperCase())}</text>`;
|
|
}
|
|
|
|
/** Мягкие радиальные пятна: «северное сияние» на тёмном фоне. */
|
|
function aurora(ctx) {
|
|
const { width: w, height: h, palette: p, uid } = ctx;
|
|
const title = fit(ctx.title, { maxWidth: w * 0.78, maxLines: 4, size: Math.round(h * 0.1), min: 20 });
|
|
const blockH = title.lines.length * title.lineHeight;
|
|
const top = Math.round((h - blockH) / 2);
|
|
const lines = title.lines
|
|
.map((line, i) => `<text x="${w / 2}" y="${top + title.fontSize + i * title.lineHeight}" text-anchor="middle" font-family="${SERIF}" font-size="${title.fontSize}" fill="${p.ink}">${esc(line)}</text>`)
|
|
.join('');
|
|
return `
|
|
<defs>
|
|
<radialGradient id="a1${uid}" cx="0.2" cy="0.15" r="0.7">
|
|
<stop offset="0" stop-color="${p.accent}" stop-opacity="0.55"/><stop offset="1" stop-color="${p.accent}" stop-opacity="0"/>
|
|
</radialGradient>
|
|
<radialGradient id="a2${uid}" cx="0.85" cy="0.8" r="0.65">
|
|
<stop offset="0" stop-color="${p.accent2}" stop-opacity="0.5"/><stop offset="1" stop-color="${p.accent2}" stop-opacity="0"/>
|
|
</radialGradient>
|
|
</defs>
|
|
<rect width="${w}" height="${h}" fill="${p.bg}"/>
|
|
<rect width="${w}" height="${h}" fill="url(#a1${uid})"/>
|
|
<rect width="${w}" height="${h}" fill="url(#a2${uid})"/>
|
|
<line x1="${w * 0.5}" y1="${top - title.lineHeight}" x2="${w * 0.5}" y2="${top - title.lineHeight + 6}" stroke="${p.accent}" stroke-width="3"/>
|
|
${lines}
|
|
<text x="${w / 2}" y="${h - Math.round(h * 0.1)}" text-anchor="middle" font-family="${SANS}" font-size="${Math.round(h * 0.03)}" fill="${p.muted}" letter-spacing="1">${esc(tagsLine(ctx))}</text>`;
|
|
}
|
|
|
|
/** Минимализм: линейки, серифный заголовок, автор внизу. */
|
|
function paper(ctx) {
|
|
const { width: w, height: h, palette: p } = ctx;
|
|
const pad = Math.round(w * 0.09);
|
|
const title = fit(ctx.title, { maxWidth: w - pad * 2, maxLines: 4, size: Math.round(h * 0.1), min: 20 });
|
|
const lines = title.lines
|
|
.map((line, i) => `<text x="${pad}" y="${Math.round(h * 0.34) + i * title.lineHeight}" font-family="${SERIF}" font-size="${title.fontSize}" fill="${p.bg}">${esc(line)}</text>`)
|
|
.join('');
|
|
const rules = [0.14, 0.3, 0.84, 0.9]
|
|
.map((y) => `<line x1="${pad}" y1="${Math.round(h * y)}" x2="${w - pad}" y2="${Math.round(h * y)}" stroke="${p.bg}" stroke-opacity="0.28" stroke-width="1"/>`)
|
|
.join('');
|
|
return `
|
|
<rect width="${w}" height="${h}" fill="${p.ink}"/>
|
|
<rect x="${pad * 0.5}" y="${pad * 0.5}" width="${w - pad}" height="${h - pad}" fill="none" stroke="${p.bg}" stroke-opacity="0.18"/>
|
|
${rules}
|
|
${lines}
|
|
<text x="${pad}" y="${Math.round(h * 0.8)}" font-family="${SANS}" font-size="${Math.round(h * 0.028)}" fill="${p.bg}" fill-opacity="0.75" letter-spacing="3">${esc((ctx.subtitle ?? '').toUpperCase())}</text>
|
|
<text x="${pad}" y="${Math.round(h * 0.94)}" font-family="${MONO}" font-size="${Math.round(h * 0.026)}" fill="${p.bg}" fill-opacity="0.6">${esc(ctx.author ?? '')}</text>`;
|
|
}
|
|
|
|
const STYLES = { poster, bauhaus, constructivist, aurora, paper };
|
|
|
|
module.exports = { STYLES, SERIF, SANS, MONO };
|