feat(post-page): implement script execution for dynamic content rendering
- 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:
@@ -10,6 +10,16 @@
|
|||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
|
|
||||||
let { data }: { data: PageData } = $props();
|
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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -95,7 +105,7 @@
|
|||||||
|
|
||||||
{#if data.commentSlot}
|
{#if data.commentSlot}
|
||||||
<Accordion label={t(data.translations, T.post_comments)} class="mt-6">
|
<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}
|
{@html data.commentSlot}
|
||||||
</div>
|
</div>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|||||||
Reference in New Issue
Block a user