diff --git a/packages/cli/src/extensions/remanso.ts b/packages/cli/src/extensions/remanso.ts index e16428a..12b5abb 100644 --- a/packages/cli/src/extensions/remanso.ts +++ b/packages/cli/src/extensions/remanso.ts @@ -181,13 +181,11 @@ function parseRkey(atUri: string): string { return uriMatch[3]! } -export async function createNote( +async function buildNoteRecord( agent: Agent, post: BlogPost, - atUri: string, options: NoteOptions, -): Promise { - const rkey = parseRkey(atUri) +): Promise> { const publishDate = new Date(post.frontmatter.publishDate).toISOString() const trimmedContent = post.content.trim() const titleMatch = trimmedContent.match(/^# (.+)$/m) @@ -207,6 +205,30 @@ export async function createNote( record.images = images } + if (post.frontmatter.theme) { + record.theme = post.frontmatter.theme + } + + if (post.frontmatter.fontSize) { + record.fontSize = post.frontmatter.fontSize + } + + if (post.frontmatter.fontFamily) { + record.fontFamily = post.frontmatter.fontFamily + } + + return record +} + +export async function createNote( + agent: Agent, + post: BlogPost, + atUri: string, + options: NoteOptions, +): Promise { + const rkey = parseRkey(atUri) + const record = await buildNoteRecord(agent, post, options) + await agent.com.atproto.repo.createRecord({ repo: agent.did!, collection: LEXICON, @@ -223,36 +245,7 @@ export async function updateNote( options: NoteOptions, ): Promise { const rkey = parseRkey(atUri) - const publishDate = new Date(post.frontmatter.publishDate).toISOString() - const trimmedContent = post.content.trim() - const titleMatch = trimmedContent.match(/^# (.+)$/m) - const title = titleMatch ? titleMatch[1] : post.frontmatter.title - - const { content, images } = await processNoteContent(agent, post, options) - - const record: Record = { - $type: LEXICON, - title, - content: content.slice(0, MAX_CONTENT), - createdAt: publishDate, - publishedAt: publishDate, - } - - if (images.length > 0) { - record.images = images - } - - if (post.frontmatter.theme) { - record.theme = post.frontmatter.theme - } - - if (post.frontmatter.fontSize) { - record.fontSize = post.frontmatter.fontSize - } - - if (post.frontmatter.fontFamily) { - record.fontFamily = post.frontmatter.fontFamily - } + const record = await buildNoteRecord(agent, post, options) await agent.com.atproto.repo.putRecord({ repo: agent.did!,