[GIFs] Restore default alt text (#3893)
* restore default alt text * factor out gif alt logic + enable require alt text setting * rm console.log * don't prefill input + esc handling * typo * Nits * shorten user alt prefix * Remove unnecessary condition, rename for clarity * Add comment --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
parent
77e6c75a2c
commit
7d72dfb1cb
4 changed files with 84 additions and 20 deletions
36
src/lib/gif-alt-text.ts
Normal file
36
src/lib/gif-alt-text.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Kind of a hack. We needed some way to distinguish these.
|
||||
const USER_ALT_PREFIX = 'Alt: '
|
||||
const DEFAULT_ALT_PREFIX = 'ALT: '
|
||||
|
||||
export function createGIFDescription(
|
||||
tenorDescription: string,
|
||||
preferredAlt: string = '',
|
||||
) {
|
||||
preferredAlt = preferredAlt.trim()
|
||||
if (preferredAlt !== '') {
|
||||
return USER_ALT_PREFIX + preferredAlt
|
||||
} else {
|
||||
return DEFAULT_ALT_PREFIX + tenorDescription
|
||||
}
|
||||
}
|
||||
|
||||
export function parseAltFromGIFDescription(description: string): {
|
||||
isPreferred: boolean
|
||||
alt: string
|
||||
} {
|
||||
if (description.startsWith(USER_ALT_PREFIX)) {
|
||||
return {
|
||||
isPreferred: true,
|
||||
alt: description.replace(USER_ALT_PREFIX, ''),
|
||||
}
|
||||
} else if (description.startsWith(DEFAULT_ALT_PREFIX)) {
|
||||
return {
|
||||
isPreferred: false,
|
||||
alt: description.replace(DEFAULT_ALT_PREFIX, ''),
|
||||
}
|
||||
}
|
||||
return {
|
||||
isPreferred: false,
|
||||
alt: description,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue