feat(post-page): implement script execution for dynamic content rendering
Deploy / verify (push) Successful in 42s
Deploy / deploy (push) Successful in 1m11s

- Added `executeScripts` function to handle script elements within the comment slot, ensuring proper execution of inline scripts.
- Updated the comment slot container to utilize the new script execution functionality, enhancing dynamic content handling.
This commit is contained in:
Peter Meier
2026-04-19 13:52:29 +02:00
parent 1d75610cd3
commit 2e0601e178
+11 -1
View File
@@ -10,6 +10,16 @@
import type { PageData } from './$types';
let { data }: { data: PageData } = $props();
function executeScripts(node: HTMLElement) {
const scripts = node.querySelectorAll("script");
scripts.forEach((old) => {
const s = document.createElement("script");
for (const { name, value } of old.attributes) s.setAttribute(name, value);
s.text = old.textContent ?? "";
old.replaceWith(s);
});
}
</script>
<svelte:head>
@@ -95,7 +105,7 @@
{#if data.commentSlot}
<Accordion label={t(data.translations, T.post_comments)} class="mt-6">
<div class="p-8 border border-zinc-200 rounded-lg">
<div class="p-8 border border-zinc-200 rounded-lg" use:executeScripts>
{@html data.commentSlot}
</div>
</Accordion>