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,
|
||||
ArrowPath,
|
||||
Sparkles,
|
||||
ChatBubbleBottomCenterText,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
@@ -20,6 +21,8 @@
|
||||
import { Button } from 'mono-svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { slide } from 'svelte/transition'
|
||||
import { feature } from '$lib/version'
|
||||
|
||||
export let edit = false
|
||||
|
||||
@@ -35,17 +38,21 @@
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail: string | undefined
|
||||
url: string | undefined
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text: string | undefined
|
||||
} = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
}
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
@@ -61,6 +68,8 @@
|
||||
data.body = editingPost.body ?? ''
|
||||
data.title = editingPost.name
|
||||
data.nsfw = editingPost.nsfw
|
||||
data.alt_text = editingPost.alt_text
|
||||
data.thumbnail = editingPost.thumbnail_url
|
||||
}
|
||||
|
||||
if (passedCommunity) {
|
||||
@@ -117,6 +126,8 @@
|
||||
url: data.url || undefined,
|
||||
post_id: editingPost.id,
|
||||
nsfw: data.nsfw,
|
||||
alt_text: data.alt_text,
|
||||
custom_thumbnail: data.thumbnail,
|
||||
})
|
||||
|
||||
if (!post) throw new Error('Failed to edit post')
|
||||
@@ -125,16 +136,14 @@
|
||||
|
||||
dispatcher('submit', post.post_view)
|
||||
} 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({
|
||||
community_id: data.community!.id,
|
||||
name: data.title,
|
||||
body: data.body,
|
||||
url: data.url,
|
||||
nsfw: data.nsfw,
|
||||
custom_thumbnail: data.thumbnail,
|
||||
alt_text: data.alt_text,
|
||||
})
|
||||
|
||||
if (!post) throw new Error('Failed to upload post')
|
||||
@@ -200,6 +209,8 @@
|
||||
title: '',
|
||||
}
|
||||
|
||||
let addAltText = false
|
||||
|
||||
$: generation.generatable = canGenerateTitle(data.url)
|
||||
</script>
|
||||
|
||||
@@ -295,6 +306,14 @@
|
||||
{$t('form.post.generateTitle')}
|
||||
{/if}
|
||||
</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
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
style="width: 38px; height: 38px; padding: 0;"
|
||||
@@ -304,6 +323,11 @@
|
||||
<Icon src={Photo} size="18" mini slot="prefix" />
|
||||
</Button>
|
||||
</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
|
||||
rows={8}
|
||||
label={$t('form.post.body')}
|
||||
|
||||
@@ -34,11 +34,11 @@
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 256)}
|
||||
loading="lazy"
|
||||
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]">
|
||||
<source
|
||||
@@ -66,8 +66,17 @@
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||
alt={post.alt_text ?? ''}
|
||||
/>
|
||||
</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>
|
||||
{/if}
|
||||
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
||||
|
||||
Reference in new issue
Block a user