Repository navigation
feat(website): lead model page titles with API & Playground #19366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2c0375
feat(website): lead model page titles with API & Playground
MaanilVerma 145200a
Merge remote-tracking branch 'origin/main' into maanil/fe-2936-model-…
MaanilVerma 623251a
fix(website): keep API & Playground in long model titles
MaanilVerma 352b0a7
test(website): check display-name uniqueness beside the page catalogue
MaanilVerma d697ab9
test(website): check page title uniqueness instead of display names
MaanilVerma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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) }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.