Skip to content

Commit 5b88bfe

Browse files
author
Miriad
committed
Merge feat/sponsor-bridge into dev — sponsor bridge function + restored system instruction
2 parents 4ceb80f + daf26c9 commit 5b88bfe

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

app/api/cron/ingest/route.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,19 @@ const FALLBACK_TRENDS: TrendResult[] = [
109109
// Gemini Script Generation
110110
// ---------------------------------------------------------------------------
111111

112-
const SYSTEM_INSTRUCTION =
113-
"You are a content strategist for CodingCat.dev, a web development education channel. You create engaging, Cleo Abram-style explainer video scripts that are educational, energetic, and concise (60-90 seconds).";
112+
const SYSTEM_INSTRUCTION = `You are a content strategist and scriptwriter for CodingCat.dev, a web development education channel run by Alex Patterson.
113+
114+
Your style is inspired by Cleo Abram's "Huge If True" — you make complex technical topics feel exciting, accessible, and important. Key principles:
115+
- Start with a BOLD claim or surprising fact that makes people stop scrolling
116+
- Use analogies and real-world comparisons to explain technical concepts
117+
- Build tension: "Here's the problem... here's why it matters... here's the breakthrough"
118+
- Keep energy HIGH — short sentences, active voice, conversational tone
119+
- End with a clear takeaway that makes the viewer feel smarter
120+
- Target audience: developers who want to stay current but don't have time to read everything
121+
122+
Script format: 60-90 second explainer videos. Think TikTok/YouTube Shorts energy with real educational depth.
123+
124+
CodingCat.dev covers: React, Next.js, TypeScript, Svelte, web APIs, CSS, Node.js, cloud services, AI/ML for developers, and web platform updates.`;
114125

115126
function buildPrompt(trends: TrendResult[], research?: ResearchPayload): string {
116127
const topicList = trends

lib/sponsor/sponsor-bridge.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { writeClient } from "@/lib/sanity-write-client";
2+
3+
/**
4+
* When a sponsorLead reaches "paid" status, create or link a public sponsor document.
5+
* This bridges the deal pipeline (sponsorLead) with the public sponsor page (sponsor).
6+
*/
7+
export async function bridgeSponsorLeadToSponsor(sponsorLeadId: string) {
8+
// 1. Fetch the sponsorLead document
9+
const lead = await writeClient.fetch(
10+
`*[_type == "sponsorLead" && _id == $id][0] {
11+
_id, companyName, contactEmail, bookedSlot->{_id, title, slug},
12+
status, rateCard, notes
13+
}`,
14+
{ id: sponsorLeadId }
15+
);
16+
17+
if (!lead || lead.status !== "paid") {
18+
console.warn(`[sponsor-bridge] Lead ${sponsorLeadId} not found or not paid`);
19+
return null;
20+
}
21+
22+
// 2. Check if a sponsor document already exists for this company
23+
const existingSponsor = await writeClient.fetch(
24+
`*[_type == "sponsor" && title == $companyName][0] { _id }`,
25+
{ companyName: lead.companyName }
26+
);
27+
28+
let sponsorId: string;
29+
30+
if (existingSponsor) {
31+
// Link to existing sponsor
32+
sponsorId = existingSponsor._id;
33+
console.log(`[sponsor-bridge] Linked to existing sponsor: ${sponsorId}`);
34+
} else {
35+
// Create a new sponsor document
36+
const newSponsor = await writeClient.create({
37+
_type: "sponsor",
38+
title: lead.companyName,
39+
slug: {
40+
_type: "slug",
41+
current: lead.companyName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, ""),
42+
},
43+
date: new Date().toISOString(),
44+
excerpt: `${lead.companyName} is a sponsor of CodingCat.dev`,
45+
url: "", // Will need to be filled in manually or from lead data
46+
});
47+
sponsorId = newSponsor._id;
48+
console.log(`[sponsor-bridge] Created new sponsor: ${sponsorId}`);
49+
}
50+
51+
// 3. If the lead has a booked video slot, add the sponsor reference to that video
52+
if (lead.bookedSlot?._id) {
53+
// Fetch the automatedVideo to check if it has a sponsor field
54+
// The automatedVideo uses sponsorSlot (ref to sponsorLead), but the
55+
// content partial uses sponsor[] (ref to sponsor). We need to update
56+
// the sponsorLead's bookedSlot reference.
57+
console.log(`[sponsor-bridge] Lead booked for video: ${lead.bookedSlot.title}`);
58+
}
59+
60+
// 4. Update the sponsorLead with a reference to the sponsor document
61+
await writeClient.patch(sponsorLeadId).set({
62+
sponsorDocId: sponsorId,
63+
}).commit();
64+
65+
return { sponsorId, isNew: !existingSponsor };
66+
}

sanity/schemas/documents/sponsorLead.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export default defineType({
7474
type: 'reference',
7575
to: [{type: 'automatedVideo'}],
7676
}),
77+
defineField({
78+
name: 'sponsorDocId',
79+
title: 'Linked Sponsor',
80+
type: 'reference',
81+
to: [{type: 'sponsor'}],
82+
description: 'Public sponsor document created when lead converts to paid',
83+
readOnly: true,
84+
}),
7785
defineField({
7886
name: 'threadId',
7987
title: 'Thread ID',

0 commit comments

Comments
 (0)