Created
April 4, 2022 08:24
-
-
Save eladroz/42b5e6922ad1495f427827dbb2ee5e9d to your computer and use it in GitHub Desktop.
Getting content from Contentful in a SvelteKit JSON resource
This file contains hidden or 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
import { client } from '$lib/contentfulClient'; | |
export async function get({ params }) { | |
const blog = await client.getEntries({ | |
'fields.slug': params.slug, | |
content_type: 'blog-post' | |
}); | |
if (blog?.items?.length > 0) { | |
return { | |
body: { | |
blog: blog.items[0], | |
} | |
}; | |
} | |
return { | |
status: 404 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment