still writing groq queries.
This commit is contained in:
		
							parent
							
								
									eead28f05a
								
							
						
					
					
						commit
						c2c2ad29eb
					
				@ -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() {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
    return `*[_type == "post"] {
 | 
			
		||||
      _id,
 | 
			
		||||
      _type,
 | 
			
		||||
      _createdAt,
 | 
			
		||||
      _updatedAt,
 | 
			
		||||
export async function getPostsQuery() {
 | 
			
		||||
  const data = await client.fetch(`*[_type == "post"] {
 | 
			
		||||
    title,
 | 
			
		||||
    slug,
 | 
			
		||||
    coverImage {
 | 
			
		||||
      ...,
 | 
			
		||||
      asset->
 | 
			
		||||
    },
 | 
			
		||||
      duration {
 | 
			
		||||
        start,
 | 
			
		||||
        end
 | 
			
		||||
      },
 | 
			
		||||
      client,
 | 
			
		||||
      site,
 | 
			
		||||
      tags[],
 | 
			
		||||
      body
 | 
			
		||||
    }`
 | 
			
		||||
    body,
 | 
			
		||||
  }`);
 | 
			
		||||
 | 
			
		||||
  if (data) {
 | 
			
		||||
    return {
 | 
			
		||||
      posts: data
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  return {
 | 
			
		||||
    status: 500,
 | 
			
		||||
    body: new Error("Internal Server Error")
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@ -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"] {
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,15 @@
 | 
			
		||||
<script>
 | 
			
		||||
	import { text } from "@sveltejs/kit";
 | 
			
		||||
    export let data;
 | 
			
		||||
    function setElement(style, text) {
 | 
			
		||||
        const targetElement = 
 | 
			
		||||
    }
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
{#each data.posts as post}
 | 
			
		||||
    <h2>{post.title}</h2>
 | 
			
		||||
    {#each post.body as block}
 | 
			
		||||
        {#if }
 | 
			
		||||
            
 | 
			
		||||
        {/if}
 | 
			
		||||
        <>{block}</p>
 | 
			
		||||
    {#each post.body as block, i}
 | 
			
		||||
        <p id="post-text-{i}">{setElement(block.style, block.children[0].text)}</p>
 | 
			
		||||
    {/each}
 | 
			
		||||
 | 
			
		||||
    <img src="{post.coverImage.asset.url}" alt="yes">
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user