-
Notifications
You must be signed in to change notification settings - Fork 0
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
158e038
commit 7c8bdd0
Showing
9 changed files
with
117 additions
and
59 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,32 @@ | ||
import { PUBLIC_BUILDERIO_KEY } from "$env/static/public" | ||
import { fetchOneEntry } from "@builder.io/sdk-svelte" | ||
import { error } from "@sveltejs/kit" | ||
import { find_icon_names, load_icons } from "./util" | ||
|
||
export async function load_page_data(url: URL, f: typeof fetch) { | ||
const content = await fetchOneEntry({ | ||
model: "page", | ||
apiKey: PUBLIC_BUILDERIO_KEY, | ||
userAttributes: { | ||
urlPath: url.pathname, | ||
}, | ||
}) | ||
|
||
if (!url.searchParams.get("builder.preview") && !content) { | ||
throw error(404, { | ||
message: "Page not found", | ||
code: "NOT_FOUND", | ||
}) | ||
} | ||
|
||
const icon_names = new Set<string>() | ||
|
||
find_icon_names(content?.data?.blocks || [], icon_names) | ||
|
||
return { | ||
content, | ||
icons: await load_icons([...icon_names], f), | ||
title: content?.data?.title, | ||
description: content?.data?.description, | ||
} | ||
} |
File renamed without changes.
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,41 @@ | ||
<script lang="ts"> | ||
import { PUBLIC_BUILDERIO_KEY } from "$env/static/public" | ||
import ButtonComponent from "$lib/blocks/Button/ButtonComponent" | ||
import HeadingComponent from "$lib/blocks/Heading/HeadingComponent.js" | ||
import IconComponent from "$lib/blocks/Icon/IconComponent.js" | ||
import SpecialComponent from "$lib/blocks/Special/SpecialComponent.js" | ||
import TagComponent from "$lib/blocks/TagComponent/TagComponent.js" | ||
import PageHead from "$lib/components/PageHead.svelte" | ||
import { icons } from "$lib/data/icons.svelte" | ||
import { Content, isPreviewing } from "@builder.io/sdk-svelte" | ||
let { | ||
data, | ||
} = $props() | ||
Object.assign(icons, data.icons) | ||
</script> | ||
<PageHead | ||
description={data.description} | ||
title={data.title || "Untitled Page"}/> | ||
<main> | ||
{#if data.content || isPreviewing()} | ||
<Content | ||
apiKey={PUBLIC_BUILDERIO_KEY} | ||
content={data.content} | ||
customComponents={[ | ||
ButtonComponent, | ||
SpecialComponent, | ||
TagComponent, | ||
HeadingComponent, | ||
IconComponent, | ||
]} | ||
data={{ | ||
citizen: false, | ||
}} | ||
model="page" /> | ||
{:else} | ||
<h1>No Content</h1> | ||
{/if} | ||
</main> |
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,5 @@ | ||
import { load_page_data } from "$lib/utils/load_page.js" | ||
|
||
export async function load({ url, fetch }) { | ||
return load_page_data(url, fetch) | ||
} |
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
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
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 |
---|---|---|
@@ -1,33 +1,5 @@ | ||
import { PUBLIC_BUILDERIO_KEY } from "$env/static/public" | ||
import { fetchOneEntry } from "@builder.io/sdk-svelte" | ||
import { error } from "@sveltejs/kit" | ||
import { find_icon_names, load_icons } from "./util.js" | ||
import { load_page_data } from "$lib/utils/load_page.js" | ||
|
||
export async function load({ url, fetch }) { | ||
// fetch your Builder content | ||
const content = await fetchOneEntry({ | ||
model: "page", | ||
apiKey: PUBLIC_BUILDERIO_KEY, | ||
userAttributes: { | ||
urlPath: url.pathname, | ||
}, | ||
}) | ||
|
||
if (!url.searchParams.get("builder.preview") && !content) { | ||
throw error(404, { | ||
message: "Page not found", | ||
code: "NOT_FOUND", | ||
}) | ||
} | ||
|
||
const icon_names = new Set<string>() | ||
|
||
find_icon_names(content?.data?.blocks || [], icon_names) | ||
|
||
return { | ||
content, | ||
icons: await load_icons([...icon_names], fetch), | ||
title: content?.data?.title, | ||
description: content?.data?.description, | ||
} | ||
return load_page_data(url, fetch) | ||
} |
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
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ const config = { | |
} | ||
|
||
export default config | ||
|