A CLI for publishing standard.site documents to ATProto

refacto: build note record

+27 -34
+27 -34
packages/cli/src/extensions/remanso.ts
··· 181 181 return uriMatch[3]! 182 182 } 183 183 184 - export async function createNote( 184 + async function buildNoteRecord( 185 185 agent: Agent, 186 186 post: BlogPost, 187 - atUri: string, 188 187 options: NoteOptions, 189 - ): Promise<void> { 190 - const rkey = parseRkey(atUri) 188 + ): Promise<Record<string, unknown>> { 191 189 const publishDate = new Date(post.frontmatter.publishDate).toISOString() 192 190 const trimmedContent = post.content.trim() 193 191 const titleMatch = trimmedContent.match(/^# (.+)$/m) ··· 207 205 record.images = images 208 206 } 209 207 208 + if (post.frontmatter.theme) { 209 + record.theme = post.frontmatter.theme 210 + } 211 + 212 + if (post.frontmatter.fontSize) { 213 + record.fontSize = post.frontmatter.fontSize 214 + } 215 + 216 + if (post.frontmatter.fontFamily) { 217 + record.fontFamily = post.frontmatter.fontFamily 218 + } 219 + 220 + return record 221 + } 222 + 223 + export async function createNote( 224 + agent: Agent, 225 + post: BlogPost, 226 + atUri: string, 227 + options: NoteOptions, 228 + ): Promise<void> { 229 + const rkey = parseRkey(atUri) 230 + const record = await buildNoteRecord(agent, post, options) 231 + 210 232 await agent.com.atproto.repo.createRecord({ 211 233 repo: agent.did!, 212 234 collection: LEXICON, ··· 223 245 options: NoteOptions, 224 246 ): Promise<void> { 225 247 const rkey = parseRkey(atUri) 226 - const publishDate = new Date(post.frontmatter.publishDate).toISOString() 227 - const trimmedContent = post.content.trim() 228 - const titleMatch = trimmedContent.match(/^# (.+)$/m) 229 - const title = titleMatch ? titleMatch[1] : post.frontmatter.title 230 - 231 - const { content, images } = await processNoteContent(agent, post, options) 232 - 233 - const record: Record<string, unknown> = { 234 - $type: LEXICON, 235 - title, 236 - content: content.slice(0, MAX_CONTENT), 237 - createdAt: publishDate, 238 - publishedAt: publishDate, 239 - } 240 - 241 - if (images.length > 0) { 242 - record.images = images 243 - } 244 - 245 - if (post.frontmatter.theme) { 246 - record.theme = post.frontmatter.theme 247 - } 248 - 249 - if (post.frontmatter.fontSize) { 250 - record.fontSize = post.frontmatter.fontSize 251 - } 252 - 253 - if (post.frontmatter.fontFamily) { 254 - record.fontFamily = post.frontmatter.fontFamily 255 - } 248 + const record = await buildNoteRecord(agent, post, options) 256 249 257 250 await agent.com.atproto.repo.putRecord({ 258 251 repo: agent.did!,