Serve the project catalog to search without JavaScript

- generate-content.mjs writes the 20 project articles into a marked <noscript>
  block in src/index.html: title, status/platforms/stack, tagline and the case
  body (~10.3k chars). With JS enabled the block never reaches the DOM, so the
  page looks the same; the injection is idempotent.
- Drop stale robots.txt disallow rules for the removed api/ and var/ paths,
  add og:image:type.
- New docs/seo.md: what the page exposes to search, the crawlable catalog
  contract, the query map, and the owner steps (Yandex.Webmaster, Search
  Console, sitemap, re-crawl, single host, 404).
- AGENTS.md, INDEX.md and spec section 10.31 point at the new contract.
This commit is contained in:
FastD committed 2026-11-15 17:49:35 +03:00
1 parent a013db4c5b
commit e8fe1c1b4e
7 files changed
+334 -8

No files matched your search

+59 -1
View File
@@ -204,6 +204,64 @@ function writeJs(path, varname, data) {
console.log(`wrote ${path} (${data.length} item(s))`);
}
writeJs(join(OUT, 'projects.js'), 'HMT_PROJECTS', loadProjects());
// ---- SEO: статический каталог для поиска (виден без JS) ----
// Карточки рисует JS из data/*.js, поэтому в HTML нет текста проектов. Поисковик без
// рендера видит пустой блок. Генератор кладёт тот же каталог текстом в <noscript>
// между маркерами в src/index.html — один источник (content/*.md), ноль расхождений.
const SEO_START = '<!-- SEO:CATALOG:START -->';
const SEO_END = '<!-- SEO:CATALOG:END -->';
function escHtml(s) {
return String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
}
// Тот же мини-рендер markdown, что в main.js: «## » → h4, «- » → ul, абзац → p.
function detailToHtml(md) {
const out = [];
let list = false;
const closeList = () => { if (list) { out.push('</ul>'); list = false; } };
for (const rawLine of String(md || '').split('\n')) {
const line = rawLine.trim();
if (!line) { closeList(); continue; }
const h = line.match(/^#{2,4}\s+(.+)/);
if (h) { closeList(); out.push('<h4>' + escHtml(h[1]) + '</h4>'); continue; }
const li = line.match(/^[-*]\s+(.+)/);
if (li) { if (!list) { out.push('<ul>'); list = true; } out.push('<li>' + escHtml(li[1]) + '</li>'); continue; }
closeList();
out.push('<p>' + escHtml(line) + '</p>');
}
closeList();
return out.join('\n');
}
function seoCatalog(projects) {
const items = projects.map((p) => {
const meta = [p.badge, (p.platforms || []).join(' · '), (p.stack || []).join(' · ')].filter(Boolean).join(' · ');
return '<article>\n<h3>' + escHtml(p.title) + '</h3>\n' +
(meta ? '<p><strong>' + escHtml(meta) + '</strong></p>\n' : '') +
(p.tagline ? '<p>' + escHtml(p.tagline) + '</p>\n' : '') +
(p.detail ? detailToHtml(p.detail) + '\n' : '') +
'</article>';
}).join('\n');
return '<noscript>\n<p class="lead">Карточки проектов открываются с включённым JavaScript. Ниже — тот же каталог текстом.</p>\n' +
'<div class="seo-catalog">\n' + items + '\n</div>\n</noscript>';
}
function injectSeoCatalog(projects) {
const page = join(ROOT, 'src', 'index.html');
const html = readFileSync(page, 'utf8');
const a = html.indexOf(SEO_START);
const b = html.indexOf(SEO_END);
if (a < 0 || b < a) { console.log('seo: маркеры не найдены, пропуск'); return; }
const eol = html.includes('\r\n') ? '\r\n' : '\n';
const block = seoCatalog(projects).replace(/\n/g, eol);
const next = html.slice(0, a + SEO_START.length) + eol + block + eol + ' ' + html.slice(b);
writeFileSync(page, next);
console.log(`seo: каталог текстом — ${projects.length} карточек`);
}
const projects = loadProjects();
writeJs(join(OUT, 'projects.js'), 'HMT_PROJECTS', projects);
writeJs(join(OUT, 'team.js'), 'HMT_TEAM', loadTeam());
injectSeoCatalog(projects);
console.log('done.');