Index loader
// src/routes/blog/+page.server.ts
import { MENTIONWELL_API_URL, MENTIONWELL_SITE_SLUG, MENTIONWELL_API_KEY } from "$env/static/private";
export const load = async () => {
const res = await fetch(`${MENTIONWELL_API_URL}/api/public/${MENTIONWELL_SITE_SLUG}/posts?limit=24`, {
headers: { Authorization: `Bearer ${MENTIONWELL_API_KEY}` }
});
const { posts } = await res.json();
return { posts };
};
Detail loader
// src/routes/blog/[slug]/+page.server.ts
import { error } from "@sveltejs/kit";
import { MENTIONWELL_API_URL, MENTIONWELL_SITE_SLUG, MENTIONWELL_API_KEY } from "$env/static/private";
export const load = async ({ params }) => {
const res = await fetch(`${MENTIONWELL_API_URL}/api/public/${MENTIONWELL_SITE_SLUG}/posts/${params.slug}`, {
headers: { Authorization: `Bearer ${MENTIONWELL_API_KEY}` }
});
if (res.status === 404) throw error(404);
const { post } = await res.json();
return { post };
};
Detail markup
<!-- src/routes/blog/[slug]/+page.svelte -->
<script lang="ts">
export let data;
</script>
<article>
<h1>{data.post.title}</h1>
{@html data.post.html}
</article>
Read this page as Markdown →