diff --git a/frontend/index.html b/frontend/index.html index 8f52de9c09..513845ebbf 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -37,7 +37,9 @@ script runs before first paint: browsers (JS on) never show the prerender; crawlers without JS still get the full content. Not cloaking — JS-running crawlers see the real app. --> + + + +
diff --git a/frontend/scripts/generate-seo-pages.mjs b/frontend/scripts/generate-seo-pages.mjs index a4bde5ac66..12b640dad0 100644 --- a/frontend/scripts/generate-seo-pages.mjs +++ b/frontend/scripts/generate-seo-pages.mjs @@ -9,6 +9,11 @@ const siteUrl = 'https://commonly.me'; const metadataStart = ''; const metadataEnd = ''; const pageContentMarker = ''; +const gateRuntimeStart = ''; +const gateRuntimeEnd = ''; +const navigationRuntimeStart = ''; +const navigationRuntimeEnd = ''; +const viteEntryAssetPrefix = 'src="/assets/index-'; const escapeHtml = (value) => String(value) .replaceAll('&', '&') @@ -30,6 +35,68 @@ const replaceMarkedSection = (template, start, end, content) => { return `${template.slice(0, startIndex)}${start}\n${content}\n${end}${template.slice(endIndex + end.length)}`; }; +const removeMarkedSection = (template, start, end) => { + const startIndex = template.indexOf(start); + const endIndex = template.indexOf(end); + + if (startIndex < 0 || endIndex < 0 || endIndex < startIndex) { + throw new Error(`Missing or malformed ${start} marker in the Vite output.`); + } + + return `${template.slice(0, startIndex)}${template.slice(endIndex + end.length)}`; +}; + +const removeRuntimeEntryScript = (template) => { + const entryIndex = template.indexOf(viteEntryAssetPrefix); + const tagStart = template.lastIndexOf('<', entryIndex); + const tagEnd = template.indexOf('>', entryIndex); + + if ( + entryIndex < 0 + || tagStart < 0 + || tagEnd < entryIndex + || !template.startsWith(' { + let document = template; + let preloadIndex = document.indexOf('rel="modulepreload"'); + + while (preloadIndex >= 0) { + const tagStart = document.lastIndexOf('<', preloadIndex); + const tagEnd = document.indexOf('>', preloadIndex); + + if ( + tagStart < 0 + || tagEnd < preloadIndex + || !document.startsWith(' { + const withoutGateRuntime = removeMarkedSection(template, gateRuntimeStart, gateRuntimeEnd); + const withoutNavigationRuntime = removeMarkedSection( + withoutGateRuntime, + navigationRuntimeStart, + navigationRuntimeEnd, + ); + + return removeModulePreloads(removeRuntimeEntryScript(withoutNavigationRuntime)); +}; + const pageUrl = (path) => `${siteUrl}${path}`; const formatDate = (value) => { @@ -371,6 +438,7 @@ export const buildPageDefinitions = ({ landing, compare, useCases, guides = {} } title: 'Guides for teams working with AI agents | Commonly', description: 'Practical guides for teams that work with AI agents: shared context, task ownership, human review, and durable handoffs.', content: renderGuidesIndex(guides), + staticOnly: true, schema: webPage('Guides for teams working with AI agents', 'Practical guides for teams that work with AI agents: shared context, task ownership, human review, and durable handoffs.', guidesIndexPath), }; @@ -397,6 +465,7 @@ export const buildPageDefinitions = ({ landing, compare, useCases, guides = {} } title: guide.titleTag, description: guide.description, content: renderGuide(guide), + staticOnly: true, ogType: 'article', datePublished: provenance.datePublished, dateModified: provenance.dateModified, @@ -429,7 +498,8 @@ export const buildPageDefinitions = ({ landing, compare, useCases, guides = {} } }; export const renderStaticPage = (template, page) => { - const withMetadata = replaceMarkedSection(template, metadataStart, metadataEnd, metadata(page)); + const staticTemplate = page.staticOnly ? staticDocument(template) : template; + const withMetadata = replaceMarkedSection(staticTemplate, metadataStart, metadataEnd, metadata(page)); if (!withMetadata.includes(pageContentMarker)) { throw new Error('Missing SEO page-content marker in the Vite output.'); } diff --git a/frontend/scripts/generate-seo-pages.test.mjs b/frontend/scripts/generate-seo-pages.test.mjs index 9fa980e5d3..2dffa0595a 100644 --- a/frontend/scripts/generate-seo-pages.test.mjs +++ b/frontend/scripts/generate-seo-pages.test.mjs @@ -54,13 +54,19 @@ test('emits a canonical crawlable page for every public route', async () => { const taskManagementArticle = taskManagementGuide.schema['@graph'].find((item) => item['@type'] === 'Article'); assert.equal(taskManagementArticle.datePublished, '2026-08-25'); assert.equal(taskManagementArticle.dateModified, '2026-08-25'); - const guideTemplate = '
'; + const guideTemplate = '
'; const taskManagementHtml = renderStaticPage(guideTemplate, taskManagementGuide); assert.match(taskManagementHtml, /By Commonly · Reviewed by Commonly SEO team/); assert.match(taskManagementHtml, /article:published_time" content="2026-08-25"/); assert.match(taskManagementHtml, /article:modified_time" content="2026-08-25"/); assert.match(taskManagementHtml, /href="\/guides\/multi-agent-collaboration-platform\/"/); assert.match(taskManagementHtml, /href="\/guides\/ai-agent-workspace\/"/); + assert.doesNotMatch(taskManagementHtml, /document\.documentElement/); + assert.doesNotMatch(taskManagementHtml, /popstate/); + assert.doesNotMatch(taskManagementHtml, /modulepreload/); + assert.doesNotMatch(taskManagementHtml, /type="module"/); + assert.doesNotMatch(taskManagementHtml, /src="\/assets\/index-/); + assert.match(taskManagementHtml, /#seo-page \{ color: #fff; \}/); for (const guidePath of [ '/guides/multi-agent-collaboration-platform/', '/guides/ai-agent-workspace/', @@ -81,10 +87,12 @@ test('puts route content, canonical metadata, and structured data in the documen content: '

Example page

Home
', schema: { '@context': 'https://schema.org', '@type': 'WebPage', name: 'Example page' }, }; - const template = '
'; + const template = '
'; const rendered = renderStaticPage(template, page); assert.match(rendered, /

Example page<\/h1>/); assert.match(rendered, /