From 51b30f761f8006a1384b608354f54d4785ae7992 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Mon, 5 Oct 2026 20:21:38 +0530 Subject: [PATCH 1/5] feat(website): describe the models hub as a collection of model pages --- apps/website/src/routes/models/index.astro | 22 ++++++- apps/website/src/utils/modelJsonLd.test.ts | 77 +++++++++++++++++++++- apps/website/src/utils/modelJsonLd.ts | 44 ++++++++++++- 3 files changed, 140 insertions(+), 3 deletions(-) diff --git a/apps/website/src/routes/models/index.astro b/apps/website/src/routes/models/index.astro index d43c1a2ca44..bc2e39b7d8b 100644 --- a/apps/website/src/routes/models/index.astro +++ b/apps/website/src/routes/models/index.astro @@ -3,6 +3,8 @@ import BaseLayout from '@/layouts/BaseLayout.astro' import { workshopModels } from '@/config/workshop-browse-content' import ModelsPage from '@/components/workshop/ModelsPage.vue' import ModelsShowcase from '@/components/models/ModelsShowcase.astro' +import { pageContext } from '@/utils/jsonLd' +import { modelsHubJsonLd } from '@/utils/modelJsonLd' import { modelsHubMeta } from './models-hub-meta' import { modelsByProvider } from './models-directory' @@ -11,9 +13,27 @@ const directory = modelsByProvider( workshopModels, Astro.locals.t('workshop.filter.other') ) +const { siteUrl, url } = pageContext( + Astro.site, + Astro.url.pathname, + Astro.currentLocale +) +const jsonLd = modelsHubJsonLd({ + models: directory.flatMap((group) => group.models), + url, + siteUrl +}) --- - + diff --git a/apps/website/src/utils/modelJsonLd.test.ts b/apps/website/src/utils/modelJsonLd.test.ts index 5e6549f43f2..c31f48e2316 100644 --- a/apps/website/src/utils/modelJsonLd.test.ts +++ b/apps/website/src/utils/modelJsonLd.test.ts @@ -1,12 +1,15 @@ import { describe, expect, it } from 'vitest' import { MODEL_DEVELOPERS, modelDeveloper } from '@/config/model-vendors' +import { modelsUrlKind } from '@/config/models-url-registry' +import { workshopModels } from '@/config/workshop-browse-content' import { getWorkshopPageDetail, workshopPagePaths } from '@/config/workshop-page-content' import type { JsonLdNode } from './jsonLd' -import { modelPageJsonLd } from './modelJsonLd' +import { modelPageJsonLd, modelsHubJsonLd } from './modelJsonLd' +import { modelsByProvider } from '@/routes/models/models-directory' const siteUrl = 'https://comfy.org' const url = 'https://comfy.org/hub/models/example/' @@ -137,3 +140,75 @@ describe('MODEL_DEVELOPERS', () => { if (developer?.wikidata) expect(developer.wikidata).toMatch(/^Q\d+$/) }) }) + +describe('modelsHubJsonLd', () => { + const hubUrl = 'https://comfy.org/hub/models/' + const directoryModels = modelsByProvider(workshopModels, 'Other').flatMap( + (group) => group.models + ) + const directoryUrls = directoryModels.flatMap(({ href }) => + href === undefined ? [] : [`${siteUrl}${href}`] + ) + + function listedUrls(models: Parameters[0]['models']) { + return modelsHubJsonLd({ + models, + url: hubUrl, + siteUrl + }).extraJsonLd.flatMap(({ itemListElement }) => + Array.isArray(itemListElement) + ? itemListElement.map((element: { url: string }) => element.url) + : [] + ) + } + + it('lists every directory link, in the order the directory shows them', () => { + const { pageType, mainEntityId, extraJsonLd } = modelsHubJsonLd({ + models: directoryModels, + url: hubUrl, + siteUrl + }) + expect(directoryUrls.length).toBeGreaterThan(0) + expect(pageType).toBe('CollectionPage') + expect(mainEntityId).toBe(`${hubUrl}#itemlist`) + expect(extraJsonLd[0]).toMatchObject({ + '@type': 'ItemList', + numberOfItems: directoryUrls.length + }) + expect(listedUrls(directoryModels)).toEqual(directoryUrls) + }) + + it('lists only absolute, unique model page URLs from the registry', () => { + const urls = listedUrls(directoryModels) + expect(new Set(urls).size).toBe(urls.length) + for (const listed of urls) { + const { origin, pathname } = new URL(listed) + expect(origin).toBe(siteUrl) + expect(pathname).toMatch(/\/$/) + expect(modelsUrlKind(pathname)).toBe('model') + } + }) + + it('leaves out links that are not indexable model pages', () => { + const [listedModel] = directoryModels + expect( + listedUrls([ + { name: 'No page' }, + { name: 'Workflow', href: '/hub/workflows/example/' }, + { name: 'Unknown', href: '/hub/models/not-a-model/' }, + listedModel + ]) + ).toEqual([`${siteUrl}${listedModel.href}`]) + }) + + it('keeps the Home > Models breadcrumb but drops the list when nothing is listed', () => { + expect(modelsHubJsonLd({ models: [], url: hubUrl, siteUrl })).toEqual({ + pageType: 'CollectionPage', + breadcrumbs: [ + { name: 'Home', url: 'https://comfy.org/' }, + { name: 'Models' } + ], + extraJsonLd: [] + }) + }) +}) diff --git a/apps/website/src/utils/modelJsonLd.ts b/apps/website/src/utils/modelJsonLd.ts index 2a9f46c51ee..0731c7ae087 100644 --- a/apps/website/src/utils/modelJsonLd.ts +++ b/apps/website/src/utils/modelJsonLd.ts @@ -1,8 +1,14 @@ +import { isIndexableModelPage } from '@/config/indexing' import type { ModelDeveloper } from '@/config/model-vendors' import { getRoutes } from '@/config/routes' import { t } from '@/i18n/translations' import type { Crumb, JsonLdNode } from './jsonLd' -import { jsonLdId, organizationId, softwareApplicationNode } from './jsonLd' +import { + itemListNode, + jsonLdId, + organizationId, + softwareApplicationNode +} from './jsonLd' interface ModelPageJsonLdInput { model: { @@ -91,3 +97,39 @@ export function modelPageJsonLd({ ] } } + +interface ModelsHubJsonLdInput { + /** The directory's models, in the order the page lists them. */ + models: readonly { name: string; href?: string }[] + url: string + siteUrl: string +} + +export function modelsHubJsonLd({ + models, + url, + siteUrl +}: ModelsHubJsonLdInput): { + pageType: 'CollectionPage' + mainEntityId?: string + breadcrumbs: Crumb[] + extraJsonLd: JsonLdNode[] +} { + const listed = models.flatMap(({ name, href }) => + href !== undefined && isIndexableModelPage(href) + ? [{ name, url: `${siteUrl}${href}` }] + : [] + ) + const breadcrumbs = [ + { name: t('breadcrumb.home'), url: `${siteUrl}/` }, + { name: t('workshop.title') } + ] + if (listed.length === 0) + return { pageType: 'CollectionPage', breadcrumbs, extraJsonLd: [] } + return { + pageType: 'CollectionPage', + mainEntityId: jsonLdId(url, 'itemlist'), + breadcrumbs, + extraJsonLd: [itemListNode(url, t('workshop.title'), listed)] + } +} From e6ffc431b7464bfe4b3aec493df72ebb1d37d761 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Mon, 5 Oct 2026 21:34:45 +0530 Subject: [PATCH 2/5] fix(website): list only model pages in the models hub ItemList Require the model kind before the launch gate so a launched workflow page can never enter the list, resolve item URLs with absoluteUrl, and take the launch state as input so the tests cover the gate instead of today's state. --- apps/website/src/utils/modelJsonLd.test.ts | 73 ++++++++++++++++------ apps/website/src/utils/modelJsonLd.ts | 20 +++++- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/apps/website/src/utils/modelJsonLd.test.ts b/apps/website/src/utils/modelJsonLd.test.ts index c31f48e2316..48f3d04ea9e 100644 --- a/apps/website/src/utils/modelJsonLd.test.ts +++ b/apps/website/src/utils/modelJsonLd.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { MODEL_DEVELOPERS, modelDeveloper } from '@/config/model-vendors' -import { modelsUrlKind } from '@/config/models-url-registry' +import { modelsUrlKind, modelsUrlPaths } from '@/config/models-url-registry' import { workshopModels } from '@/config/workshop-browse-content' import { getWorkshopPageDetail, @@ -149,12 +149,20 @@ describe('modelsHubJsonLd', () => { const directoryUrls = directoryModels.flatMap(({ href }) => href === undefined ? [] : [`${siteUrl}${href}`] ) - - function listedUrls(models: Parameters[0]['models']) { + const [workflowPath] = modelsUrlPaths('workflow') + + function listedUrls( + models: Parameters[0]['models'], + launch: Pick< + Parameters[0], + 'launched' | 'workflowsLaunched' + > = { launched: 'all', workflowsLaunched: false } + ) { return modelsHubJsonLd({ models, url: hubUrl, - siteUrl + siteUrl, + ...launch }).extraJsonLd.flatMap(({ itemListElement }) => Array.isArray(itemListElement) ? itemListElement.map((element: { url: string }) => element.url) @@ -166,7 +174,8 @@ describe('modelsHubJsonLd', () => { const { pageType, mainEntityId, extraJsonLd } = modelsHubJsonLd({ models: directoryModels, url: hubUrl, - siteUrl + siteUrl, + launched: 'all' }) expect(directoryUrls.length).toBeGreaterThan(0) expect(pageType).toBe('CollectionPage') @@ -181,26 +190,54 @@ describe('modelsHubJsonLd', () => { it('lists only absolute, unique model page URLs from the registry', () => { const urls = listedUrls(directoryModels) expect(new Set(urls).size).toBe(urls.length) - for (const listed of urls) { - const { origin, pathname } = new URL(listed) - expect(origin).toBe(siteUrl) - expect(pathname).toMatch(/\/$/) - expect(modelsUrlKind(pathname)).toBe('model') - } + expect( + urls.map((listed) => { + const { origin, pathname } = new URL(listed) + return { + origin, + trailingSlash: pathname.endsWith('/'), + kind: modelsUrlKind(pathname) + } + }) + ).toEqual( + urls.map(() => ({ origin: siteUrl, trailingSlash: true, kind: 'model' })) + ) }) - it('leaves out links that are not indexable model pages', () => { + it('leaves out links that are not model pages, even with workflows launched', () => { const [listedModel] = directoryModels + expect(workflowPath).toBeDefined() expect( - listedUrls([ - { name: 'No page' }, - { name: 'Workflow', href: '/hub/workflows/example/' }, - { name: 'Unknown', href: '/hub/models/not-a-model/' }, - listedModel - ]) + listedUrls( + [ + { name: 'No page' }, + { name: 'Workflow', href: workflowPath }, + { name: 'Unknown', href: '/hub/models/not-a-model/' }, + listedModel + ], + { launched: 'all', workflowsLaunched: true } + ) ).toEqual([`${siteUrl}${listedModel.href}`]) }) + it('lists only the model pages the launch keeps', () => { + const [kept] = directoryModels + const dropped = directoryModels + .filter(({ routerId }) => routerId !== kept.routerId) + .slice(0, 1) + expect(dropped).toHaveLength(1) + expect( + listedUrls([kept, ...dropped], { launched: new Set([kept.routerId]) }) + ).toEqual([`${siteUrl}${kept.href}`]) + }) + + it('resolves a link without a trailing slash to the canonical page URL', () => { + const [model] = directoryModels + expect( + listedUrls([{ name: model.name, href: model.href?.replace(/\/$/, '') }]) + ).toEqual([`${siteUrl}${model.href}`]) + }) + it('keeps the Home > Models breadcrumb but drops the list when nothing is listed', () => { expect(modelsHubJsonLd({ models: [], url: hubUrl, siteUrl })).toEqual({ pageType: 'CollectionPage', diff --git a/apps/website/src/utils/modelJsonLd.ts b/apps/website/src/utils/modelJsonLd.ts index 0731c7ae087..d93ccb0264c 100644 --- a/apps/website/src/utils/modelJsonLd.ts +++ b/apps/website/src/utils/modelJsonLd.ts @@ -1,9 +1,16 @@ import { isIndexableModelPage } from '@/config/indexing' +import { + launchedModelPages, + launchedWorkflowPages +} from '@/config/model-page-launch' +import type { ModelPageLaunch } from '@/config/model-page-launch' import type { ModelDeveloper } from '@/config/model-vendors' +import { modelsUrlKind } from '@/config/models-url-registry' import { getRoutes } from '@/config/routes' import { t } from '@/i18n/translations' import type { Crumb, JsonLdNode } from './jsonLd' import { + absoluteUrl, itemListNode, jsonLdId, organizationId, @@ -103,21 +110,28 @@ interface ModelsHubJsonLdInput { models: readonly { name: string; href?: string }[] url: string siteUrl: string + launched?: ModelPageLaunch + workflowsLaunched?: boolean } export function modelsHubJsonLd({ models, url, - siteUrl + siteUrl, + launched = launchedModelPages, + workflowsLaunched = launchedWorkflowPages }: ModelsHubJsonLdInput): { pageType: 'CollectionPage' mainEntityId?: string breadcrumbs: Crumb[] extraJsonLd: JsonLdNode[] } { + const site = new URL(siteUrl) const listed = models.flatMap(({ name, href }) => - href !== undefined && isIndexableModelPage(href) - ? [{ name, url: `${siteUrl}${href}` }] + href !== undefined && + modelsUrlKind(href) === 'model' && + isIndexableModelPage(href, launched, workflowsLaunched) + ? [{ name, url: absoluteUrl(site, href) }] : [] ) const breadcrumbs = [ From dceb64a321df666edc74f16cea70ff9dcb55c67c Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Tue, 6 Oct 2026 14:06:34 +0530 Subject: [PATCH 3/5] refactor(website): drop the inert workflowsLaunched parameter from modelsHubJsonLd The model-kind guard already excludes workflow pages, so the flag could not change the list. The workflow test now launches workflow pages through the launch config, so it fails if the kind guard is removed. --- apps/website/src/utils/modelJsonLd.test.ts | 48 +++++++++++++--------- apps/website/src/utils/modelJsonLd.ts | 11 ++--- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/apps/website/src/utils/modelJsonLd.test.ts b/apps/website/src/utils/modelJsonLd.test.ts index 48f3d04ea9e..ff87b12c039 100644 --- a/apps/website/src/utils/modelJsonLd.test.ts +++ b/apps/website/src/utils/modelJsonLd.test.ts @@ -1,5 +1,6 @@ -import { describe, expect, it } from 'vitest' +import { describe, expect, it, onTestFinished, vi } from 'vitest' +import type { ModelPageLaunch } from '@/config/model-page-launch' import { MODEL_DEVELOPERS, modelDeveloper } from '@/config/model-vendors' import { modelsUrlKind, modelsUrlPaths } from '@/config/models-url-registry' import { workshopModels } from '@/config/workshop-browse-content' @@ -11,6 +12,17 @@ import type { JsonLdNode } from './jsonLd' import { modelPageJsonLd, modelsHubJsonLd } from './modelJsonLd' import { modelsByProvider } from '@/routes/models/models-directory' +const launch = vi.hoisted( + (): { + launchedModelPages: ModelPageLaunch + launchedWorkflowPages: boolean + } => ({ + launchedModelPages: 'all', + launchedWorkflowPages: false + }) +) +vi.mock(import('@/config/model-page-launch'), () => launch) + const siteUrl = 'https://comfy.org' const url = 'https://comfy.org/hub/models/example/' @@ -153,16 +165,13 @@ describe('modelsHubJsonLd', () => { function listedUrls( models: Parameters[0]['models'], - launch: Pick< - Parameters[0], - 'launched' | 'workflowsLaunched' - > = { launched: 'all', workflowsLaunched: false } + launched: ModelPageLaunch = 'all' ) { return modelsHubJsonLd({ models, url: hubUrl, siteUrl, - ...launch + launched }).extraJsonLd.flatMap(({ itemListElement }) => Array.isArray(itemListElement) ? itemListElement.map((element: { url: string }) => element.url) @@ -204,19 +213,20 @@ describe('modelsHubJsonLd', () => { ) }) - it('leaves out links that are not model pages, even with workflows launched', () => { + it('leaves out a launched workflow page and links that are not model pages', () => { const [listedModel] = directoryModels expect(workflowPath).toBeDefined() + launch.launchedWorkflowPages = true + onTestFinished(() => { + launch.launchedWorkflowPages = false + }) expect( - listedUrls( - [ - { name: 'No page' }, - { name: 'Workflow', href: workflowPath }, - { name: 'Unknown', href: '/hub/models/not-a-model/' }, - listedModel - ], - { launched: 'all', workflowsLaunched: true } - ) + listedUrls([ + { name: 'No page' }, + { name: 'Workflow', href: workflowPath }, + { name: 'Unknown', href: '/hub/models/not-a-model/' }, + listedModel + ]) ).toEqual([`${siteUrl}${listedModel.href}`]) }) @@ -226,9 +236,9 @@ describe('modelsHubJsonLd', () => { .filter(({ routerId }) => routerId !== kept.routerId) .slice(0, 1) expect(dropped).toHaveLength(1) - expect( - listedUrls([kept, ...dropped], { launched: new Set([kept.routerId]) }) - ).toEqual([`${siteUrl}${kept.href}`]) + expect(listedUrls([kept, ...dropped], new Set([kept.routerId]))).toEqual([ + `${siteUrl}${kept.href}` + ]) }) it('resolves a link without a trailing slash to the canonical page URL', () => { diff --git a/apps/website/src/utils/modelJsonLd.ts b/apps/website/src/utils/modelJsonLd.ts index d93ccb0264c..15e1bf703af 100644 --- a/apps/website/src/utils/modelJsonLd.ts +++ b/apps/website/src/utils/modelJsonLd.ts @@ -1,8 +1,5 @@ import { isIndexableModelPage } from '@/config/indexing' -import { - launchedModelPages, - launchedWorkflowPages -} from '@/config/model-page-launch' +import { launchedModelPages } from '@/config/model-page-launch' import type { ModelPageLaunch } from '@/config/model-page-launch' import type { ModelDeveloper } from '@/config/model-vendors' import { modelsUrlKind } from '@/config/models-url-registry' @@ -111,15 +108,13 @@ interface ModelsHubJsonLdInput { url: string siteUrl: string launched?: ModelPageLaunch - workflowsLaunched?: boolean } export function modelsHubJsonLd({ models, url, siteUrl, - launched = launchedModelPages, - workflowsLaunched = launchedWorkflowPages + launched = launchedModelPages }: ModelsHubJsonLdInput): { pageType: 'CollectionPage' mainEntityId?: string @@ -130,7 +125,7 @@ export function modelsHubJsonLd({ const listed = models.flatMap(({ name, href }) => href !== undefined && modelsUrlKind(href) === 'model' && - isIndexableModelPage(href, launched, workflowsLaunched) + isIndexableModelPage(href, launched) ? [{ name, url: absoluteUrl(site, href) }] : [] ) From 3c3d6c26f482ea917eb4e8f2520705aa44f85e87 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Tue, 6 Oct 2026 14:30:49 +0530 Subject: [PATCH 4/5] test(website): fail the build check when the models hub loses its JSON-LD check:models-html now reads dist/hub/models/index.html and requires one CollectionPage, one BreadcrumbList and one ItemList. The ItemList must list the rendered directory links that the launch keeps, with the same count and order. --- apps/website/scripts/check-models-html.ts | 19 ++++- .../website/scripts/models-html-audit.test.ts | 82 ++++++++++++++++++- apps/website/scripts/models-html-audit.ts | 58 +++++++++++++ 3 files changed, 155 insertions(+), 4 deletions(-) diff --git a/apps/website/scripts/check-models-html.ts b/apps/website/scripts/check-models-html.ts index 500afc8fde4..55aa2a85afe 100644 --- a/apps/website/scripts/check-models-html.ts +++ b/apps/website/scripts/check-models-html.ts @@ -1,10 +1,16 @@ import { readFileSync } from 'node:fs' import { join } from 'node:path' +import { isIndexableModelPage } from '@/config/indexing' +import { getRoutes } from '@/config/routes' import { workshopModels } from '@/config/workshop-browse-content' import { getRouterWorkshopModelDetail } from '@/config/workshop-router-content' import { auditExampleGallery } from './models-gallery-audit' -import { auditMediaLabels, auditModelPage } from './models-html-audit' +import { + auditMediaLabels, + auditModelPage, + auditModelsHub +} from './models-html-audit' const DIST = join(process.cwd(), 'dist') @@ -18,7 +24,13 @@ const pagedModels = workshopModels.flatMap(({ href, name, slug }) => href === undefined ? [] : [{ href, name, slug }] ) -const errors = pagedModels.flatMap((model) => { +const hubPath = getRoutes().workshop +const hubErrors = auditModelsHub( + readFileSync(join(DIST, hubPath, 'index.html'), 'utf-8'), + (href) => isIndexableModelPage(href) +).map((error) => `${hubPath}: ${error}`) + +const modelErrors = pagedModels.flatMap((model) => { const html = readFileSync(join(DIST, model.href, 'index.html'), 'utf-8') return [ ...auditModelPage(html, model.name), @@ -26,6 +38,7 @@ const errors = pagedModels.flatMap((model) => { ...auditExampleGallery(html, examplesOf(model.slug).length) ].map((error) => `${model.href}: ${error}`) }) +const errors = [...hubErrors, ...modelErrors] if (errors.length > 0) { console.error(`[models-html] ${errors.length} problem(s):`) @@ -33,5 +46,5 @@ if (errors.length > 0) { process.exit(1) } console.warn( - `[models-html] ${pagedModels.length} model pages carry their model in the HTML.` + `[models-html] ${pagedModels.length} model pages carry their model in the HTML; ${hubPath} lists them in its JSON-LD.` ) diff --git a/apps/website/scripts/models-html-audit.test.ts b/apps/website/scripts/models-html-audit.test.ts index 091ddbaa43a..07f651fad6c 100644 --- a/apps/website/scripts/models-html-audit.test.ts +++ b/apps/website/scripts/models-html-audit.test.ts @@ -1,6 +1,10 @@ import { describe, expect, it } from 'vitest' -import { auditMediaLabels, auditModelPage } from './models-html-audit' +import { + auditMediaLabels, + auditModelPage, + auditModelsHub +} from './models-html-audit' const showcase = '

Grok Imagine in ComfyUI

' const related = (cards: string) => @@ -84,3 +88,79 @@ describe(auditMediaLabels, () => { expect(auditMediaLabels(html)).toEqual(errors) }) }) + +describe(auditModelsHub, () => { + const graph = (...nodes: object[]) => + `` + const itemList = (...paths: string[]) => ({ + '@type': 'ItemList', + numberOfItems: paths.length, + itemListElement: paths.map((path, index) => ({ + '@type': 'ListItem', + position: index + 1, + url: `https://comfy.org${path}` + })) + }) + const directory = (...paths: string[]) => + `
    ${paths.map((path) => `
  • Model
  • `).join('')}
` + const collection = { '@type': 'CollectionPage' } + const breadcrumbs = { '@type': 'BreadcrumbList' } + const everyLink = () => true + + it.for([ + { + name: 'a collection listing every directory link in order', + html: + graph(collection, breadcrumbs, itemList('/a/', '/b/')) + + directory('/a/', '/b/'), + errors: [] + }, + { + name: 'a page that lost its collection markup', + html: graph({ '@type': 'WebPage' }, breadcrumbs) + directory('/a/'), + errors: [ + 'expected 1 CollectionPage, found 0', + 'expected 1 ItemList, found 0' + ] + }, + { + name: 'a list that counts fewer models than the directory links', + html: + graph(collection, breadcrumbs, itemList('/a/')) + + directory('/a/', '/b/'), + errors: [ + 'ItemList numberOfItems 1 does not match 2 directory links', + 'ItemList URLs differ from the directory links or their order' + ] + }, + { + name: 'a list in a different order from the directory', + html: + graph(collection, breadcrumbs, itemList('/b/', '/a/')) + + directory('/a/', '/b/'), + errors: ['ItemList URLs differ from the directory links or their order'] + }, + { + name: 'an empty directory', + html: graph(collection, breadcrumbs, itemList('/a/')), + errors: [ + 'expected 0 ItemList, found 1', + 'renders no model links in the directory', + 'ItemList numberOfItems 1 does not match 0 directory links', + 'ItemList URLs differ from the directory links or their order' + ] + } + ])('$name', ({ html, errors }) => { + expect(auditModelsHub(html, everyLink)).toEqual(errors) + }) + + it('expects only the directory links the launch keeps', () => { + expect( + auditModelsHub( + graph(collection, breadcrumbs, itemList('/a/')) + + directory('/a/', '/b/'), + (href) => href === '/a/' + ) + ).toEqual([]) + }) +}) diff --git a/apps/website/scripts/models-html-audit.ts b/apps/website/scripts/models-html-audit.ts index ceee30dbfa5..82ef85d1558 100644 --- a/apps/website/scripts/models-html-audit.ts +++ b/apps/website/scripts/models-html-audit.ts @@ -65,3 +65,61 @@ export function auditMediaLabels(html: string): string[] { }) return [...images, ...videos] } + +const JSON_LD_BLOCK = + /]*type="application\/ld\+json"[^>]*>([\s\S]*?)<\/script>/g + +interface JsonLdNode { + '@type'?: string + numberOfItems?: number + itemListElement?: { url: string }[] +} + +function jsonLdNodes(html: string): JsonLdNode[] { + return [...html.matchAll(JSON_LD_BLOCK)].flatMap(([, json]) => { + const parsed = JSON.parse(json) + return parsed['@graph'] ?? [parsed] + }) +} + +function directoryHrefs(html: string): string[] { + const directory = + html.split('data-testid="models-directory"')[1]?.split('')[0] ?? + '' + return [...directory.matchAll(/]*\shref="([^"]*)"/g)].map( + ([, href]) => href + ) +} + +export function auditModelsHub( + html: string, + isListed: (href: string) => boolean +): string[] { + const nodes = jsonLdNodes(html) + const ofType = (type: string) => + nodes.filter((node) => node['@type'] === type) + const links = directoryHrefs(html) + const expected = links.filter(isListed) + const expectedCounts = { + CollectionPage: 1, + BreadcrumbList: 1, + ItemList: expected.length > 0 ? 1 : 0 + } + const errors = Object.entries(expectedCounts).flatMap(([type, count]) => { + const found = ofType(type).length + return found === count ? [] : [`expected ${count} ${type}, found ${found}`] + }) + if (links.length === 0) errors.push('renders no model links in the directory') + const itemList = ofType('ItemList').at(0) + if (!itemList) return errors + const listed = (itemList.itemListElement ?? []).map( + ({ url }) => new URL(url).pathname + ) + if (itemList.numberOfItems !== expected.length) + errors.push( + `ItemList numberOfItems ${itemList.numberOfItems} does not match ${expected.length} directory links` + ) + if (listed.join() !== expected.join()) + errors.push('ItemList URLs differ from the directory links or their order') + return errors +} From dc0e6bde70f68d8bc326e348f33f4cdef86bcc52 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Tue, 6 Oct 2026 16:06:02 +0530 Subject: [PATCH 5/5] fix(website): compare full ItemList URLs in the models hub audit Compare each ItemList URL with the absolute comfy.org URL of its directory link, so an off-origin URL with the same path fails check:models-html. --- apps/website/scripts/models-html-audit.test.ts | 15 +++++++++++++++ apps/website/scripts/models-html-audit.ts | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/website/scripts/models-html-audit.test.ts b/apps/website/scripts/models-html-audit.test.ts index 07f651fad6c..8b40199465f 100644 --- a/apps/website/scripts/models-html-audit.test.ts +++ b/apps/website/scripts/models-html-audit.test.ts @@ -140,6 +140,21 @@ describe(auditModelsHub, () => { directory('/a/', '/b/'), errors: ['ItemList URLs differ from the directory links or their order'] }, + { + name: 'a list on another origin with the same paths', + html: + graph(collection, breadcrumbs, { + ...itemList('/a/'), + itemListElement: [ + { + '@type': 'ListItem', + position: 1, + url: 'https://other.example/a/' + } + ] + }) + directory('/a/'), + errors: ['ItemList URLs differ from the directory links or their order'] + }, { name: 'an empty directory', html: graph(collection, breadcrumbs, itemList('/a/')), diff --git a/apps/website/scripts/models-html-audit.ts b/apps/website/scripts/models-html-audit.ts index 82ef85d1558..d8b0b00810c 100644 --- a/apps/website/scripts/models-html-audit.ts +++ b/apps/website/scripts/models-html-audit.ts @@ -66,6 +66,7 @@ export function auditMediaLabels(html: string): string[] { return [...images, ...videos] } +const SITE_ORIGIN = 'https://comfy.org' const JSON_LD_BLOCK = /]*type="application\/ld\+json"[^>]*>([\s\S]*?)<\/script>/g @@ -112,14 +113,13 @@ export function auditModelsHub( if (links.length === 0) errors.push('renders no model links in the directory') const itemList = ofType('ItemList').at(0) if (!itemList) return errors - const listed = (itemList.itemListElement ?? []).map( - ({ url }) => new URL(url).pathname - ) + const listed = (itemList.itemListElement ?? []).map(({ url }) => url) + const expectedUrls = expected.map((href) => new URL(href, SITE_ORIGIN).href) if (itemList.numberOfItems !== expected.length) errors.push( `ItemList numberOfItems ${itemList.numberOfItems} does not match ${expected.length} directory links` ) - if (listed.join() !== expected.join()) + if (listed.join() !== expectedUrls.join()) errors.push('ItemList URLs differ from the directory links or their order') return errors }