From 078397cd1785d3190aa5b295a718ab94328fe6cb Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 8 Feb 2026 01:50:48 +0100 Subject: [PATCH] publish to litenote too --- packages/cli/src/commands/publish-lite.ts | 75 +++++++++++++++++++++++ packages/cli/src/commands/publish.ts | 3 + 2 files changed, 78 insertions(+) create mode 100644 packages/cli/src/commands/publish-lite.ts diff --git a/packages/cli/src/commands/publish-lite.ts b/packages/cli/src/commands/publish-lite.ts new file mode 100644 index 0000000..9d89c64 --- /dev/null +++ b/packages/cli/src/commands/publish-lite.ts @@ -0,0 +1,75 @@ +import { Agent } from "@atproto/api" +import { BlogPost } from "../lib/types" + +const LEXICON = "space.litenote.note" +const MAX_CONTENT = 10000 + +export async function createNote( + agent: Agent, + post: BlogPost, + atUri: string, +): Promise { + // Parse the atUri to get the site.standard.document rkey + // Format: at://did:plc:xxx/collection/rkey + const uriMatch = atUri.match(/^at:\/\/([^/]+)\/([^/]+)\/(.+)$/); + if (!uriMatch) { + throw new Error(`Invalid atUri format: ${atUri}`); + } + + const [, , , rkey] = uriMatch; + const publishDate = new Date(post.frontmatter.publishDate).toISOString(); + + const record: Record = { + $type: LEXICON, + title: post.frontmatter.title, + content: post.content.slice(0, MAX_CONTENT), + createdAt: publishDate, + publishedAt: publishDate, + }; + + + const response = await agent.com.atproto.repo.createRecord({ + repo: agent.did!, + collection: LEXICON, + record, + rkey, + validate: false + }); + + console.log("\n\n create -", response); +} + +export async function updateNote( + agent: Agent, + post: BlogPost, + atUri: string, +): Promise { + // Parse the atUri to get the rkey + // Format: at://did:plc:xxx/collection/rkey + const uriMatch = atUri.match(/^at:\/\/([^/]+)\/([^/]+)\/(.+)$/); + if (!uriMatch) { + throw new Error(`Invalid atUri format: ${atUri}`); + } + + const [, , , rkey] = uriMatch; + + const publishDate = new Date(post.frontmatter.publishDate).toISOString(); + + const record: Record = { + $type: LEXICON, + title: post.frontmatter.title, + content: post.content.slice(0, MAX_CONTENT), + createdAt: publishDate, + publishedAt: publishDate, + }; + + const response = await agent.com.atproto.repo.putRecord({ + repo: agent.did!, + collection: LEXICON, + rkey: rkey!, + record, + validate: false + }); + + console.log("\n\n update -", response); +} diff --git a/packages/cli/src/commands/publish.ts b/packages/cli/src/commands/publish.ts index 5e9225a..53e5fd4 100644 --- a/packages/cli/src/commands/publish.ts +++ b/packages/cli/src/commands/publish.ts @@ -26,6 +26,7 @@ import { } from "../lib/markdown"; import type { BlogPost, BlobObject, StrongRef } from "../lib/types"; import { exitOnCancel } from "../lib/prompts"; +import { createNote, updateNote } from "./publish-lite" export const publishCommand = command({ name: "publish", @@ -316,6 +317,7 @@ export const publishCommand = command({ if (action === "create") { atUri = await createDocument(agent, post, config, coverImage); + await createNote(agent, post, atUri) s.stop(`Created: ${atUri}`); // Update frontmatter with atUri @@ -332,6 +334,7 @@ export const publishCommand = command({ } else { atUri = post.frontmatter.atUri!; await updateDocument(agent, post, atUri, config, coverImage); + await updateNote(agent, post, atUri) s.stop(`Updated: ${atUri}`); // For updates, rawContent already has atUri -- 2.51.2