Skip to content

Commit

Permalink
Blur nsfw images on cards
Browse files Browse the repository at this point in the history
This was meant to do this already, but I missed it, so nsfw images were showing unblurred when the blur setting is on.
  • Loading branch information
sheodox committed Aug 20, 2023
1 parent 97b7ebb commit c3b2462
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Alexandrite",
"version": "0.8.2",
"version": "0.8.3",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Image.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
.image-mode-thumbnail.blur:not(:hover) img {
filter: blur(10px);
}
.image-mode-full.blur {
// need to do this otherwise the blur overflows its container and goes all over the card
display: block;
overflow: hidden;
&:not(:hover) img {
filter: blur(40px);
}
}
img {
width: 100%;
}
Expand Down
15 changes: 12 additions & 3 deletions src/lib/feeds/posts/previews/CardPostImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@
}
</style>

<div class="card-image" class:nsfw={postView.post.nsfw || postView.community.nsfw}>
<div class="card-image" class:nsfw={isNsfw}>
{#if (postView.post.nsfw || postView.community.nsfw) && $nsfwImageHandling === 'HIDE' && !showAnyway}
<div class="card-image-placeholder">
<button class="tertiary" on:click|stopPropagation={() => (showAnyway = true)}> Show NSFW </button>
</div>
{:else if postAssertions.imageSrc}
<!-- not passing nsfw, this component handles it otherwise we'd have nested buttons -->
<Image src={postAssertions.imageSrc} full resizable={false} lazy={false} loadingHeight="20rem" />
<!-- not passing nsfw when handling='show' this component handles it otherwise we'd have nested buttons,
but we need to still tell it when it needs to blur otherwise you see unblurred nsfw content -->
<Image
src={postAssertions.imageSrc}
full
resizable={false}
lazy={false}
loadingHeight="20rem"
nsfw={$nsfwImageHandling === 'BLUR' && isNsfw}
/>
{/if}
</div>

Expand All @@ -39,4 +47,5 @@
let showAnyway = false;
$: postAssertions = makePostAssertions(postView);
$: isNsfw = postView.post.nsfw || postView.community.nsfw;
</script>

0 comments on commit c3b2462

Please sign in to comment.