Skip to content

Commit c327bf1

Browse files
author
Marcus
committed
add projects
1 parent 15df6bf commit c327bf1

4 files changed

Lines changed: 59 additions & 23 deletions

File tree

app/(app)/projects/[slug]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ interface Props {
1111
export default async function ProjectDetails({ params }: Props) {
1212
const pet = await getPetBySlug(params.slug);
1313
if (!pet) return notFound();
14+
console.log(pet);
1415
return (
1516
<SectionWrapper>
1617
<article>
17-
{pet.coverImage?.asset?.url && (
18+
{pet.coverImage?.url && (
1819
<Image
19-
src={pet.coverImage.asset.url}
20+
src={pet.coverImage.url}
2021
alt={pet.coverImage.alt || pet.name}
2122
width={1000}
2223
height={600}

components/portable-text.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import Image from "next/image";
55

66
const components: PortableTextComponents = {
77
types: {
8-
image: ({ value }) =>
9-
value?.asset?.url ? (
10-
<div className="my-6">
11-
<Image
12-
src={value.asset.url}
13-
alt={value.alt || "Project image"}
14-
width={800}
15-
height={500}
16-
className="rounded-lg object-cover"
17-
/>
18-
</div>
19-
) : null,
8+
image: ({ value }) => {
9+
console.log(value);
10+
return (
11+
<>
12+
{value?.url ? (
13+
<div className="my-6">
14+
<Image
15+
src={value.url}
16+
alt={value.alt || "Project image"}
17+
width={800}
18+
height={500}
19+
className="rounded-lg object-cover"
20+
/>
21+
</div>
22+
) : null}
23+
</>
24+
);
25+
},
2026

2127
// ✅ Sanity Table Renderer
2228
table: ({ value }) => {
@@ -82,6 +88,7 @@ const components: PortableTextComponents = {
8288
};
8389

8490
// ✅ Named export
91+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8592
export function PortableBlock({ value }: { value: any }) {
8693
return (
8794
<div className="prose dark:prose-invert max-w-none">

sanity/lib/query.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,30 @@ export async function getPetBySlug(slug: string): Promise<Pet | null> {
9696
groq`*[_type == "pet" && slug.current == $slug][0]{
9797
_id,
9898
name,
99-
slug,
100-
logo { asset-> { url } },
99+
"slug": slug.current,
100+
"logo": {
101+
"url": logo.asset->url,
102+
"alt": logo.alt
103+
},
104+
"coverImage": {
105+
"url": coverImage.asset->url,
106+
"alt": coverImage.alt
107+
},
101108
projectUrl,
102109
repository,
103-
coverImage { alt, asset-> { url } },
104110
category,
105-
techStack[] {
111+
techStack[]{
106112
name,
107113
icon
108114
},
109-
description
115+
// include all block content (including image/table blocks)
116+
description[]{
117+
...,
118+
_type == "image" => {
119+
...,
120+
"url": asset->url
121+
}
122+
}
110123
}`,
111124
{ slug },
112125
);

types/pet.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@ export interface Tech {
66
export interface Pet {
77
_id: string;
88
name: string;
9-
slug: { current: string };
9+
slug: string; // now simplified from slug.current
1010
logo?: {
11-
asset: { url: string };
11+
url?: string;
12+
alt?: string;
1213
};
1314
projectUrl?: string;
1415
repository?: string;
1516
coverImage?: {
17+
url?: string;
1618
alt?: string;
17-
asset: { url: string };
1819
};
1920
category?: "web" | "mobile" | "desktop" | "ai" | "game";
2021
techStack?: Tech[];
21-
description?: any[]; // Portable Text blocks
22+
description?: Array<
23+
| {
24+
_type: "block";
25+
children: Array<{ _key: string; text: string; marks?: string[] }>;
26+
}
27+
| {
28+
_type: "image";
29+
url: string;
30+
alt?: string;
31+
}
32+
| {
33+
_type: "table";
34+
rows?: { _key: string; cells: string[] }[];
35+
}
36+
>;
2237
}

0 commit comments

Comments
 (0)