diff --git a/apps/website/src/components/workshop/WorkshopLoading.vue b/apps/website/src/components/workshop/WorkshopLoading.vue index 3eb7c60ae1c..8e845f9ef88 100644 --- a/apps/website/src/components/workshop/WorkshopLoading.vue +++ b/apps/website/src/components/workshop/WorkshopLoading.vue @@ -20,6 +20,7 @@ const { label, minh = true } = defineProps<{ ) " data-testid="workshop-loading" + data-twin-omit > { } } -async function readBuiltPage( +async function builtPagePath( root: string, pathname: string ): Promise { @@ -65,11 +65,32 @@ async function readBuiltPage( join(root, `${trimmed || 'index'}.html`) ] for (const candidate of candidates) { - if (await exists(candidate)) return readFile(candidate, 'utf8') + if (await exists(candidate)) return candidate } return undefined } +async function readBuiltPage( + root: string, + pathname: string +): Promise { + const path = await builtPagePath(root, pathname) + return path === undefined ? undefined : readFile(path, 'utf8') +} + +const TWIN_LINK = /]*\btype="text\/markdown"[^>]*>/ + +async function unlinkTwin(root: string, pathname: string): Promise { + const path = await builtPagePath(root, pathname) + if (path === undefined) return + const html = await readFile(path, 'utf8') + const unlinked = html.replace(TWIN_LINK, '') + if (unlinked.includes('type="text/markdown"')) { + throw new Error(`${path} kept a markdown twin link TWIN_LINK did not match`) + } + if (unlinked !== html) await writeFile(path, unlinked, 'utf8') +} + async function readBuiltTwinSource( root: string, pathname: string @@ -88,8 +109,9 @@ async function readBuiltTwinSource( /** * Write a `.md` twin next to every built HTML page: `/cli/` → `/cli.md`, - * `/` → `/index.md`. Pages kept out of the sitemap get no twin, and a twin - * that already exists (hand-written by a page endpoint) is left alone. + * `/` → `/index.md`. Pages kept out of the sitemap get no twin, a page with no + * content loses its markdown link instead, and a twin that already exists + * (hand-written by a page endpoint) is left alone. */ export async function writeMarkdownTwins( root: string, @@ -125,6 +147,11 @@ export async function writeMarkdownTwins( const page = htmlToTwin(source.html, canonical, { canonical: source.alternate ? canonical : undefined }) + if (page.body === '') { + await unlinkTwin(root, pathname) + report.skipped.push(twinPath) + continue + } await mkdir(dirname(target), { recursive: true }) await writeFile(target, renderTwin(page), 'utf8') report.written.push(twinPath) diff --git a/apps/website/src/lib/markdown-twin.test.ts b/apps/website/src/lib/markdown-twin.test.ts index dfe9bc681ff..29b5c475bce 100644 --- a/apps/website/src/lib/markdown-twin.test.ts +++ b/apps/website/src/lib/markdown-twin.test.ts @@ -1,8 +1,11 @@ import { mkdtemp, readFile, mkdir, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' -import { afterEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { h } from 'vue' +import { renderToString } from 'vue/server-renderer' +import WorkshopLoading from '../components/workshop/WorkshopLoading.vue' import { isExcludedFromSitemap } from '../config/indexing' import { routerModelSlugAliases, @@ -16,6 +19,10 @@ import { markdownTwinPath } from './markdown-twin-path' const launch = vi.hoisted(() => ({ MODEL_PAGES_INDEXABLE: false })) vi.mock(import('../config/model-page-launch'), () => launch) +const loadingSpinner = await renderToString( + h(WorkshopLoading, { label: 'Loading' }) +) + const PAGE = ` @@ -24,10 +31,11 @@ const PAGE = ` +
Comfy home
-

Drive ComfyUI from your terminal.
Or your agent's.

+

Drive ComfyUI from your terminal.
Or your agent's.

Generate from Comfy Cloud or your own GPU with comfy-cli.

@@ -37,6 +45,8 @@ const PAGE = ` icon + ${loadingSpinner} +

Saved to your library.

Set up Comfy CLI

@@ -87,6 +97,7 @@ describe('htmlToTwin', () => { "# Drive ComfyUI from your terminal. Or your agent's." ) expect(page.body).not.toContain('Comfy MCP') + expect(page.body).not.toContain('Comfy home') expect(page.body).not.toContain('Products') expect(page.body).not.toContain('window.track') expect(page.body).not.toContain('icon') @@ -94,6 +105,11 @@ describe('htmlToTwin', () => { expect(page.body).not.toContain('clip.mp4') }) + it('drops the Workshop loading spinner but keeps other status copy', () => { + expect(page.body).not.toContain('Loading') + expect(page.body).toContain('Saved to your library.') + }) + it('makes links absolute, drops anchor links, and keeps emphasis', () => { expect(page.body).toContain( 'Generate from [Comfy Cloud](https://comfy.org/cloud/) or your own GPU with **comfy-cli**.' @@ -125,6 +141,14 @@ describe('htmlToTwin', () => { expect(page.body).toContain('> Method, not magic.') }) + it('drops the site banner but keeps page headers when there is no main', () => { + const noMain = htmlToTwin( + '
Comfy home

Pack

Nodes.

', + 'https://comfy.org/x/' + ) + expect(noMain.body).toBe('# Pack\n\nNodes.') + }) + it('falls back to the route when the page has no canonical link', () => { const bare = htmlToTwin( '

x

', @@ -308,4 +332,102 @@ describe('writeMarkdownTwins', () => { } ) }) + + describe('model pages', () => { + const [{ slug: modelSlug }] = workshopModels + const route = `models/${modelSlug}/` + const twinPath = `/models/${modelSlug}.md` + + async function buildModelPage( + main: string, + twinLink = `` + ) { + const root = await mkdtemp(join(tmpdir(), 'twins-')) + await mkdir(join(root, route), { recursive: true }) + await writeFile( + join(root, route, 'index.html'), + `${modelSlug}${twinLink}
Comfy home
${main}
` + ) + return root + } + + const readPage = (root: string) => + readFile(join(root, route, 'index.html'), 'utf8') + + beforeEach(() => { + launch.MODEL_PAGES_INDEXABLE = true + }) + + afterEach(() => { + launch.MODEL_PAGES_INDEXABLE = false + }) + + it('writes no twin and drops the markdown link for a spinner-only page', async () => { + const root = await buildModelPage( + `${loadingSpinner}` + ) + + const report = await writeMarkdownTwins(root, [route]) + + expect(report.written).toEqual([]) + expect(report.skipped).toEqual([twinPath]) + await expect(readFile(join(root, twinPath))).rejects.toThrow() + const html = await readPage(root) + expect(html).not.toContain('text/markdown') + expect(html).toContain('rel="canonical"') + }) + + it('drops the markdown link whatever its attribute order', async () => { + const root = await buildModelPage( + `${loadingSpinner}`, + `` + ) + + await writeMarkdownTwins(root, [route]) + + expect(await readPage(root)).not.toContain('text/markdown') + }) + + it('leaves a contentless page that never linked a twin untouched', async () => { + const root = await buildModelPage( + `${loadingSpinner}`, + '' + ) + const before = await readPage(root) + + const report = await writeMarkdownTwins(root, [route]) + + expect(report.skipped).toEqual([twinPath]) + expect(await readPage(root)).toBe(before) + }) + + it('fails the build when a contentless page keeps a markdown link it cannot drop', async () => { + const root = await buildModelPage( + `${loadingSpinner}`, + `` + ) + + await expect(writeMarkdownTwins(root, [route])).rejects.toThrow( + join(root, route, 'index.html') + ) + }) + + it('twins the server-rendered hero and drops the spinner (post-FE-2942 (#18899) shape)', async () => { + const root = await buildModelPage( + `

Provider

Model name

Model summary.

${loadingSpinner}` + ) + + const report = await writeMarkdownTwins(root, [route]) + + expect(report.written).toEqual([twinPath]) + const twin = await readFile(join(root, twinPath), 'utf8') + expect(twin).toContain(`canonical: https://comfy.org/${route}\n`) + expect(twin).toContain( + '---\n\nProvider\n\n# Model name\n\nModel summary.\n' + ) + expect(twin).not.toContain('Loading') + expect(twin).not.toContain('Comfy home') + expect(await readPage(root)).toContain('text/markdown') + }) + }) }) diff --git a/apps/website/src/lib/markdown-twin.ts b/apps/website/src/lib/markdown-twin.ts index 466a5f2c86f..9458cdbda27 100644 --- a/apps/website/src/lib/markdown-twin.ts +++ b/apps/website/src/lib/markdown-twin.ts @@ -29,7 +29,6 @@ const DROPPED_TAGS = new Set([ 'FORM', 'NAV', 'FOOTER', - 'HEADER', 'DIALOG', 'SOURCE', 'TRACK' @@ -46,6 +45,7 @@ const BLOCK_TAGS = new Set([ 'DT', 'FIGCAPTION', 'FIGURE', + 'HEADER', 'MAIN', 'P', 'SECTION', @@ -86,10 +86,20 @@ function tag(element: Element): string { return element.tagName.toUpperCase() } +/** HTML-AAM: a header outside main, article, aside and section is the site banner. */ +function isBanner(element: Element): boolean { + return ( + tag(element) === 'HEADER' && + element.closest('main, article, aside, section') === null + ) +} + function isDropped(element: Element): boolean { return ( DROPPED_TAGS.has(tag(element)) || - element.getAttribute('aria-hidden') === 'true' + isBanner(element) || + element.getAttribute('aria-hidden') === 'true' || + element.hasAttribute('data-twin-omit') ) } diff --git a/apps/website/src/pages/workshop/models/[slug].astro b/apps/website/src/pages/workshop/models/[slug].astro index 82abb73437a..0efa2666786 100644 --- a/apps/website/src/pages/workshop/models/[slug].astro +++ b/apps/website/src/pages/workshop/models/[slug].astro @@ -47,11 +47,6 @@ const { model, related } = Astro.props - {/* - A div, not a header. `markdown-twin.ts` drops HEADER along with the - site chrome, so wrapping the hero in one leaves every model's llms.txt - entry with a title and nothing else. The h1 still carries the heading. - */}

{model.provider}