Skip to content

Commit 735e602

Browse files
committed
feat(tasks): add Sanity Studio draft links on Line 1 and route Trend Radar tasks to CodingCat.dev Posts
1 parent 0a82854 commit 735e602

2 files changed

Lines changed: 48 additions & 15 deletions

File tree

‎scripts/run-syndicate-post.mjs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,25 @@ async function createGoogleSyndicationTask({ title, canonicalUrl, tags = [] }) {
6060

6161
const hnUrl = `https://news.ycombinator.com/submitlink?u=${encodeURIComponent(canonicalUrl)}&t=${encodeURIComponent(title)}`;
6262
const taskTitle = title;
63-
// Put canonicalUrl on Line 1 so it is immediately clickable on the Google Tasks card preview
63+
const baseDocId = String(docId).replace(/^drafts\./, "");
64+
const studioUrl = `https://codingcat-prod.sanity.studio/intent/edit/id=${baseDocId};type=post/`;
65+
const slugMatch = canonicalUrl.match(/codingcat\.dev\/(?:post|podcast|course)\/([a-z0-9-]+)/i);
66+
const extractedSlug = slugMatch ? slugMatch[1] : "";
67+
const mobileHashnodeUrl = extractedSlug
68+
? `https://transcripts.codingcat.dev/hashnode/${extractedSlug}`
69+
: "https://hashnode.com/draft/6adff331943e682eec05f06c";
70+
71+
// Put canonicalUrl and Sanity Studio link at the top so they are immediately clickable on the card
6472
const taskNotes = [
6573
canonicalUrl,
74+
`Studio: ${studioUrl}`,
6675
`Tags: ${tags.join(", ")}`,
6776
].join("\n");
6877

6978
const subtasks = [
7079
{
71-
title: "3. Cross-post to Hashnode",
72-
notes: `https://hashnode.com/draft\nCanonical URL: ${canonicalUrl}`,
80+
title: "3. Cross-post to Hashnode (1-Tap Copy & Open)",
81+
notes: `${mobileHashnodeUrl}\nRaw .md: ${mobileHashnodeUrl}.md\nDraft: https://hashnode.com/draft/6adff331943e682eec05f06c`,
7382
},
7483
{
7584
title: "2. Import to Medium (1-Click)",

‎scripts/run-trend-radar.mjs‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -748,18 +748,33 @@ async function createGoogleTaskNotification(title, notes) {
748748
if (!tokenRes.ok) return;
749749
const { access_token } = await tokenRes.json();
750750

751-
const taskRes = await fetch("https://tasks.googleapis.com/tasks/v1/lists/@default/tasks", {
752-
method: "POST",
753-
headers: {
754-
Authorization: `Bearer ${access_token}`,
755-
"Content-Type": "application/json",
756-
},
757-
body: JSON.stringify({
758-
title,
759-
notes,
760-
due: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
761-
}),
751+
let targetListId = "@default";
752+
const listsRes = await fetch("https://tasks.googleapis.com/tasks/v1/users/@me/lists?maxResults=100", {
753+
headers: { Authorization: `Bearer ${access_token}` },
762754
});
755+
if (listsRes.ok) {
756+
const listsData = await listsRes.json();
757+
const found = (listsData.items || []).find(
758+
(l) => (l.title || "").trim().toLowerCase() === "codingcat.dev posts"
759+
);
760+
if (found?.id) targetListId = found.id;
761+
}
762+
763+
const taskRes = await fetch(
764+
`https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(targetListId)}/tasks`,
765+
{
766+
method: "POST",
767+
headers: {
768+
Authorization: `Bearer ${access_token}`,
769+
"Content-Type": "application/json",
770+
},
771+
body: JSON.stringify({
772+
title,
773+
notes,
774+
due: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
775+
}),
776+
}
777+
);
763778
if (taskRes.ok) {
764779
console.log(`✓ Created Google Task: "${title}"`);
765780
}
@@ -987,9 +1002,18 @@ async function runForDataset(targetDataset) {
9871002

9881003
if (targetDataset === "production" && createdDraftInfo) {
9891004
const { signal, draftDoc, socialDrafts } = createdDraftInfo;
1005+
const baseDraftId = String(draftDoc._id).replace(/^drafts\./, "");
1006+
const studioDraftUrl = `https://codingcat-prod.sanity.studio/intent/edit/id=${baseDraftId};type=post/`;
9901007
await createGoogleTaskNotification(
9911008
`🔥 [Trend Radar] Review Draft: ${signal.title}`,
992-
`Score: ${signal.score}/100 (${signal.rawMetrics})\nSource: ${signal.sourceUrl}\nSanity Draft ID: ${draftDoc._id}\n\nReady-to-post X Draft:\n${socialDrafts.x}`
1009+
[
1010+
`Studio Draft: ${studioDraftUrl}`,
1011+
`Score: ${signal.score}/100 (${signal.rawMetrics})`,
1012+
`Source: ${signal.sourceUrl}`,
1013+
``,
1014+
`Ready-to-post X Draft:`,
1015+
socialDrafts.x,
1016+
].join("\n")
9931017
);
9941018
}
9951019
}

0 commit comments

Comments
 (0)