Sanity.io meta data not being overridden by global layout
Unanswered
Gharial posted this in #help-forum
GharialOP
Hello. I have a NextJs 13.4 working with Sanity.io and I am having a problem overriding the global layout.js in the root directory. I have tried to create a layout.jsx in the app->posts->[post]-> Folder and that didn't work. I was wondering if anyone had luck getting this to work with the new app directory. Any Help appreciated. Here is what I have tried recently in that file page.tsx:
import { getPost } from "../../../sanity/sanity.utils";
import BlockContent from "@sanity/block-content-to-react";
import { GetStaticPropsContext, GetStaticPropsResult } from "next";
import { Post } from "../../../types/Post";
import { NextSeo } from "next-seo";
type Props = {
post: Post;
};
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<GetStaticPropsResult<Props>> {
const { post: postParam } = context.params ?? {};
const slug = Array.isArray(postParam) ? postParam[0] : postParam;
const fetchedPost = await getPost(slug);
if (!fetchedPost) {
return {
notFound: true,
};
}
return {
props: {
post: fetchedPost,
},
};
}
export default function Post({ post }: Props) {
const formattedPublishedAt = new Date(post.publishedAt).toLocaleDateString();
return (
<>
<NextSeo
title={`${post.title} | Radgnarack`}
description={post.description}
/>
<div className="bg-[#222] pb-12">
// Rest of the code, not relevant for the question
</div>
</>
)
}