/* Точка входа публичного сайта: роутинг без /alter, без панели твиков. */ const PAIN_SLUGS = A.pains.map(p => p.slug); const ROLE_SLUGS = A.roles.map(r => r.slug); function resolve(path, query) { const raw = (path || '/').replace(/\/$/, '') || '/'; if (raw === '/') return ; const seg = raw.split('/').filter(Boolean); const [a, b] = seg; if (PAIN_SLUGS.includes(a) && !b) return ; if (ROLE_SLUGS.includes(a) && !b) return ; if (a === 'portfolio' && b) return ; if (a === 'portfolio') return ; if (a === 'blog' && b) return ; if (a === 'blog') return ; const map = { diagnostika: DiagPage, about: AboutPage, ceny: CenyPage, process: ProcessPage, garantii: GarantiiPage, // otzyvy временно скрыта — страница OtzyvyPage остаётся в page-trust.jsx faq: FaqPage, slovar: SlovarPage, }; if (map[a] && !b) { const C = map[a]; return ; } // oferta скрыта (редирект на сервере); в SPA не открываем if (a === 'politika' && !b) return ; return ; } function mergePosts(staticPosts, live) { // Есть опубликованные записки/статьи из БД — только они (без демо из data.js). if (live && live.length) { return live.map(p => { const pains = Array.isArray(p.pains) && p.pains.length ? p.pains.map(x => String(x || '').trim().toLowerCase()).filter(Boolean) : (p.pain ? [String(p.pain).toLowerCase()] : []); const row = { slug: p.slug, title: p.title, cat: p.cat || '', pain: pains[0] || null, pains, min: Number(p.minutes || p.min || 5), date: p.date_label || p.date || '', lead: p.lead || p.hook || p.description || '', figure_url: p.figure_url || '', }; // Не тащим мир Завода в рубрику карточки. row.cat = blogPublicCat(row); return row; }).filter(p => p.slug); } return (staticPosts || []).filter(p => p && p.slug); } function LiveBlogPage() { const [tick, setTick] = React.useState(0); React.useEffect(() => { fetch('/api/public/blog?limit=500') .then(r => r.ok ? r.json() : null) .then(data => { if (data && Array.isArray(data.items)) { const posts = mergePosts(A.posts, data.items); A.posts = posts; A.postBy = Object.fromEntries(posts.map(p => [p.slug, p])); setTick(t => t + 1); } }) .catch(() => {}); }, []); return ; } function relatedWorksToCards(list) { if (!Array.isArray(list) || !list.length) return []; return list.map((w) => { const fromA = (A.caseBy && w.slug && A.caseBy[w.slug]) || null; if (fromA) return fromA; return { slug: w.slug, title: w.title || w.slug, img: w.cover_url || null, res: w.result_line || w.summary || '', phLabel: 'обложка кейса', }; }).filter((c) => c && c.slug); } function LiveArticlePage({ slug }) { const [post, setPost] = React.useState(() => A.postBy[slug] || null); const [html, setHtml] = React.useState(''); const [related, setRelated] = React.useState([]); const [loading, setLoading] = React.useState(!A.postBy[slug]); React.useEffect(() => { let cancelled = false; fetch('/api/public/blog/' + encodeURIComponent(slug)) .then(r => r.ok ? r.json() : null) .then(data => { if (cancelled || !data) return; const pains = Array.isArray(data.pains) && data.pains.length ? data.pains.map(x => String(x || '').trim().toLowerCase()).filter(Boolean) : (data.pain ? [String(data.pain).toLowerCase()] : []); setPost({ slug: data.slug, title: data.title, cat: blogPublicCat({ cat: data.cat || '', pain: pains[0] || null, pains }), pain: pains[0] || null, pains, min: data.minutes || 5, date: data.date_label || data.date || '', lead: data.lead || data.hook || data.description || '', figure_url: data.figure_url || '', }); setHtml(data.body_html || ''); setRelated(relatedWorksToCards(data.related_works)); setLoading(false); }) .catch(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [slug]); if (loading && !post) { return

Загрузка…

; } if (!post) return ; if (html) { const pain = post.pain && A.painBy[post.pain]; return ( <>
{post.cat}{post.date}{post.min} мин чтения

{post.title}

{post.lead}

Наталия Вершинина
автоматизатор и маркетолог
{post.figure_url ? {post.title :
иллюстрация к записке · 16:9
}
{related.length > 0 && (
Все проекты} />
{related.map((c) => )}
)} ); } return ; } function caseTabHtml(html, tab) { const src = String(html || ''); const re = new RegExp(']*data-case-tab=["\']' + tab + '["\'][^>]*>([\\s\\S]*?)', 'i'); const m = src.match(re); return m ? m[1].trim() : ''; } function splitAfterFirstP(html) { const src = String(html || ''); const m = src.match(/<\/p>/i); if (!m) return { before: src, after: '' }; const i = m.index + m[0].length; return { before: src.slice(0, i), after: src.slice(i) }; } function CaseShotStrip({ shots, onOpen, title }) { if (!shots || !shots.length) return null; const fallback = title || ''; return (
{shots.map((s, i) => ( ))}
); } function CaseLightbox({ shots, index, onClose, onNav, title }) { const open = index != null && index >= 0 && shots && shots[index]; React.useEffect(() => { if (!open) return undefined; const onKey = (e) => { if (e.key === 'Escape') onClose(); if (e.key === 'ArrowRight') onNav(1); if (e.key === 'ArrowLeft') onNav(-1); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [open, index, onClose, onNav]); if (!open) return null; const s = shots[index]; const imgAlt = s.caption || s.alt || title || ''; return (
{shots.length > 1 && ( <> )}
e.stopPropagation()}> {imgAlt} {s.caption ?
{s.caption}
: null}
); } function LiveCasePage({ slug }) { const listed = A.caseBy[slug]; const [work, setWork] = React.useState(null); const [loading, setLoading] = React.useState(true); const [mode, setMode] = React.useState('human'); const [lb, setLb] = React.useState(null); React.useEffect(() => { let cancelled = false; setLoading(true); setLb(null); fetch('/api/public/works/' + encodeURIComponent(slug)) .then((r) => (r.ok ? r.json() : null)) .then((data) => { if (cancelled) return; setWork(data && data.work ? data.work : null); setLoading(false); }) .catch(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [slug]); if (loading && !work && !listed) { return

Загрузка…

; } if (!work && !listed) return ; if (!work && listed && !listed.live) return ; if (!work) { return

Не удалось загрузить кейс.

; } // В БД вкладки: people + automata (legacy tech тоже читаем). const peopleHtml = caseTabHtml(work.content_html, 'people'); const schemeHtml = caseTabHtml(work.content_html, 'automata') || caseTabHtml(work.content_html, 'tech'); const hasTabs = Boolean(peopleHtml || schemeHtml); const bodyHtml = hasTabs ? (mode === 'scheme' ? (schemeHtml || peopleHtml) : (peopleHtml || schemeHtml)) : (work.content_html || ''); const parts = splitAfterFirstP(bodyHtml); const shots = (work.gallery || []).filter((g) => g && g.url && !g.is_cover && !g.is_blueprint); const blueprint = (work.gallery || []).find((g) => g && g.url && g.is_blueprint) || null; const faqItems = Array.isArray(work.faq_json) ? work.faq_json.map((row) => [row.q || row.question || '', row.a || row.answer || '']).filter((x) => x[0] && x[1]) : []; const more = A.cases.filter((x) => x.slug && x.slug !== work.slug).slice(0, 3); // Кейс: обложка и чертёж всегда 16:9 — cover_aspect из БД игнорируем (там ещё бывает 3:4). const stateLabel = ({ active: 'Действующий проект', in_progress: 'В работе', closed: 'Завершён' })[work.project_state] || 'Проект'; const heroUrl = mode === 'scheme' && blueprint ? blueprint.url : work.cover_url; const heroLabel = mode === 'scheme' ? 'чертёж процесса · 16:9' : 'обложка кейса · 16:9'; return ( <>
● {stateLabel}
{(work.tags || []).length > 0 && (
На чём сделано
{(work.tags || []).slice(0, 8).map((t) => {t})}
)}

{work.title}

{work.summary || work.meta_description || ''}

{heroUrl ? {work.title :
{heroLabel}
} {(hasTabs || blueprint) && (
)} {work.result_line && mode === 'human' && (
Результат. {work.result_line}
)}
{mode === 'scheme' && !blueprint && (

Чертёж ещё не готов — в админке вкладка «Чертёж» → «Сгенерировать».

)} {bodyHtml ? (
{mode === 'human' ? : null} {parts.after ?
: null}
) : ( mode === 'human' ?

Текст кейса ещё не заполнен.

: null )}
{faqItems.length > 0 && (
Вопросы по кейсу

Частые вопросы

)} {more.length > 0 && (
Все проекты} />
{more.map((x) => )}
)} setLb(null)} onNav={(dir) => setLb((i) => { if (i == null || !shots.length) return i; return (i + dir + shots.length) % shots.length; })} /> ); } function CasePageGate({ slug }) { const c = A.caseBy[slug]; if (c && c.live) return ; return ; } function mergeCases(staticCases, live) { // Есть опубликованные кейсы из БД — только они (без демо-дублей из макета). if (live && live.length) { return live.map(c => ({ slug: c.slug, title: c.title, img: c.cover_url || null, phLabel: 'обложка кейса', tags: c.tags || [], pains: c.pains || [], roles: c.roles || [], sum: c.summary || c.meta_description || '', res: c.result_line || c.summary || '', live: true, })).filter(c => c.slug); } return (staticCases || []).filter(c => c && c.slug); } function App() { const r = useRoute(); const [casesTick, setCasesTick] = React.useState(0); React.useEffect(() => { document.documentElement.setAttribute('data-theme', 'light'); }, []); React.useEffect(() => { fetch('/api/public/works?limit=50') .then(r => r.ok ? r.json() : null) .then(data => { const list = data && (data.works || data.items); if (!Array.isArray(list)) return; const merged = mergeCases(A.cases, list); A.cases = merged; A.caseBy = Object.fromEntries(merged.map(c => [c.slug, c])); setCasesTick(t => t + 1); }) .catch(() => {}); }, []); return ( <>
{resolve(r.path, r.query)}