-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8bd075
commit 2c65d93
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script> | ||
// an object of components that map to section names (e.g., { "Hero": Hero }) where Hero is a Svelte component | ||
export let components = {}; | ||
// an array of objects that contain a section name and content (either an array of object) | ||
export let body = []; | ||
</script> | ||
|
||
{#each body as { section, content }} | ||
{@const id = section.toLowerCase()} | ||
{@const component = components[section]} | ||
<section {id}> | ||
{#if component} | ||
<svelte:component this={component} {...content}></svelte:component> | ||
{:else} | ||
{#each content as { type, value }} | ||
{#if components[type]} | ||
<svelte:component this={component} {...value}></svelte:component> | ||
{:else if type === "text"} | ||
<p>{@html value}</p> | ||
{:else} | ||
<svelte:element this={type} {...value.attributes} | ||
>{#if typeof value === "string"}{@html value}{/if}</svelte:element | ||
> | ||
{/if} | ||
{/each} | ||
{/if} | ||
</section> | ||
{/each} |