diff --git a/src/app/blog/[id]/page.tsx b/src/app/blog/[id]/page.tsx index 168ca38..e31fb6e 100644 --- a/src/app/blog/[id]/page.tsx +++ b/src/app/blog/[id]/page.tsx @@ -20,13 +20,13 @@ export default async function Page({ slug: q.slug("slug"), publishedAt: q.date(), content: q.string(), - mainImage: q("mainImage").grabOne$("asset->url", q.string()), + mainImage: q("mainImage").grabOne$("asset->url", q.string().optional()), }) .slice(0, 1); const post = schema.parse(await client.fetch(query))[0]; - const r = post.mainImage.match(/(?\d+)x(?\d+)/); + const r = post.mainImage?.match(/(?\d+)x(?\d+)/); return (
@@ -44,13 +44,15 @@ export default async function Page({
- {post.title} + {post.mainImage && ( + {post.title} + )} diff --git a/src/app/blog/page.tsx b/src/app/blog/page.tsx index 1d8ca5f..85887d5 100644 --- a/src/app/blog/page.tsx +++ b/src/app/blog/page.tsx @@ -13,11 +13,12 @@ export default async function Page() { subtitle: q.string(), slug: q.slug("slug"), publishedAt: q.date(), - mainImage: q("mainImage").grabOne$("asset->url", q.string()), + mainImage: q("mainImage").grabOne$("asset->url", q.string().optional()), categories: q("categories") .filter() .deref() - .grabOne$("title", q.string()), + .grabOne$("title", q.string()) + .nullable(), }); const posts = schema.parse(await client.fetch(query)); @@ -38,7 +39,7 @@ export default async function Page() {
{posts.map((post) => { - const r = post.mainImage.match(/(?\d+)x(?\d+)/); + const r = post.mainImage?.match(/(?\d+)x(?\d+)/); return ( - {post.title} + {post.mainImage && ( + {post.title} + )}

{post.title}

{post.subtitle}

-

- Categories: - {post.categories.map((category) => ( - - {category} - - ))} -

+ {post.categories && post.categories.length > 0 && ( +

+ Categories: + {post.categories.map((category) => ( + + {category} + + ))} +

+ )}
-

-

- Categories: - {project.categories.map((category) => ( - - {category} - - ))} -
-

+
+ {project.categories && project.categories.length > 0 && ( +
+ Categories: + {project.categories.map((category) => ( + + {category} + + ))} +
+ )} +