feat: add support for alt text
This commit is contained in:
1 parent
5226504765
commit
6d94b23faa
4 files changed
+42
-6
No files matched your search
@@ -10,6 +10,7 @@
|
|||||||
BookOpen,
|
BookOpen,
|
||||||
ArrowPath,
|
ArrowPath,
|
||||||
Sparkles,
|
Sparkles,
|
||||||
|
ChatBubbleBottomCenterText,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
@@ -20,6 +21,8 @@
|
|||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
import { feature } from '$lib/version'
|
||||||
|
|
||||||
export let edit = false
|
export let edit = false
|
||||||
|
|
||||||
@@ -35,17 +38,21 @@
|
|||||||
title: string
|
title: string
|
||||||
body: string
|
body: string
|
||||||
image: FileList | null
|
image: FileList | null
|
||||||
|
thumbnail: string | undefined
|
||||||
url: string | undefined
|
url: string | undefined
|
||||||
nsfw: boolean
|
nsfw: boolean
|
||||||
loading: boolean
|
loading: boolean
|
||||||
|
alt_text: string | undefined
|
||||||
} = {
|
} = {
|
||||||
community: null,
|
community: null,
|
||||||
title: '',
|
title: '',
|
||||||
body: '',
|
body: '',
|
||||||
image: null,
|
image: null,
|
||||||
|
thumbnail: undefined,
|
||||||
url: undefined,
|
url: undefined,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
alt_text: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
let saveDraft = edit ? false : true
|
let saveDraft = edit ? false : true
|
||||||
@@ -61,6 +68,8 @@
|
|||||||
data.body = editingPost.body ?? ''
|
data.body = editingPost.body ?? ''
|
||||||
data.title = editingPost.name
|
data.title = editingPost.name
|
||||||
data.nsfw = editingPost.nsfw
|
data.nsfw = editingPost.nsfw
|
||||||
|
data.alt_text = editingPost.alt_text
|
||||||
|
data.thumbnail = editingPost.thumbnail_url
|
||||||
}
|
}
|
||||||
|
|
||||||
if (passedCommunity) {
|
if (passedCommunity) {
|
||||||
@@ -117,6 +126,8 @@
|
|||||||
url: data.url || undefined,
|
url: data.url || undefined,
|
||||||
post_id: editingPost.id,
|
post_id: editingPost.id,
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
|
alt_text: data.alt_text,
|
||||||
|
custom_thumbnail: data.thumbnail,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!post) throw new Error('Failed to edit post')
|
if (!post) throw new Error('Failed to edit post')
|
||||||
@@ -125,16 +136,14 @@
|
|||||||
|
|
||||||
dispatcher('submit', post.post_view)
|
dispatcher('submit', post.post_view)
|
||||||
} else {
|
} else {
|
||||||
let image = data.image
|
|
||||||
? await uploadImage(data.image[0], $profile.instance, $profile.jwt)
|
|
||||||
: undefined
|
|
||||||
data.url = image || data.url || undefined
|
|
||||||
const post = await client().createPost({
|
const post = await client().createPost({
|
||||||
community_id: data.community!.id,
|
community_id: data.community!.id,
|
||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
url: data.url,
|
url: data.url,
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
|
custom_thumbnail: data.thumbnail,
|
||||||
|
alt_text: data.alt_text,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!post) throw new Error('Failed to upload post')
|
if (!post) throw new Error('Failed to upload post')
|
||||||
@@ -200,6 +209,8 @@
|
|||||||
title: '',
|
title: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let addAltText = false
|
||||||
|
|
||||||
$: generation.generatable = canGenerateTitle(data.url)
|
$: generation.generatable = canGenerateTitle(data.url)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -295,6 +306,14 @@
|
|||||||
{$t('form.post.generateTitle')}
|
{$t('form.post.generateTitle')}
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
on:click={() => (addAltText = !addAltText)}
|
||||||
|
style="width: 38px; height: 38px; padding: 0;"
|
||||||
|
class="flex-shrink-0"
|
||||||
|
title={$t('form.post.altText')}
|
||||||
|
>
|
||||||
|
<Icon src={ChatBubbleBottomCenterText} size="18" mini slot="prefix" />
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (uploadingImage = !uploadingImage)}
|
on:click={() => (uploadingImage = !uploadingImage)}
|
||||||
style="width: 38px; height: 38px; padding: 0;"
|
style="width: 38px; height: 38px; padding: 0;"
|
||||||
@@ -304,6 +323,11 @@
|
|||||||
<Icon src={Photo} size="18" mini slot="prefix" />
|
<Icon src={Photo} size="18" mini slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
{#if addAltText}
|
||||||
|
<div transition:slide={{ axis: 'y', duration: 150 }} class="w-full">
|
||||||
|
<TextInput label={$t('form.post.altText')} bind:value={data.alt_text} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
rows={8}
|
rows={8}
|
||||||
label={$t('form.post.body')}
|
label={$t('form.post.body')}
|
||||||
|
|||||||
@@ -34,11 +34,11 @@
|
|||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
<img
|
<img
|
||||||
src={bestImageURL(post, false, 256)}
|
src={bestImageURL(post, false, 256)}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl opacity-50"
|
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl opacity-50"
|
||||||
alt="the background blur"
|
|
||||||
/>
|
/>
|
||||||
<picture class="max-h-[inherit]">
|
<picture class="max-h-[inherit]">
|
||||||
<source
|
<source
|
||||||
@@ -66,8 +66,17 @@
|
|||||||
width={512}
|
width={512}
|
||||||
height={300}
|
height={300}
|
||||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||||
|
alt={post.alt_text ?? ''}
|
||||||
/>
|
/>
|
||||||
</picture>
|
</picture>
|
||||||
|
{#if post.alt_text}
|
||||||
|
<button
|
||||||
|
class="absolute bottom-0 left-0 text-sm m-2 bg-white dark:bg-zinc-900 px-3 py-1.5
|
||||||
|
rounded-full border border-slate-200 dark:border-zinc-800 shadow-lg text-left"
|
||||||
|
>
|
||||||
|
{post.alt_text}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</svelte:element>
|
</svelte:element>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
||||||
|
|||||||
@@ -119,7 +119,8 @@
|
|||||||
"body": "Body",
|
"body": "Body",
|
||||||
"nsfw": "NSFW",
|
"nsfw": "NSFW",
|
||||||
"generateTitle": "Generate Title",
|
"generateTitle": "Generate Title",
|
||||||
"uploadImage": "Upload Image"
|
"uploadImage": "Upload Image",
|
||||||
|
"altText": "Alt Text"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"displayName": "Display name",
|
"displayName": "Display name",
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ const FEATURES = {
|
|||||||
newTotp: '0.19.0',
|
newTotp: '0.19.0',
|
||||||
blockInstances: '0.19.0',
|
blockInstances: '0.19.0',
|
||||||
hidePosts: '0.19.4',
|
hidePosts: '0.19.4',
|
||||||
|
altText: '0.19.4',
|
||||||
|
customThumbnail: '0.19.4',
|
||||||
}
|
}
|
||||||
|
|
||||||
type Feature = keyof typeof FEATURES
|
type Feature = keyof typeof FEATURES
|
||||||
|
|||||||
Reference in new issue
Block a user