your personal website on atproto - mirror blento.app

hide nsfw labeled posts

+38 -4
+3 -1
src/lib/components/bluesky-post/index.ts
··· 26 26 // const reason = data.reason; 27 27 // const reply = data.reply?.parent; 28 28 // const replyId = reply?.uri?.split('/').pop(); 29 + console.log(JSON.parse(JSON.stringify(data))); 29 30 30 31 const id = post.uri.split('/').pop(); 31 32 ··· 87 88 } as PostEmbed) 88 89 : undefined, 89 90 90 - htmlContent: blueskyPostToHTML(post, baseUrl) 91 + htmlContent: blueskyPostToHTML(post, baseUrl), 92 + labels: post.labels ? post.labels.map((label) => label.val) : undefined 91 93 }; 92 94 } 93 95
+2 -3
src/lib/components/post/Post.svelte
··· 8 8 import type { Snippet } from 'svelte'; 9 9 import { numberToHumanReadable } from '..'; 10 10 import { RelativeTime } from '@foxui/time'; 11 + import PostEmbed from './PostEmbed.svelte'; 11 12 12 13 let { 13 14 ref = $bindable(), ··· 181 182 {/if} 182 183 </Prose> 183 184 184 - {#if data.embed} 185 - <Embed embed={data.embed} /> 186 - {/if} 185 + <PostEmbed {data} /> 187 186 188 187 {#if showReply || showRepost || showLike || showBookmark || customActions} 189 188 <div
+23
src/lib/components/post/PostEmbed.svelte
··· 1 + <script lang="ts"> 2 + import { hasNSFWLabel, type PostData } from '.'; 3 + import Embed from './embeds/Embed.svelte'; 4 + 5 + let { 6 + data 7 + }: { 8 + data: PostData; 9 + } = $props(); 10 + 11 + let showNSFW = $state(false); 12 + </script> 13 + 14 + {#if hasNSFWLabel(data) && !showNSFW} 15 + <button 16 + onclick={() => (showNSFW = true)} 17 + class="border-base-500/20 bg-base-200/50 text-base-600 dark:border-base-400/20 dark:bg-base-800/50 dark:text-base-400 accent:border-accent-900 mt-4 flex h-18 w-full cursor-pointer items-center justify-center rounded-2xl border text-center text-sm" 18 + > 19 + NSFW content, click to show. 20 + </button> 21 + {:else if data.embed} 22 + <Embed embed={data.embed} /> 23 + {/if}
+10
src/lib/components/post/index.ts
··· 70 70 htmlContent?: string; 71 71 72 72 replies?: PostData[]; 73 + 74 + labels?: string[]; 73 75 }; 76 + 77 + export const nsfwLabels = ['porn', 'sexual', 'graphic-media', 'nudity']; 78 + 79 + export function hasNSFWLabel(post: PostData): boolean { 80 + if (!post.labels) return false; 81 + 82 + return post.labels.some((label) => nsfwLabels.includes(label)); 83 + } 74 84 75 85 export { default as Post } from './Post.svelte';