mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add markdown parsing and rendering support
fix: resolve lint issues chore: npm run format - Added `parseMarkdown` function to handle markdown content with DOMPurify for sanitization. - Updated `+page.svelte` to render markdown content and handle media loading. - Introduced new styles for markdown elements in the Svelte component. - Enhanced media placeholders for external content with privacy warnings.
This commit is contained in:
@@ -4,17 +4,16 @@ import { extractError } from '$lib/utils/misc';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch }) => {
|
||||
try {
|
||||
const res = await fetch('/api/paste/recent');
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw error(res.status, errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
return { recentPastes: [] };
|
||||
}
|
||||
try {
|
||||
const res = await fetch('/api/paste/recent');
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw error(res.status, errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { recentPastes: [] };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
$: now = new Date();
|
||||
let now = new Date();
|
||||
|
||||
onMount(() => {
|
||||
const interval = setInterval(() => {
|
||||
@@ -39,7 +39,7 @@
|
||||
{:else}
|
||||
<h1 class="mb-4 text-3xl font-bold">Recent Pastes</h1>
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
{#each data.recentPastes as paste}
|
||||
{#each data.recentPastes as paste (paste.uuid)}
|
||||
{@const createdAt = extractDateFromUUIDv7(paste.uuid)}
|
||||
{@const syntax = syntaxes[paste.syntax] ?? syntaxes['plaintext']}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
class="flex flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
>
|
||||
<span
|
||||
class="w-fit truncate text-lg max-w-full font-semibold text-neutral-100 hover:text-white"
|
||||
class="w-fit max-w-full truncate text-lg font-semibold text-neutral-100 hover:text-white"
|
||||
use:tooltip={paste.title || 'Untitled Paste'}
|
||||
>
|
||||
{paste.title || 'Untitled Paste'}
|
||||
|
||||
Reference in New Issue
Block a user