From eead28f05a8c8072d9ef59681637f30df2929b18 Mon Sep 17 00:00:00 2001 From: ChrQR Date: Sun, 28 Apr 2024 13:05:57 +0200 Subject: [PATCH] changed queries and loads etc. Learned html basics --- src/lib/PostPreview.svelte | 0 src/lib/queries.js | 19 ++-------- src/routes/+layout.svelte | 12 +++--- src/routes/learnings/+page.server.js | 47 ++++++++++++++++++------ src/routes/learnings/+page.svelte | 15 +++++--- src/routes/learnings/[slug]/+page.svelte | 2 + 6 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 src/lib/PostPreview.svelte create mode 100644 src/routes/learnings/[slug]/+page.svelte diff --git a/src/lib/PostPreview.svelte b/src/lib/PostPreview.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/queries.js b/src/lib/queries.js index 8e11a59..ed79ce6 100644 --- a/src/lib/queries.js +++ b/src/lib/queries.js @@ -2,7 +2,10 @@ * 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(extraFilter) { +export function getPostsQuery() { + + + return `*[_type == "post"] { _id, _type, @@ -26,17 +29,3 @@ export function getPostsQuery(extraFilter) { } - // Insert the return component calling `getContent()` below - /** - * You can also re-use parts of projections as fragments. - * In this case, we're defining that, to render an author card, we need their name, slug & image. - */ - export const POST_CARD_FRAGMENT = ` - _id, - _type, - _createdAt, - _updatedAt, - title, - slug, - coverImage - ` \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 785bbe3..ee747a3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -5,8 +5,10 @@ import '../app.css'; - // Navigation links are generated based on this object - const nav = [ +/* Navigation links are generated based on this object. + Nav items are added by adding and object to the nav array. + Underscore _ should be added instead of whitespace, and it is then removed when the nav item is instantiated. + */ const nav = [ { name: "index", subPages: [], @@ -40,7 +42,7 @@ {#each nav as main,i} {#if i != 0} {#if !nav[i].subPages[0]} - + {:else} {/if} @@ -51,12 +53,12 @@ {#key selected} {/key} -
  • +
  • diff --git a/src/routes/learnings/+page.server.js b/src/routes/learnings/+page.server.js index 55a7a0c..93fcbdd 100644 --- a/src/routes/learnings/+page.server.js +++ b/src/routes/learnings/+page.server.js @@ -1,20 +1,43 @@ import { client } from '$lib/sanity/client.js' -import { POST_CARD_FRAGMENT, getPostsQuery } from '$lib/queries.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()}, - }`) +// // 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"] { + title, + slug, + coverImage { + ..., + asset-> + }, + body, + }`); if (data) { return { - status: 200, - body: data - } + posts: data + }; } - return { - status: 404 - } + status: 500, + body: new Error("Internal Server Error") + }; } \ No newline at end of file diff --git a/src/routes/learnings/+page.svelte b/src/routes/learnings/+page.svelte index f00a430..c3f1b1a 100644 --- a/src/routes/learnings/+page.svelte +++ b/src/routes/learnings/+page.svelte @@ -1,11 +1,16 @@ -{#each data.body.posts as post } +{#each data.posts as post}

    {post.title}

    -

    {post.body}

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

    + {/each} + + yes + read more... {/each} \ No newline at end of file diff --git a/src/routes/learnings/[slug]/+page.svelte b/src/routes/learnings/[slug]/+page.svelte new file mode 100644 index 0000000..500c791 --- /dev/null +++ b/src/routes/learnings/[slug]/+page.svelte @@ -0,0 +1,2 @@ +

    hello

    +

    why is this being weird

    \ No newline at end of file