impr: make post semantics better

This commit is contained in:
Xylight committed 2024-09-03 17:05:22 -07:00
1 parent 6831a640c5
commit aea47580bf
13 files changed
+178 -163

No files matched your search

+7 -1
View File
@@ -83,6 +83,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<Material
element="article"
color={view != 'card' ? 'none' : 'distinct'}
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none group
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
@@ -160,7 +161,12 @@
{/if}
{/key}
{#if post.post.body && !post.post.nsfw && view != 'compact' && !hideBody && rule != 'hide'}
<PostBody body={post.post.body} {view} style="grid-area: body" />
<PostBody
element="section"
body={post.post.body}
{view}
style="grid-area: body"
/>
{/if}
{#if actions}
<PostActions on:hide bind:post style="grid-area: actions;" {view} />
@@ -116,7 +116,7 @@
{/await}
{/if}
<div
<footer
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
style={$$props.style ?? ''}
>
@@ -398,4 +398,4 @@
{/if}
{/if}
</Menu>
</div>
</footer>
@@ -7,6 +7,10 @@
export let body: string
export let view: View = 'cozy'
export let clickThrough = false
let htmlElement = 'div'
export { htmlElement as element }
let expanded = false
let element: Element
@@ -25,7 +29,8 @@
$: overflows = isOverflown(element, body)
</script>
<div
<svelte:element
this={htmlElement}
style={$$props.style ?? ''}
class="{!expanded
? `text-sm overflow-hidden
@@ -55,4 +60,4 @@ ${view == 'list' ? `max-h-24` : 'max-h-48'}`
/>
</Button>
{/if}
</div>
</svelte:element>
+15 -13
View File
@@ -105,7 +105,7 @@
@component
This component will build two different things: a post's meta block and the title.
-->
<div
<header
class="grid w-full meta {community
? 'grid-rows-2'
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
@@ -124,7 +124,7 @@
>
<Avatar
url={community.icon}
width={28}
width={32}
alt={community.name}
style="grid-area: avatar; height: 100%;"
class="flex-shrink-0"
@@ -159,16 +159,18 @@
style="grid-area: stats;"
>
{#if user}
<UserLink avatarSize={20} {user} avatar={!showCommunity}>
<svelte:fragment slot="badges">
{#if badges.moderator}
<ShieldIcon filled width={14} class="text-green-500" />
{/if}
{#if badges.admin}
<ShieldIcon filled width={14} class="text-red-500" />
{/if}
</svelte:fragment>
</UserLink>
<address>
<UserLink avatarSize={20} {user} avatar={!showCommunity}>
<svelte:fragment slot="badges">
{#if badges.moderator}
<ShieldIcon filled width={14} class="text-green-500" />
{/if}
{#if badges.admin}
<ShieldIcon filled width={14} class="text-red-500" />
{/if}
</svelte:fragment>
</UserLink>
</address>
{/if}
{#if published}
<RelativeDate date={published} class="flex-shrink-0" />
@@ -251,7 +253,7 @@
{/if}
<slot name="badges" />
</div>
</div>
</header>
{#if title && id}
<a
href="/post/{getInstance()}/{id}"
@@ -64,6 +64,8 @@
? ''
: '!text-inherit'} !text-inherit divide-x divide-slate-200 dark:divide-zinc-800
{loading ? 'animate-pulse opacity-75 pointer-events-none' : ''}"
role="group"
aria-label={$t('aria.vote.group')}
>
<button
on:click={() => castVote(vote == 1 ? 0 : 1)}
@@ -71,6 +73,8 @@
{vote == 1
? shouldShowVoteColor(vote, 'upvotes')
: 'hover:bg-slate-100 hover:dark:bg-zinc-800'}"
aria-pressed={vote == 1}
aria-label={$t('post.actions.vote.upvote')}
>
<Icon src={ChevronUp} size="20" micro />
<span class="grid text-sm">
@@ -79,6 +83,7 @@
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t('aria.vote.upvotes', { default: upvotes })}
>
<FormattedNumber number={upvotes} />
</span>
@@ -92,6 +97,8 @@
{vote == -1
? shouldShowVoteColor(vote, 'downvotes')
: 'hover:bg-slate-100 hover:dark:bg-zinc-800'}"
aria-pressed={vote == -1}
aria-label={$t('post.actions.vote.downvote')}
>
<Icon src={ChevronDown} size="20" micro />
<span class="grid text-sm">
@@ -100,6 +107,7 @@
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t('aria.vote.downvotes', { default: downvotes })}
>
<FormattedNumber number={downvotes} />
</span>
+2 -13
View File
@@ -12,19 +12,8 @@ export const bestImageURL = (
compact: boolean = true,
width: number = 1024
) => {
let fetchWidth =
width > 1024
? // -1 disables a small thumbnail
-1
: // set width to 512 if compact
compact
? 512
: // otherwise, just use the original width
width
if (post.thumbnail_url)
return optimizeImageURL(post.thumbnail_url, fetchWidth)
else if (post.url) return optimizeImageURL(post.url, fetchWidth)
if (post.thumbnail_url) return optimizeImageURL(post.thumbnail_url, width)
else if (post.url) return optimizeImageURL(post.url, width)
return post.url ?? ''
}
@@ -30,12 +30,12 @@
-->
{#if embed_title && view != 'compact'}
<Material
style="--img-url: {thumbnail_url}"
color="distinct"
class="flex flex-col-reverse sm:flex-row
overflow-hidden gap-4 embed-card z-0 relative
dark:border-t-zinc-800 border-opacity-80"
rounding="xl"
element="article"
>
{#if thumbnail_url}
<img
@@ -187,16 +187,4 @@
{/if}
</Button>
</div>
{#if thumbnail_url && view != 'compact'}
<a href={url} target="_blank">
<img
src={optimizeImageURL(thumbnail_url, 256)}
class="rounded-md max-w-72 w-full h-auto aspect-video object-cover bg-slate-200 dark:bg-zinc-800"
width={600}
height={400}
alt={embed_title ?? 'Embed prevented alt text'}
class:blur-3xl={nsfw}
/>
</a>
{/if}
{/if}
@@ -0,0 +1,94 @@
<script lang="ts">
import { userSettings, type View } from '$lib/settings'
import type { Post } from 'lemmy-js-client'
import { bestImageURL, postLink } from '../helpers'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { Button, modal } from 'mono-svelte'
import { onMount } from 'svelte'
export let post: Post
export let blur: boolean = false
let imageLoaded: boolean | null = null
onMount(() => {
imageLoaded = false
})
</script>
<!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:element
this={$userSettings.expandImages ? 'button' : 'a'}
href={postLink(post)}
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
data-sveltekit-preload-data="off"
aria-label={post.name}
on:click={() => showImage(bestImageURL(post, false, 2048))}
role="button"
tabindex="0"
>
<!-- svelte-ignore a11y-missing-attribute -->
<img
loading="lazy"
fetchpriority="auto"
src={bestImageURL(post, false, 64)}
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-lg
scale-[1.2] opacity-50"
/>
<picture class="max-h-[inherit]">
<source
srcset={bestImageURL(post, false, 256)}
media="(max-width: 256px)"
/>
<source
srcset={bestImageURL(post, false, 512)}
media="(max-width: 512px)"
/>
<source
srcset={bestImageURL(post, false, 1024)}
media="(max-width: 1024px)"
/>
<source
srcset={bestImageURL(post, false, 1512)}
media="(max-width: 1512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post, false, -1)}
loading="lazy"
class="max-h-[inherit] max-w-full h-auto z-30
transition-opacity duration-500 object-contain mx-auto
{imageLoaded === false ? 'opacity-0' : 'opacity-100'}"
width={512}
height={300}
class:blur-3xl={blur}
alt={post.alt_text ?? ''}
on:load={() => (imageLoaded = true)}
/>
</picture>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
rounded-full ml-auto w-max m-2 p-0 gap-1
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
on:click|stopPropagation={() => {}}
>
{#if post.alt_text}
<Button
on:click={(e) => {
e.stopPropagation()
modal({
title: 'Alt',
body: post.alt_text ?? '',
})
}}
color="tertiary"
size="md"
rounding="pill"
>
ALT
</Button>
{/if}
</div>
</svelte:element>
@@ -16,20 +16,13 @@
import { Button, Material, modal } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
import PostImage from './PostImage.svelte'
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
export let post: Post
export let type: MediaType = 'none'
export let opened: boolean | undefined = undefined
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
let showAltText = false
let imageLoaded: boolean | null = null
onMount(() => {
imageLoaded = false
})
</script>
<!--
@@ -39,94 +32,7 @@
- Embed link/card.
-->
{#if type == 'image'}
{#if view == 'card' || view == 'cozy'}
<!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:element
this={$userSettings.expandImages ? 'button' : 'a'}
href={postLink(post)}
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
data-sveltekit-preload-data="off"
aria-label={post.name}
on:click={() => showImage(bestImageURL(post, false, 2048))}
role="button"
tabindex="0"
>
<!-- svelte-ignore a11y-missing-attribute -->
<img
loading="lazy"
fetchpriority="auto"
src={bestImageURL(post, false, 64)}
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-lg
scale-[1.2] opacity-50"
/>
<picture class="max-h-[inherit]">
<source
srcset={bestImageURL(post, false, 256)}
media="(max-width: 256px)"
/>
<source
srcset={bestImageURL(post, false, 512)}
media="(max-width: 512px)"
/>
<source
srcset={bestImageURL(post, false, 1024)}
media="(max-width: 1024px)"
/>
<source
srcset={bestImageURL(post, false, 1512)}
media="(max-width: 1512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post, false, 2048)}
loading="lazy"
class="max-h-[inherit] max-w-full h-auto z-30
transition-opacity duration-500 object-contain mx-auto
{imageLoaded === false ? 'opacity-0' : 'opacity-100'}"
width={512}
height={300}
class:blur-3xl={blur}
alt={post.alt_text ?? ''}
on:load={() => (imageLoaded = true)}
/>
</picture>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
rounded-full ml-auto w-max m-2 p-0 gap-1
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
on:click|stopPropagation={() => {}}
>
<!-- <Button
color="tertiary"
size="sm"
class="aspect-square"
rounding="pill"
href={post.url}
download
>
<Icon src={ArrowDownTray} size="16" micro />
</Button> -->
{#if post.alt_text}
<Button
on:click={(e) => {
e.stopPropagation()
modal({
title: 'Alt',
body: post.alt_text ?? '',
})
}}
color="tertiary"
size="md"
rounding="pill"
>
ALT
</Button>
{/if}
</div>
</svelte:element>
{/if}
<PostImage {post} {blur} />
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
<PostIframe
thumbnail={post.thumbnail_url}
+16 -8
View File
@@ -13,16 +13,21 @@
export let width: number
export let res: number | undefined = undefined
const optimizeUrl = (url: string | undefined): string | undefined => {
const optimizeUrl = (
url: string | undefined,
res: number
): string | undefined => {
if (url === undefined) return
try {
const urlObj = new URL(url)
urlObj.searchParams.append('format', 'webp')
urlObj.searchParams.append(
'thumbnail',
findClosestNumber(sizes, (res || width) * 1.5).toString()
)
if (res > -1) {
urlObj.searchParams.append(
'thumbnail',
findClosestNumber(sizes, res).toString()
)
}
return urlObj.toString()
} catch (e) {
@@ -30,13 +35,16 @@
}
}
$: optimizedURL = optimizeUrl(url)
$: optimizedURLs = [2, 3, 6, -1].map((n) =>
optimizeUrl(url, (res || width) * n)
)
</script>
{#if optimizedURL}
{#if optimizedURLs}
<img
loading="lazy"
src={optimizedURL}
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
src={optimizedURLs[0]}
{alt}
{width}
{title}
+9
View File
@@ -472,6 +472,10 @@
"link": {
"title": "Alternative Links",
"actions": "Link Actions"
},
"vote": {
"upvote": "Upvote",
"downvote": "Downvote"
}
},
"badges": {
@@ -839,6 +843,11 @@
"pagination": {
"nav": "Pagination",
"current": "Current page"
},
"vote": {
"group": "Post voting controls",
"upvotes": "{{default}} upvotes",
"downvotes": "{{default}} downvotes"
}
}
}
+15 -15
View File
@@ -127,23 +127,23 @@
</div>
{:else}
<div class="flex flex-col h-full gap-4">
<div class="flex flex-row justify-between">
<Header pageHeader>{$t('routes.accounts')}</Header>
</div>
<div class="flex">
<div class="flex gap-2 mr-auto">
<Button href="/login" size="lg" class="flex-1 px-8" color="primary">
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
{$t('account.login')}
</Button>
{#if !LINKED_INSTANCE_URL}
<Button href="/login/guest" size="lg">
<Icon slot="prefix" src={Plus} size="16" mini />
{$t('account.addGuest')}
<Header pageHeader>
{$t('routes.accounts')}
<div class="flex" slot="extended">
<div class="flex gap-2 mr-auto">
<Button href="/login" size="lg" class="flex-1 px-8" color="primary">
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
{$t('account.login')}
</Button>
{/if}
{#if !LINKED_INSTANCE_URL}
<Button href="/login/guest" size="lg">
<Icon slot="prefix" src={Plus} size="16" mini />
{$t('account.addGuest')}
</Button>
{/if}
</div>
</div>
</div>
</Header>
<FilterTabs items={$profileData.profiles} id={(i) => i.instance} let:items>
<EditableList
on:action={(acc) => {