Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions scripts/run-syndicate-post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ async function createGoogleSyndicationTask({ title, canonicalUrl, tags = [] }) {

const hnUrl = `https://news.ycombinator.com/submitlink?u=${encodeURIComponent(canonicalUrl)}&t=${encodeURIComponent(title)}`;
const taskTitle = title;
// Put canonicalUrl on Line 1 so it is immediately clickable on the Google Tasks card preview
const baseDocId = String(docId).replace(/^drafts\./, "");
const studioUrl = `https://codingcat-prod.sanity.studio/intent/edit/id=${baseDocId};type=post/`;
const slugMatch = canonicalUrl.match(/codingcat\.dev\/(?:post|podcast|course)\/([a-z0-9-]+)/i);
const extractedSlug = slugMatch ? slugMatch[1] : "";
const mobileHashnodeUrl = extractedSlug
? `https://transcripts.codingcat.dev/hashnode/${extractedSlug}`
: "https://hashnode.com/draft/6adff331943e682eec05f06c";

// Put canonicalUrl and Sanity Studio link at the top so they are immediately clickable on the card
const taskNotes = [
canonicalUrl,
`Studio: ${studioUrl}`,
`Tags: ${tags.join(", ")}`,
].join("\n");

const subtasks = [
{
title: "3. Cross-post to Hashnode",
notes: `https://hashnode.com/draft\nCanonical URL: ${canonicalUrl}`,
title: "3. Cross-post to Hashnode (1-Tap Copy & Open)",
notes: `${mobileHashnodeUrl}\nRaw .md: ${mobileHashnodeUrl}.md\nDraft: https://hashnode.com/draft/6adff331943e682eec05f06c`,
},
{
title: "2. Import to Medium (1-Click)",
Expand Down
48 changes: 36 additions & 12 deletions scripts/run-trend-radar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -748,18 +748,33 @@ async function createGoogleTaskNotification(title, notes) {
if (!tokenRes.ok) return;
const { access_token } = await tokenRes.json();

const taskRes = await fetch("https://tasks.googleapis.com/tasks/v1/lists/@default/tasks", {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
notes,
due: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
}),
let targetListId = "@default";
const listsRes = await fetch("https://tasks.googleapis.com/tasks/v1/users/@me/lists?maxResults=100", {
headers: { Authorization: `Bearer ${access_token}` },
});
if (listsRes.ok) {
const listsData = await listsRes.json();
const found = (listsData.items || []).find(
(l) => (l.title || "").trim().toLowerCase() === "codingcat.dev posts"
);
if (found?.id) targetListId = found.id;
}

const taskRes = await fetch(
`https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(targetListId)}/tasks`,
{
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
notes,
due: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
}),
}
);
if (taskRes.ok) {
console.log(`✓ Created Google Task: "${title}"`);
}
Expand Down Expand Up @@ -987,9 +1002,18 @@ async function runForDataset(targetDataset) {

if (targetDataset === "production" && createdDraftInfo) {
const { signal, draftDoc, socialDrafts } = createdDraftInfo;
const baseDraftId = String(draftDoc._id).replace(/^drafts\./, "");
const studioDraftUrl = `https://codingcat-prod.sanity.studio/intent/edit/id=${baseDraftId};type=post/`;
await createGoogleTaskNotification(
`🔥 [Trend Radar] Review Draft: ${signal.title}`,
`Score: ${signal.score}/100 (${signal.rawMetrics})\nSource: ${signal.sourceUrl}\nSanity Draft ID: ${draftDoc._id}\n\nReady-to-post X Draft:\n${socialDrafts.x}`
[
`Studio Draft: ${studioDraftUrl}`,
`Score: ${signal.score}/100 (${signal.rawMetrics})`,
`Source: ${signal.sourceUrl}`,
``,
`Ready-to-post X Draft:`,
socialDrafts.x,
].join("\n")
);
}
}
Expand Down
Loading