Skip to content

Commit 7e5c775

Browse files
Miriadbuilder
andcommitted
fix: replace all remaining Cloudinary runtime references with Sanity image URLs
- queries.ts: settingsQuery ogImage projection (secure_url → full image object) - utils.ts: resolveOpenGraphImage uses urlForImage() instead of secure_url - layout.tsx: ogImage uses resolveOpenGraphImage() properly - devto/route.tsx: coverImage + cloudinary.asset serializer → urlForImage() - hashnode/route.tsx: coverImage + cloudinary.asset serializer → urlForImage() - rss.ts: coverImage.secure_url → urlForImage() - package.json: remove next-cloudinary and sanity-plugin-cloudinary Co-authored-by: builder <builder@miriad.systems>
1 parent c9b2d56 commit 7e5c775

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

app/(main)/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as demo from "@/sanity/lib/demo";
1313
import { sanityFetch } from "@/sanity/lib/live";
1414
import { settingsQuery } from "@/sanity/lib/queries";
1515
import { cn } from "@/lib/utils";
16+
import { resolveOpenGraphImage } from "@/sanity/lib/utils";
1617
import { ThemeProvider } from "@/components/theme-provider";
1718
import Link from "next/link";
1819
import { Button } from "@/components/ui/button";
@@ -56,8 +57,7 @@ export async function generateMetadata(): Promise<Metadata> {
5657
const title = settings?.title || demo.title;
5758
const description = settings?.description || demo.description;
5859

59-
// const ogImage = resolveOpenGraphImage(settings?.ogImage);
60-
const ogImage = settings?.ogImage?.secure_url;
60+
const ogImage = resolveOpenGraphImage(settings?.ogImage);
6161
return {
6262
title: {
6363
template: `%s | ${title}`,

app/api/devto/route.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { podcastQuery, postQuery } from "@/sanity/lib/queries";
33
import { isValidSignature, SIGNATURE_HEADER_NAME } from "@sanity/webhook";
44
import toMarkdown from "@sanity/block-content-to-markdown";
55
import { createClient } from "next-sanity";
6+
import { urlForImage } from "@/sanity/lib/utils";
67

78
const secret = process.env.PRIVATE_SYNDICATE_WEBOOK_SECRET;
89
import { apiVersion, dataset, projectId, studioUrl } from "@/sanity/lib/api";
@@ -81,10 +82,7 @@ const formatPodcast = async (_type: string, slug: string) => {
8182
title: podcast.title,
8283
published: true,
8384
tags: ["webdev", "javascript", "beginners"],
84-
main_image: podcast?.coverImage?.secure_url?.replace(
85-
"upload/",
86-
"upload/b_rgb:5e1186,c_pad,w_1000,h_420/",
87-
),
85+
main_image: urlForImage(podcast?.coverImage)?.width(1000).height(420).url() || "",
8886
canonical_url: `https://codingcat.dev/${podcast._type}/${podcast.slug}`,
8987
description: podcast?.excerpt || "",
9088
organization_id: "1009",
@@ -239,7 +237,12 @@ const serializers = {
239237
types: {
240238
code: (props: any) =>
241239
"```" + props?.node?.language + "\n" + props?.node?.code + "\n```",
242-
"cloudinary.asset": (props: any) => `![](${props?.node?.secure_url})`,
240+
image: (props: any) => {
241+
const url = props?.node?.asset?._ref
242+
? urlForImage(props.node)?.url()
243+
: "";
244+
return `![](${url})`;
245+
},
243246
codepen: (props: any) => `{% codepen ${props?.node?.url} %}`,
244247
codesandbox: (props: any) =>
245248
`{% codesandbox ${props?.node?.url?.split("https://codesandbox.io/p/sandbox/")?.at(-1)} %}`,

app/api/hashnode/route.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { podcastQuery, postQuery } from "@/sanity/lib/queries";
33
import { isValidSignature, SIGNATURE_HEADER_NAME } from "@sanity/webhook";
44
import toMarkdown from "@sanity/block-content-to-markdown";
55
import { createClient } from "next-sanity";
6+
import { urlForImage } from "@/sanity/lib/utils";
67
import { apiVersion, dataset, projectId, studioUrl } from "@/sanity/lib/api";
78

89
const secret = process.env.PRIVATE_SYNDICATE_WEBOOK_SECRET;
@@ -110,7 +111,7 @@ const formatPodcast = async (_type: string, slug: string) => {
110111
},
111112
],
112113
coverImageOptions: {
113-
coverImageURL: podcast?.coverImage?.secure_url,
114+
coverImageURL: urlForImage(podcast?.coverImage)?.width(1600).height(840).url() || "",
114115
},
115116
originalArticleURL: `https://codingcat.dev/${podcast._type}/${podcast.slug}`,
116117
contentMarkdown: `
@@ -344,7 +345,12 @@ const serializers = {
344345
types: {
345346
code: (props: any) =>
346347
"```" + props?.node?.language + "\n" + props?.node?.code + "\n```",
347-
"cloudinary.asset": (props: any) => `![](${props?.node?.secure_url})`,
348+
image: (props: any) => {
349+
const url = props?.node?.asset?._ref
350+
? urlForImage(props.node)?.url()
351+
: "";
352+
return `![](${url})`;
353+
},
348354
codepen: (props: any) => `{% codepen ${props?.node?.url} %}`,
349355
codesandbox: (props: any) =>
350356
`{% codesandbox ${props?.node?.url?.split("https://codesandbox.io/p/sandbox/")?.at(-1)} %}`,

lib/rss.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { sanityFetch } from "@/sanity/lib/live";
33
import type { RssQueryResult } from "@/sanity/types";
44
import { rssQuery } from "@/sanity/lib/queries";
55
import { toHTML } from "@portabletext/to-html";
6+
import { urlForImage } from "@/sanity/lib/utils";
67

78
const productionDomain = process.env.VERCEL_PROJECT_PRODUCTION_URL;
89
const site = productionDomain
@@ -55,7 +56,7 @@ export async function buildFeed(params: {
5556
item.content && Array.isArray(item.content) ? toHTML(item.content) : "",
5657
link: `${site}/${item._type}/${item.slug}`,
5758
description: `${item.excerpt}`,
58-
image: item.coverImage?.secure_url || feed.items.at(0)?.image,
59+
image: urlForImage(item.coverImage)?.width(1200).height(630).url() || feed.items.at(0)?.image,
5960
date: item.date ? new Date(item.date) : new Date(),
6061
id: item._id,
6162
author: item.author

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"micromark": "^4.0.2",
8181
"micromark-extension-gfm-table": "^2.0.0",
8282
"next": "^16.1.6",
83-
"next-cloudinary": "^6.17.5",
8483
"next-sanity": "^12.1.0",
8584
"next-themes": "^0.4.6",
8685
"nextjs-toploader": "^3.9.17",
@@ -104,7 +103,6 @@
104103
"remotion": "^4.0.431",
105104
"resend": "^6.9.3",
106105
"sanity": "^5.12.0",
107-
"sanity-plugin-cloudinary": "^1.4.1",
108106
"sanity-plugin-media": "^4.1.1",
109107
"server-only": "^0.0.1",
110108
"sonner": "^2.0.7",

sanity/lib/queries.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export const docCount = groq`count(*[_type == $type])`;
44

55
export const settingsQuery = groq`*[_type == "settings"][0]{
66
...,
7-
ogImage{
8-
secure_url
9-
}
7+
ogImage
108
}`;
119

1210
// Partials

sanity/lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const urlForImage = (source: any) => {
1717
};
1818

1919
export function resolveOpenGraphImage(image: any, width = 1920, height = 1080) {
20-
if (!image || !image?.secure_url) return;
21-
const url = image?.secure_url;
20+
if (!image?.asset?._ref) return;
21+
const url = urlForImage(image)?.width(width).height(height).url();
2222
if (!url) return;
2323
return {
2424
url,
25-
alt: image?.context?.custom?.alt || "CodingCat.dev Image",
25+
alt: image?.alt || "CodingCat.dev Image",
2626
width,
2727
height,
2828
};

0 commit comments

Comments
 (0)