diff --git a/src/lib/queries.js b/src/lib/queries.js index ed79ce6..bc2d44b 100644 --- a/src/lib/queries.js +++ b/src/lib/queries.js @@ -2,30 +2,24 @@ * Example of how you could re-use GROQ queries across different contexts with Javascript. * As your schema evolves, this pattern will be useful to keep your data in sync across all surfaces. */ -export function getPostsQuery() { +export async function getPostsQuery() { + const data = await client.fetch(`*[_type == "post"] { + title, + slug, + coverImage { + ..., + asset-> + }, + body, + }`); - - - return `*[_type == "post"] { - _id, - _type, - _createdAt, - _updatedAt, - title, - slug, - coverImage { - ..., - asset-> - }, - duration { - start, - end - }, - client, - site, - tags[], - body - }` + if (data) { + return { + posts: data + }; } - - + return { + status: 500, + body: new Error("Internal Server Error") + }; +} \ No newline at end of file diff --git a/src/routes/learnings/+page.server.js b/src/routes/learnings/+page.server.js index 93fcbdd..f75e3c0 100644 --- a/src/routes/learnings/+page.server.js +++ b/src/routes/learnings/+page.server.js @@ -1,24 +1,4 @@ import { client } from '$lib/sanity/client.js' -// import { getPostsQuery } from '$lib/queries.js' - -// // Fetch all valid posts & authors to display in the homepage -// export async function load() { -// const data = await client.fetch(/* groq */ `{ -// "posts": ${getPostsQuery()}, -// }`) - -// if (data) { -// return { -// status: 200, -// body: data -// } -// } - -// return { -// status: 404 -// } -// } - export async function load({ params }) { const data = await client.fetch(`*[_type == "post"] { diff --git a/src/routes/learnings/+page.svelte b/src/routes/learnings/+page.svelte index c3f1b1a..374ef54 100644 --- a/src/routes/learnings/+page.svelte +++ b/src/routes/learnings/+page.svelte @@ -1,14 +1,15 @@ {#each data.posts as post}

{post.title}

- {#each post.body as block} - {#if } - - {/if} - <>{block}

+ {#each post.body as block, i} +

{setElement(block.style, block.children[0].text)}

{/each} yes