From 80f9972fb6003013552df33a61216f18009eb7bc Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Thu, 29 Jan 2026 18:13:55 +0100 Subject: [PATCH] hide nsfw labeled posts --- src/lib/components/bluesky-post/index.ts | 4 +++- src/lib/components/post/Post.svelte | 5 ++--- src/lib/components/post/PostEmbed.svelte | 23 +++++++++++++++++++++++ src/lib/components/post/index.ts | 10 ++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/lib/components/post/PostEmbed.svelte diff --git a/src/lib/components/bluesky-post/index.ts b/src/lib/components/bluesky-post/index.ts index a007fa6..bf81fb6 100644 --- a/src/lib/components/bluesky-post/index.ts +++ b/src/lib/components/bluesky-post/index.ts @@ -26,6 +26,7 @@ export function blueskyPostToPostData( // const reason = data.reason; // const reply = data.reply?.parent; // const replyId = reply?.uri?.split('/').pop(); + console.log(JSON.parse(JSON.stringify(data))); const id = post.uri.split('/').pop(); @@ -87,7 +88,8 @@ export function blueskyPostToPostData( } as PostEmbed) : undefined, - htmlContent: blueskyPostToHTML(post, baseUrl) + htmlContent: blueskyPostToHTML(post, baseUrl), + labels: post.labels ? post.labels.map((label) => label.val) : undefined }; } diff --git a/src/lib/components/post/Post.svelte b/src/lib/components/post/Post.svelte index 39b37b6..8f87eb6 100644 --- a/src/lib/components/post/Post.svelte +++ b/src/lib/components/post/Post.svelte @@ -8,6 +8,7 @@ import type { Snippet } from 'svelte'; import { numberToHumanReadable } from '..'; import { RelativeTime } from '@foxui/time'; + import PostEmbed from './PostEmbed.svelte'; let { ref = $bindable(), @@ -181,9 +182,7 @@ {/if} - {#if data.embed} - - {/if} + {#if showReply || showRepost || showLike || showBookmark || customActions}
+ import { hasNSFWLabel, type PostData } from '.'; + import Embed from './embeds/Embed.svelte'; + + let { + data + }: { + data: PostData; + } = $props(); + + let showNSFW = $state(false); + + +{#if hasNSFWLabel(data) && !showNSFW} + +{:else if data.embed} + +{/if} diff --git a/src/lib/components/post/index.ts b/src/lib/components/post/index.ts index c8eaac7..9e58b4f 100644 --- a/src/lib/components/post/index.ts +++ b/src/lib/components/post/index.ts @@ -70,6 +70,16 @@ export type PostData = { htmlContent?: string; replies?: PostData[]; + + labels?: string[]; }; +export const nsfwLabels = ['porn', 'sexual', 'graphic-media', 'nudity']; + +export function hasNSFWLabel(post: PostData): boolean { + if (!post.labels) return false; + + return post.labels.some((label) => nsfwLabels.includes(label)); +} + export { default as Post } from './Post.svelte'; -- 2.51.2