Skip to content

Commit

Permalink
cms
Browse files Browse the repository at this point in the history
  • Loading branch information
russellsamora committed Aug 20, 2024
1 parent e8bd075 commit 2c65d93
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/components/CMS.svelte
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}

0 comments on commit 2c65d93

Please sign in to comment.