Skip to content

connection problem with sanity, and slug not working Till video #5 #1

@SHUBH0924

Description

@SHUBH0924

image
This is the folder structure.

import React from 'react'

export default function home({blogs}) {
console.log(blogs)
return (


home

)
}

export async function getServerSideProps(context){
const client = createClient({
projectId: 'yzoa5xqp',
dataset: 'production',
useCdn: true,
});
// Fetch the data for this page using the Sanity API. This is a simple query that fetches all posts.
const query = *[_type == "blog"];
const blogs = await client.fetch(query);
return{
props: {
blogs
}
}
}

import { useRouter } from 'next/router'

export default function Page() {
const router = useRouter()
return

Post: {router.query.slug}


}
//slug.js

export default {
name: "blog",
type: "document",
title: "Blog Posts",
fields: [{
name: "title",
type: "string",
title: "Title"
},
{
name: 'content',
title: 'Content',
type: 'array',
of: [
{
type: 'block'
},
{
type: 'image',
fields: [
{
type: 'text',
name: 'alt',
title: 'Alternative text',
description: Some of your visitors cannot see images, be they blind, color-blind, low-sighted; alternative text is of great help for those people that can rely on it to have a good idea of what\'s on your page.,
options: {
isHighlighted: true
}
}
]
}
]
},
{
name: "metadesc",
type: "string",
title: "Meta Description"
},
{
title: 'Blog Image',
name: 'blogimage',
type: 'image',
options: {
hotspot: true // <-- Defaults to false
},
fields: [
{
name: 'caption',
type: 'string',
title: 'Caption',
},
{
name: 'attribution',
type: 'string',
title: 'Attribution',
}
]
},
{
title: "Created At",
name: "createdAt",
type: "datetime",
},
{
name: 'author',
type: 'object',
fields : [
{
title: 'Author',
name: 'author',
type: 'reference',
to: [{type:'author'}]
}
]
}
]
}
// this is the blog.js

image
//console.error

image
//terminal error for console

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions