Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/website/src/config/workshop-workflow-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { assert, describe, expect, it } from 'vitest'
import displayJson from '../content/workshop-display.json'
import categories from '../content/workshop-workflow-categories.json'
import { workshopDisplayEntriesSchema } from '../content/workshop-display.schema'
import { modelTitle } from '../lib/workshop/model-title'
import { workshopExecutionId } from './models-catalogue'
import { initialWorkshopPageState } from './workshop-page-state'
import { urlUploadField, validateForm } from './workshop-playground'
Expand Down Expand Up @@ -264,3 +265,10 @@ describe('curated workflow pages', () => {
}
)
})

describe('workshop pages', () => {
it('gives every model and workflow page its own title', () => {
const titles = workshopPages.map((model) => modelTitle(model))
expect(new Set(titles).size).toBe(titles.length)
})
})
12 changes: 12 additions & 0 deletions apps/website/src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9755,6 +9755,18 @@ Enterprise`
'workshop.model.tabs.playground': { en: 'Playground', 'zh-CN': 'Playground' },
'workshop.model.tabs.api': { en: 'API', 'zh-CN': 'API' },
'workshop.model.tabs.details': { en: 'Details', 'zh-CN': '详情' },
'workshop.model.meta.title': {
en: '{name} API & Playground - Comfy',
'zh-CN': '{name} API 与 Playground - Comfy'
},
'workshop.model.meta.titleUnbranded': {
en: '{name} API & Playground',
'zh-CN': '{name} API 与 Playground'
},
'workshop.model.meta.titleApi': {
en: '{name} API - Comfy',
'zh-CN': '{name} API - Comfy'
},
'workshop.model.relatedProvider': {
en: 'More from {provider}',
'zh-CN': '{provider} 的更多模型'
Expand Down
69 changes: 69 additions & 0 deletions apps/website/src/lib/workshop/model-title.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, expect, it } from 'vitest'

import type { Locale } from '../../i18n/translations'
import { t } from '../../i18n/translations'
import { modelTitle } from './model-title'

const nameOfLength = (length: number) => 'x'.repeat(length)
const full = (name: string, locale: Locale = 'en') =>
t('workshop.model.meta.title', locale, { name })
const unbranded = (name: string) =>
t('workshop.model.meta.titleUnbranded', 'en', { name })
const apiOnly = (name: string) =>
t('workshop.model.meta.titleApi', 'en', { name })

describe('modelTitle', () => {
it.for([
{
name: 'names the API and playground when they fit',
modelName: 'Seedream 4.0',
expected: full('Seedream 4.0')
},
{
name: 'keeps the full title at exactly the limit',
modelName: nameOfLength(35),
expected: full(nameOfLength(35))
},
{
name: 'drops the brand before the playground',
modelName: nameOfLength(36),
expected: unbranded(nameOfLength(36))
},
{
name: 'keeps the unbranded title at exactly the limit',
modelName: nameOfLength(43),
expected: unbranded(nameOfLength(43))
},
{
name: 'falls back to the API title when the playground no longer fits',
modelName: nameOfLength(44),
expected: apiOnly(nameOfLength(44))
},
{
name: 'keeps the whole name in the API title at exactly the limit',
modelName: nameOfLength(48),
expected: apiOnly(nameOfLength(48))
},
{
name: 'shortens a longer name at a word boundary',
modelName:
'Seed Audio 1.0 Multilingual Text-to-Speech with Voice Cloning Preview',
expected: apiOnly('Seed Audio 1.0 Multilingual Text-to-Speech with…')
},
{
name: 'cuts a long name with no spaces to fit',
modelName: nameOfLength(70),
expected: apiOnly(`${nameOfLength(47)}…`)
},
{
name: 'writes the Chinese title with the Chinese conjunction',
locale: 'zh-CN' as const,
modelName: 'Seedream 4.0',
expected: full('Seedream 4.0', 'zh-CN')
}
])('$name', ({ modelName, locale, expected }) => {
const title = modelTitle({ name: modelName }, locale)
expect(title).toBe(expected)
expect(title.length).toBeLessThanOrEqual(60)
})
})
24 changes: 24 additions & 0 deletions apps/website/src/lib/workshop/model-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Locale } from '../../i18n/translations'
import { t } from '../../i18n/translations'

const TITLE_MAX = 60
Comment thread
benjcooley marked this conversation as resolved.
Resolved
const ELLIPSIS = '…'

function shortenAtWord(text: string, max: number) {
if (text.length <= max) return text
const limit = max - ELLIPSIS.length
const wordEnd = text.lastIndexOf(' ', limit)
return `${text.slice(0, wordEnd > 0 ? wordEnd : limit)}${ELLIPSIS}`
}

export function modelTitle(model: { name: string }, locale: Locale = 'en') {
const fitting = (
['workshop.model.meta.title', 'workshop.model.meta.titleUnbranded'] as const
)
.map((key) => t(key, locale, { name: model.name }))
.find((title) => title.length <= TITLE_MAX)
if (fitting) return fitting
const apiKey = 'workshop.model.meta.titleApi'
const nameBudget = TITLE_MAX - t(apiKey, locale, { name: '' }).length
return t(apiKey, locale, { name: shortenAtWord(model.name, nameBudget) })
}
3 changes: 2 additions & 1 deletion apps/website/src/routes/models/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ModelsPage from '../../components/workshop/ModelsPage.vue'
import ModelsShowcase from '../../components/models/ModelsShowcase.astro'
import { workshopPagePaths } from '../../config/workshop-page-content'
import { t } from '../../i18n/translations'
import { modelTitle } from '../../lib/workshop/model-title'
import { prepareModelPage } from './model-page'

export const getStaticPaths: GetStaticPaths = () =>
Expand All @@ -19,7 +20,7 @@ const { model } = page
---

<BaseLayout
title={`${model.name} · ${t('workshop.title')} - Comfy`}
title={modelTitle(model)}
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
Comment thread
benjcooley marked this conversation as resolved.
Resolved
description={t('workshop.model.meta.description', 'en', {
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
name: model.name
})}
Expand Down
Loading